How to add a path and use it for a Normal Stress Result using Mechanical scripting?

Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
100 Answers 500 Comments 250 Likes First Anniversary
✭✭✭✭

How to add a path and use it for a Normal Stress Result using Mechanical scripting?

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
    100 Answers 500 Comments 250 Likes First Anniversary
    ✭✭✭✭
    def InsertPath(UsePathName,node1 , node2 ):
    
        firstnode  = ExtAPI.DataModel.MeshDataByName("Global").NodeById(node1)
        secondnode = ExtAPI.DataModel.MeshDataByName("Global").NodeById(node2)
    
        Model = ExtAPI.DataModel.Project.Model
        csall = Model.CoordinateSystems
        globalcs = csall.Children[0]
        cons=Model.ConstructionGeometry
    
        p=cons.AddPath()
        p.Name = UsePathName
        p.StartCoordinateSystem = globalcs
        p.StartXCoordinate = Quantity(str(firstnode.X)+" [m]")
        p.StartYCoordinate = Quantity(str(firstnode.Y)+" [m]")
        p.StartZCoordinate = Quantity(str(firstnode.Z)+" [m]")
        p.EndCoordinateSystem = globalcs
        p.EndXCoordinate = Quantity(str(secondnode.X)+" [m]")
        p.EndYCoordinate = Quantity(str(secondnode.Y)+" [m]")
        p.EndZCoordinate = Quantity(str(secondnode.Z)+" [m]")
        allpaths = ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.Path)
        mypath = [i for i in allpaths if i.Name == UsePathName][0]
    
        result = Model.Analyses[0].Solution.AddLinearizedNormalStress()
        result.NormalOrientation=NormalOrientationType.XAxis
        sel = ExtAPI.SelectionManager.CurrentSelection
        pathLoc = Ansys.Mechanical.Selection.PathLocation(mypath, sel)
        result.Location = pathLoc
        result.Name=UsePathName
    #================================================================
    
    #Usage : Path's ( and result's) name , first node, second node numbers
    InsertPath('newpath2',195 , 84 )