Ansys Assistant will be unavailable on the Learning Forum starting January 30. An upgraded version is coming soon. We apologize for any inconvenience and appreciate your patience. Stay tuned for updates.
Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

Automating “New Part” in ANSYS DesignModeler from Python (CadQuery → STEP)

    • gdigiusto
      Subscriber

      I’m generating the geometry for an FSI case using CadQuery and Ansys.
      The setup is:

      - a 3D fluid volume
      - an internal zero-thickness surface (the “flag”), lying exactly on a plane inside the fluid domain

      I export both as a single multibody STEP and import it into ANSYS Mechanical.
      The problem is Mechanical sees two separate bodies and produces two independent meshes.

      If I manually select both bodies in DesignModeler and click Create → New Part, everything works: I get a true multibody Part and Mechanical produces a conformal interface.

      I’m generating the geometry entirely via script, because I need to produce many different geometries automatically (randomized shapes and domains), so manual operations in DesignModeler are not an option.

      What I’m trying to figure out is:
      How can I achieve the same “New Part” result automatically?

      In short:
      Is there a reliable way to create a single Part between a fluid volume and an internal zero-thickness surface generated in CadQuery, without manual operations in DesignModeler?
      I am asking both here and on the CadQuery github forum, because I’m not sure whether this can be solved purely on the CadQuery/OCC side or if a solution exists inside DesignModeler.
      I have already tried exporting the two bodies as a Compound in CadQuery, but ANSYS still treats them as separate bodies.

    • Gary Stofan
      Ansys Employee

       

      The only way to create a shared topology/conformal mesh between bodies is to pass it through the Ansys programs DesignModeler or SpaceClaim or Discovery. 
      No commercial CAD program is capable of creating shared topology operations. 
      The best program to do this via Python scripting operations would be Discovery. 

       

    • gdigiusto
      Subscriber

      Thank you for the clarification.
      In the end I managed to achieve the shared topology directly inside Workbench by sending a script command to DesignModeler. Executing the following block produces exactly the same result as manually doing Create → New Part:

      geometry1.SendCommand(Command="""

      // regenerates
      agb.Regen();

      agb.FormNewPartFromAllBodies();

      // regenerates
      agb.Regen();
      """)

    • Gary Stofan
      Ansys Employee

      Yes that will work fine for your purpose. 
      Going forward, Python scripting in Discovery is the recommended method.

    • mjmiddle
      Ansys Employee

      Design Modeler is in maintenance mode and the scripting was never developed completely in this application because it was moved to maintenance mode not long after they began adding python scripting methods. But there are ways to get scripting done in DM both with jscript and python. Your SendCommand method will send jscript to DM, by default, when a language is not specified. You can send python with this command:

      DMCmds = '''
      #command 1
      #command 2
      '''
      system = GetSystem(Name="Geom")  # Specify system name
      geometry1 = system.GetContainer(ComponentName="Geometry")
      geometry1.SendCommand(Language="Python", Command=DMCmds)

      You can create ACt extensions in DM to make your own Outline features. Here is some python code that could be used in a DM ACT extension to create a part from bodies:
       
      part1 = ExtAPI.DataModel.GeometryBuilder.Operations.Tools.CreatePart([b0, b1])    # Used for creating part from bodies if done in an callback of ACT extension
      part1.Name = "My part"    # The Name is mandatory
      # b0, b1 must be PSBody type from bodies created under ExtAPI.DataModel.GeometryBuilder, not DMBody accessed under ExtAPI.DataModel.GeoData.Bodies
       
      Creating part manually without need of an callback:
       
      Create part from selected bodies:
      part1 = Ansys.ACT.DesignModeler.APIConfig.AgApplet.BatchMgr.FormNewPartFromSelectedBodies()
      Create part from all bodies:
      part1 = Ansys.ACT.DesignModeler.APIConfig.AgApplet.BatchMgr.FormNewPartFromAllBodies()
      ExtAPI.DataModel.FeatureManager.Generate()   # Needed to refresh the Outline
       
      Selection of geometry if ID is known (face ID below):
      sel = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
      sel.Ids = [face_Id]
      #sel.Ids = [int(face.SeqNum)]    # must cast to int if get SeqNum from geometry object
      ExtAPI.SelectionManager.AddSelection(sel)  # highlights selection in viewer.  Not always necessary to highlight.
      # can also use a body object (ExtAPI.DataModel.GeoData.Bodies[0]) as the argument for AddSelection()
       
      Some options under part retreived through creation functions above can be accessed directly instead of going through InternalObject when retrieved from ExtAPI.DataModel.GeoData.Parts
      Set Shared topology:
      part1.SharedTopology = 0    # 0=Automatic, 1=Edge Joints (for surfaces), 2=Imprints, 3=None
      ExtAPI.DataModel.FeatureManager.Generate()   # Needed to refresh the Outline
Viewing 4 reply threads
  • You must be logged in to reply to this topic.
[bingo_chatbox]