How can I get the node/vertex coordinates for defined springs in ANSYS Mechanical using scripting?
[{"insert":"Please include the following if applicable:\nCopy\/paste of piece of code in question"},{"attributes":{"list":{"depth":0,"type":"bullet"}},"insert":"\n"},{"insert":"Screenshot of error message"},{"attributes":{"list":{"depth":0,"type":"bullet"}},"insert":"\n"},{"insert":"What you've tried so far to debug"},{"attributes":{"list":{"depth":0,"type":"bullet"}},"insert":"\n"}]
Best Answers
-
Hello, I think you could take the Location coordinates from reference and mobile attachments
Something like this should help you to start:
AllSprings = ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.Spring) for spring in AllSprings: print("X Ref = ",spring.ReferenceXCoordinate) print("Y Ref = ",spring.ReferenceYCoordinate) print("Z Ref = ",spring.ReferenceZCoordinate) print("X Mob = ",spring.MobileXCoordinate) print("Y Mob = ",spring.MobileZCoordinate) print("Z Mob = ",spring.MobileYCoordinate)
Best Regards
1 -
Just to add that the above script also works for direct attachments on nodes or vertices.
Hope this helps.
Erik
1
Answers
-
Thank you for your kind reply. I have figured it out in a different way as the following:
select Connections in the Tree
sel = DataModel.GetObjectsByName('Connections')[0]
select Springs under Connections
a=sel.Children[0]
springs=a.Children # Create a list of all the springs defined**Then ,you can use the following to write them to a csv file: **
for spring in springs: ratio=spring.MobileYCoordinate.Value/spring.MobileXCoordinate.Value if spring.MobileXCoordinate.Value<0 and spring.MobileYCoordinate.Value>0: theta=atan(ratio)*180/3.1415926 + 180 elif spring.MobileXCoordinate.Value<0 and spring.MobileYCoordinate.Value<0: theta=atan(ratio)*180/3.1415926 - 180 else: theta=atan(ratio)*180/3.1415926 formated_X='{:5.2f}'.format(spring.MobileXCoordinate.Value) formated_Y='{:5.2f}'.format(spring.MobileYCoordinate.Value) formated_theta='{:5.2f}'.format(theta) writer.writerow([spring.Name,formated_X,formated_Y,formated_theta])
@Erik Kostson said:
Just to add that the above script also works for direct attachments on nodes or vertices.Hope this helps.
Erik
0 -
Thank you for your kind reply. I have figured it out in a different way as the following:
select Connections in the Tree
sel = DataModel.GetObjectsByName('Connections')[0]
select Springs under Connections
a=sel.Children[0]
springs=a.Children # Create a list of all the springs defined**Then ,you can use the following to write them to a csv file: **
for spring in springs: ratio=spring.MobileYCoordinate.Value/spring.MobileXCoordinate.Value if spring.MobileXCoordinate.Value<0 and spring.MobileYCoordinate.Value>0: theta=atan(ratio)*180/3.1415926 + 180 elif spring.MobileXCoordinate.Value<0 and spring.MobileYCoordinate.Value<0: theta=atan(ratio)*180/3.1415926 - 180 else: theta=atan(ratio)*180/3.1415926 formated_X='{:5.2f}'.format(spring.MobileXCoordinate.Value) formated_Y='{:5.2f}'.format(spring.MobileYCoordinate.Value) formated_theta='{:5.2f}'.format(theta) writer.writerow([spring.Name,formated_X,formated_Y,formated_theta])
@Abel Ramos said:
Hello, I think you could take the Location coordinates from reference and mobile attachmentsSomething like this should help you to start:
AllSprings = ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.Spring) for spring in AllSprings: print("X Ref = ",spring.ReferenceXCoordinate) print("Y Ref = ",spring.ReferenceYCoordinate) print("Z Ref = ",spring.ReferenceZCoordinate) print("X Mob = ",spring.MobileXCoordinate) print("Y Mob = ",spring.MobileZCoordinate) print("Z Mob = ",spring.MobileYCoordinate)
Best Regards
0