代码过长,需要全部脚本,请关注公众号,并发送1957!!from ansa import *
class Main:
def __init__(self):
self.node_name=''
self.node_name_id=0
self.coord_id=0
self.win()
return
def win(self):
TopWindow = guitk.BCWindowCreate("局部载荷施加", guitk.constants.BCOnExitDestroy)
BCVBox_1 = guitk.BCVBoxCreate(TopWindow)
BCHBox_1 = guitk.BCHBoxCreate(BCVBox_1)
BCLabel_1 = guitk.BCLabelCreate(BCHBox_1, "请选择要施加载荷的壳单元:")
BCPushButton_1 = guitk.BCPushButtonCreate(BCHBox_1, "Pick",self.pick)
BCHBox_2 = guitk.BCHBoxCreate(BCVBox_1)
BCLabel_2 = guitk.BCLabelCreate(BCHBox_2, "请输入施加载荷的大小(默认法向):")
self.force = guitk.BCTextEditCreate(BCHBox_2, "20")
BCLabel_3 = guitk.BCLabelCreate(BCHBox_2, "N")
BCHBox_3 = guitk.BCHBoxCreate(BCVBox_1)
BCPushButton_2 = guitk.BCPushButtonCreate(BCHBox_3, "Load Force",self.load)
guitk.BCShow(TopWindow)
return
def pick(self,b,data):
all_eles=base.PickEntities(4,'SHELL')
all_nodes=base.CollectEntities(4,all_eles,'NODE')
x_max=-1000000000000
x_min=1000000000000
y_max=-1000000000000
y_min=1000000000000
z_max=-1000000000000
z_min=1000000000000
for n in all_nodes:
if x_max <= n.position[0]:
x_max=n.position[0]
if y_max <= n.position[1]:
y_max=n.position[1]
if z_max <= n.position[2]:
z_max=n.position[2]
if x_min >= n.position[0]:
x_min=n.position[0]
if y_min >= n.position[1]:
y_min=n.position[1]
if z_min >= n.position[2]:
z_min=n.position[2]
#add 0.001 to the average ,because Nodes are collinear,Resulted in coordinate system creation failure.
x_average = (x_max + x_min) / 2+0.001
y_average = (y_max + y_min) / 2+0.001
z_average = (z_max + z_min) / 2+0.001
all_set=base.CollectEntities(4,None,'SET')
num=0
for s in all_set:
if 'node_set' in s._name:
ID_num=s._name.split('_')[-1]
ID_num=int(ID_num)
if num <= ID_num:
num=ID_num+1
vas_set={
'Name':'node_set_'+str(num),
}
set_name='set_'+str(num)
set_name=base.CreateEntity(4,'SET',vas_set)
base.AddToSet(set_name,all_nodes)
#create a rbe2
if set_name:
#create a reference node
vas_ref_node={
'X':x_average,
'Y':y_average,
'Z':z_average,
}
self.node_name='reference_node_'+str(data)
self.node_name=base.CreateEntity(4,'NODE',vas_ref_node)
self.node_name_id=self.node_name._id
vas_set={
'COUPLING':'*KINEMATIC',
'REF NODE':self.node_name._id,
'DOF':123456,
'NSET':set_name._id,
}
base.CreateEntity(4,'COUPLING',vas_set)