Hi,
Thanks to this post :
https://developer.ansys.com/blog/script-tip-friday-efficiently-combining-mapdl-and-mechanical-scripting
I wrote a similar function, with minor adjustments.
My problem is : When the model contains lots of joints, the creation time is long ... very long.
My questions are :
1- Is there a way to speed up this function ? (I try to add "with Transaction(suspendClicks=True):", it seems to be better, but not very fast)
2- Is there a way to create a progress bar in order to see the progression ?
def def_creation_ID(analysis):
with Transaction(suspendClicks=True):
connections_folder = ExtAPI.DataModel.Project.Model.Connections
joints_temp = connections_folder.GetChildren(DataModelObjectCategory.Joint,True)
joints = [joint for joint in joints_temp if joint.Suppressed == False and len(joint.MobileLocation.Ids) != 0 and len(joint.ReferenceLocation.Ids) != 0]
nb_joints = 0
for j in joints:
if j.Suppressed is False:
nb_joints += 1
with Transaction(suspendClicks=True):
nb_insert_command = len(j.Children)
if nb_insert_command > 0:
for i in range(nb_insert_command):
if j.Children[i].Name == r"commande_joint_ID":
j.Children[i].Delete()
new_snippet = j.AddCommandSnippet()
new_snippet.Name = r"commande_joint_ID"
string1 = 'joint_'+str(nb_joints) + ' = _jid \n'
string2 = '*DIM,joint_name_'+str(nb_joints)+',string,248 \n'
string3 = 'joint_name_'+str(nb_joints) + '(1) = \'' + j.Name + '\'\n'
string4 = '*DIM,joint_type_'+str(nb_joints)+',string,248 \n'
string5 = 'joint_type_'+str(nb_joints) + '(1) = \'' + str(j.Type) + '\'\n'
new_snippet.AppendText(string1)
new_snippet.AppendText(string2)
new_snippet.AppendText(string3)
new_snippet.AppendText(string4)
new_snippet.AppendText(string5)
new_snippet.AppendText("nb_joints = " + str(nb_joints))
ExtAPI.DataModel.Tree.Refresh()