Creating constructions lines in cylindrical faces - bolt abstraction

Options
Pierre Thieffry
Pierre Thieffry Member, Moderator, Employee Posts: 101
First Anniversary Ansys Employee Solution Developer Community of Practice Member Photogenic
edited June 2023 in Structures

Bolts can sometimes be modeled as simple line bodies. With construction lines, we can easily achieve this. Yet, how can we automate the creation of line bodies from a number of selected cylindrical faces?

Tagged:

Answers

  • James Derrick
    James Derrick Administrator, Employee Posts: 248
    First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Up Votes
    admin
    Options

    Hi @Pierre Thieffry This doesn't appear to be a question? Would you be able to edit it into the standard Question/Answer format? Thanks!

  • Pierre Thieffry
    Pierre Thieffry Member, Moderator, Employee Posts: 101
    First Anniversary Ansys Employee Solution Developer Community of Practice Member Photogenic
    Answer ✓
    Options

    The script below shows a sample implementation: the user needs to select all cylindrical faces to use as a basis for line creation. Then we create one construction line per face and create the corresponding line body in the geometry. It uses the fact that the drawing plane for the construction line can be snapped to a cylindrical surface - Mechanical will automatically propose a plane along the axis of the face.

    Couple limitations of this example:

    • it is assumed the main axis of the cylindrical face is parallel to the global Y axis.

    • one construction line per face, we could replace by a single line for all faces

    • the 'Construction Geometry' folder must exist in the project (2021R1)

    Additional notes: the construction lines will follow geometric changes (for example if you move the cylindrical faces). However, the corresponding line bodies under geometries will not be updated until you click on "Update Geometry" for EACH body. The update can of course be scripted in a few lines (see bottom of the post)

    curSel=ExtAPI.SelectionManager.CurrentSelection
    
        
        construction_geometry = Model.ConstructionGeometry
        
        for faceId in curSel.Ids:
            print faceId
            face=ExtAPI.DataModel.GeoData.GeoEntityById(faceId)
            mid0=face.Centroid
            mid1=face.Edges[0].Centroid
            mid2=face.Edges[1].Centroid
            construction_line = construction_geometry.AddConstructionLine()
            plane= construction_line.CreatePlane(DataModel.GeoData.GeoEntityById(faceId))
            [plane_1] = ConstructionLineHelper.GetPlanesById(construction_line, [1])
            y1=mid1[1]-mid0[1]
            y2=mid2[1]-mid0[1]
            [point2d_planar_1, point2d_planar_2] = construction_line.CreatePlanarPoints(plane_1, [(0,y1), (0.0,y2)])
            edge_collection_4 = construction_line.CreateStraightLines([point2d_planar_1, point2d_planar_2], [(0, 1)])
            with Transaction():
                construction_line.AddToGeometry()
        #endregion
    
    
    
    #Update geometry for all construction lines
    constructionLines=ExtAPI.DataModel.GetObjectsByType(Ansys.ACT.Automation.Mechanical.ConstructionLines.ConstructionLine)
    
    with Transaction():
        for constLine in constructionLines:
            constLine.UpdateGeometry()