How can I get the node/vertex coordinates for defined springs in ANSYS Mechanical using scripting?

TreeofWinter
TreeofWinter Member Posts: 4
First Comment Name Dropper
**
edited June 3 in Structures

[{"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

  • Abel Ramos
    Abel Ramos Member, Employee Posts: 40
    First Answer 5 Likes 10 Comments Photogenic
    ✭✭✭✭
    edited June 6 Answer ✓

    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

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 200
    50 Answers 100 Comments Photogenic 5 Likes
    ✭✭✭✭
    edited June 6 Answer ✓

    Just to add that the above script also works for direct attachments on nodes or vertices.

    Hope this helps.

    Erik

Answers

  • TreeofWinter
    TreeofWinter Member Posts: 4
    First Comment Name Dropper
    **

    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

  • TreeofWinter
    TreeofWinter Member Posts: 4
    First Comment Name Dropper
    **

    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 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