-
Notifications
You must be signed in to change notification settings - Fork 4
/
utilities.py
165 lines (131 loc) · 4.75 KB
/
utilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# -*- coding: utf-8 -*-
from abaqus import *
from abaqusConstants import *
import math
info = 1
debug = 0
def writeFormat(file, format, content):
str_fmt = ''
for i, t in enumerate(format):
if t == 'd':
str_fmt += '{0[' + str(i) + ']:10d}'
elif t == 'e' or t == 'E':
str_fmt += '{0[' + str(i) + ']:16.6' + t + '}'
str_fmt += '\n'
#print str_fmt
file.write(str_fmt.format(content))
return
def strFormat(format):
#formata='ddEEEEEEEEE'
strFormat = ''
for i, t in enumerate(format):
if t == 'd' or t == 'D':
strFormat += '{0[' + str(i) + ']:10d}'
#==============================================================================
# if t == 's' or t == 'S':
# strFormat += '{0[' + str(i) + ']:10s}'
#==============================================================================
elif t == 'e' or t == 'E':
strFormat += '{0[' + str(i) + ']:16.6' + t + '}'
elif t == 'f' or t == 'F':
strFormat += '{0[' + str(i) + ']:16.6' + t + '}'
strFormat += '\n'
#strinfo_fmt
#g=[1220,4,1442,1443,272,273,0, 0,0 ,0,0]
#print strinfo_fmt.format(g)
return strFormat
def eleFormat(format1, format2):
#formata='ddEEEEEEEEE'
eleFormat = ''
for i, t in enumerate(format1):
if (t == 'd' or t == 'D'):
eleFormat += '{0[' + str(i) + ']:10d}'
for i, t in enumerate(format2):
if (t == 'd' or t == 'D'):
eleFormat += '{0[2][' + str(i) + ']:10d}'
elif t == 'e' or t == 'E':
eleFormat += '{0[2][' + str(i) + ']::16.6' + t + '}'
elif t == 'f' or t == 'F':
strFormat += '{0[' + str(i) + ']:16.6' + t + '}'
eleFormat += '\n'
return eleFormat
def trimIntersectCurves(sketch, curve1_id, keep1, curve2_id, keep2, near_pt):
# keep1, keep2 = 1 (keep the 1st sub-curve) or 2 (keep the 2nd sub-curve)
g = sketch.geometry
sketch.breakCurve(curve1=g[curve1_id], point1=near_pt,
curve2=g[curve2_id], point2=near_pt)
g = sketch.geometry
gk = g.keys()
id3 = gk[-2]
id4 = gk[-1]
if keep1 == 1:
curve1_id_new = id3
trim = (g[id4],)
elif keep1 == 2:
curve1_id_new = id4
trim = (g[id3],)
sketch.breakCurve(curve1=g[curve2_id], point1=near_pt,
curve2=g[id3], point2=near_pt)
g = sketch.geometry
gk = g.keys()
id5 = gk[-2]
id6 = gk[-1]
if keep2 == 1:
curve2_id_new = id5
trim += (g[id6],)
elif keep2 == 2:
curve2_id_new = id6
trim += (g[id5],)
sketch.delete(objectList=trim)
return [curve1_id_new, curve2_id_new]
def extendIntersectCurves(sketch, curve1_id, curve2_id, near_pt):
g = sketch.geometry
sketch.trimExtendCurve(curve1=g[curve1_id], point1=near_pt,
curve2=g[curve2_id], point2=near_pt)
g = sketch.geometry
gk = g.keys()
id3 = gk[-1]
sketch.trimExtendCurve(curve1=g[curve2_id], point1=near_pt,
curve2=g[id3], point2=near_pt)
g = sketch.geometry
gk = g.keys()
id4 = gk[-1]
return [id3, id4]
def findEndPoints(sketch, edge_id):
g = sketch.geometry
v = g[edge_id].getVertices()
v1 = v[0].coords
v2 = v[1].coords
return [v1, v2]
def findTwoPointsDistance(point1, point2):
x1, y1 = point1[0], point1[1]
x2, y2 = point2[0], point2[1]
d = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
return d
def refreshSets(mdb, model_name, part_name, set_fpt):
p = mdb.models[model_name].parts[part_name]
#set_fpt = mdb.customData.models[model_name]['Parts'][part_name]['Set-FacePoint']
f = p.faces
for rn, fpt in set_fpt.items():
ff = f.findAt((fpt,))
p.Set(name=rn, faces=ff)
# def getElemStats(region,elementShap):
# p = mdb.models['Model-1'].parts['Part-1']
# p.getElementType(region=region,elemShape=QUAD)
def setViewYZ(vp=None, nsg=3, obj=None, clr=None):
if vp is None:
vp = session.viewports[session.currentViewportName]
if obj is not None:
vp.setValues(displayedObject=obj)
if nsg == 1 or nsg == 2:
vp.view.setViewpoint(viewVector=(1.0, 0.0, 0.0),
cameraUpVector=(0.0, 0.0, 1.0))
elif nsg == 3:
vp.view.setViewpoint(viewVector=(1.0, 0.8, 0.6),
cameraUpVector=(0.0, 0.0, 1.0))
if clr is not None:
cmap = vp.colorMappings['Material']
vp.setColor(colorMapping=cmap)
vp.disableMultipleColors()
vp.view.fitView()
return 1