import re
import ansa
from ansa import base
from ansa import constants
from ansa import guitk
#程序修饰器,生成一个分组和对应的脚本按钮,以及对脚本的一些介绍。
@ansa.session.defbutton("测试专用","啥都有","专门用来测试的脚本")
def TestAnything():
TopWindow = guitk.BCWindowCreate("TITLE", guitk.constants.BCOnExitDestroy)
#创建一个窗口,并给窗口命名。
guitk.BCSetCaption(TopWindow, "功能")
#创建窗口选项
BCBoxLayout_1 = guitk.BCBoxLayoutCreate(TopWindow, guitk.constants.BCHorizontal)
BCLabel_1 = guitk.BCLabelCreate(BCBoxLayout_1, "选项 :")
CVals_0 = ("测试Prop","测试PropName")
BCComboBox = [guitk.BCComboBoxCreate(BCBoxLayout_1, CVals_0)]
guitk.BCComboBoxSetActivatedTextFunction(BCComboBox[0], _DeckTest, None)
#创建OK按钮和Cancel按钮
BCDialogButtonBox_1 = guitk.BCDialogButtonBoxCreate(TopWindow)
guitk.BCWindowSetAcceptFunction(TopWindow, _OkPressed, BCComboBox)
guitk.BCWindowSetRejectFunction(TopWindow, _CancelPressed, None)
guitk.BCShow(TopWindow)
def _DeckTest(combo, text, data):
print("你当前选的功能是 : "+text)
return 0
def _OkPressed(w, data):
deck = guitk.BCComboBoxCurrentText(data[0])
if deck == "测试Prop":
print("选择需要测试的properties!")
EntsType = ("SECTION_SHELL","SECTION_SOLID","SECTION_BEAM","SECTION_DISCRETE","SECTION_SEATBELT","SECTION_BEAM_ELFORM_6") #定义一个单元类型的元组。
base.SetPickMethod(base.constants.PID_SELECTION) #通过PID来选择需要修改名字的Prop。
Results_Prop = base.PickEntities(constants.LSDYNA, EntsType) #将选择的对象保存到Results_Prop中。
for ent in Results_Prop:
Prop = base.GetEntityCardValues(constants.LSDYNA,ent,("Name","PID","MID","T1","SECID","USER_SECID",)) #通过for循环将选中的对象名字提取出来。
ProName = Prop["Name"]
ProPID = Prop["PID"]
ProMID = Prop["MID"]
ProT = Prop["T1"]
ProSecid = Prop["SECID"]
ProUserSec = Prop["USER_SECID"]
print(ProName)
print(ProPID)
print(ProMID)
print(ProT)
print(ProSecid)
print(ProUserSec)
if deck == "测试PropName":
print("选择需要测试的properties!")
EntsType = ("SECTION_SHELL","SECTION_SOLID","SECTION_BEAM","SECTION_DISCRETE","SECTION_SEATBELT","SECTION_BEAM_ELFORM_6") #定义一个单元类型的元组。
base.SetPickMethod(base.constants.PID_SELECTION) #通过PID来选择需要修改名字的Prop。
Results_Prop = base.PickEntities(constants.LSDYNA, EntsType) #将选择的对象保存到Results_Prop中。
for ent in Results_Prop:
Prop = base.GetEntityCardValues(constants.LSDYNA,ent,("Name",)) #通过for循环将选中的对象名字提取出来。
ProName = Prop["Name"]
PropName = str(ProName)
print(ProName)
print(PropName)
regex_name = re.compile("_\dp\d")
thickness = regex_name.findall(PropName)
print(thickness)
def _CancelPressed(w, data):
print("搞完了,拜拜!!!")
return 1