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.
General Mechanical

General Mechanical

Topics related to Mechanical Enterprise, Motion, Additive Print and more.

Establishing Workflow via Python Coding for model updating in different platform

    • Sampetai_Koen
      Subscriber

      I have an assembly in Autodesk Inventor, whose parameters I want to import to Parameter Set and subsequently to Response Surface Optimization. As far as I know, I can extract parameters from a 3D CAD design in Autodesk Inventor, as displayed in this video https://www.youtube.com/watch?v=r1rU2DhUmtw. Unfortunately, I don't have the hardware to do so (minimum 4GB of GPU), thus my design doesn't open in ANSYS Discovery. 1) If the issue is something else please let me know. In Inventor, I have parametrized my design, so when I change the parameters from the Excel spreadsheet, they automatically change the design. The problem is that when I press "Update from CAD" button in ANSYS Mechanical (I have used the built-in application in Inventor to load the design in ANSYS), the contacts change and the mesh as well, thus I have to re-apply them manually (Bonded, MPC formulation, Constraint Type: Uncoupled U to ROT, selection of surfaces/bodies for contacts, mesh method/sizing). 2) How can I create a workflow by using code to do that automatically? I have already created the Named Selections in Inventor and they are visible to Ansys Mechanical, but how do I connect them via coding? When I run the Optimization, I want these events to happen automatically, otherwise it won't run, because the Contacts and the Mesh will not be defined. Moreover, I need the code to select specific parts and designate the Method and the element size for these parts. What kind of code should I write? Where do I find documentation about it? Do I write it in Ansys Mechanical or do I use ACTWorkflowDesigner? I am a bit confused regarding the utility of coding in ANSYS in a) ANSYS APDL, b) in ANSYS Mechanical (scripting) and c) In some other external sosftware (

      ). 

      What I have done so far is: 1) Create named selections in Inventor, 2) Group all surface and solid parts and create named selections as well, 3) Write code in scripting within ANSYS Mechanical so the mesh and the contacts are completed automatically when I run the script. What I want to do, is create a workflow like this: a) Design the assembly in Inventor and export the parameters b) Insert the parameters into Parameter Set, c) Create Design of Experiments points, d) Have a piece of code that is going to assign the right mesh and contacts in every point d) Run Response Surface Optimization for Model updating. 

      This is the code I have written so far:

      Model = ExtAPI.DataModel.Project.Model
      Geometry = Model.Geometry
      Material = Model.Materials
      Mesh= Model.Mesh
       
      # Surface Meshing:
          # Sizing:
      M1 = Mesh.AddSizing()
      M1.Location=ExtAPI.DataModel.GetObjectsByName("Surfaces")[0]
      M1.ElementSize = Quantity(4.75,"mm")
          # Method:
      M2 = Mesh.AddAutomaticMethod()
      M2.Location=ExtAPI.DataModel.GetObjectsByName("Surfaces")[0]
      M2.Method =  MethodType.AllQuad
       
      # Solids Meshing
          # Sizing:
      M3 = Mesh.AddSizing()
      M3.Location=ExtAPI.DataModel.GetObjectsByName("Solids")[0]
      M3.ElementSize = Quantity(5.25,"mm")
          # Method:
      M4 = Mesh.AddAutomaticMethod()
      M4.Location=ExtAPI.DataModel.GetObjectsByName("Solids")[0]
      M4.Method =  MethodType.MultiZone
      M4.SurfaceMeshMethod=1
      Mesh.Update()
      ###########################################################################################
      # Contacts:
       
              # Fuselage with interior side of Interior_Brackets
      Connections_1 = Model.Connections.AddConnectionGroup()
      Connections_1.Name = "Fuselage_Interior_L_Brackets"
      Connections_1.Children
       
      target_names = [
          "NS_L_bracket1_InteriorSurface",
          "NS_L_bracket2_InteriorSurface",
         "NS_L_bracket3_InteriorSurface",
         "NS_L_bracket4_InteriorSurface",
         "NS_L_bracket5_InteriorSurface",
         "NS_L_bracket6_InteriorSurface",
         "NS_L_bracket7_InteriorSurface",
         "NS_L_bracket8_InteriorSurface",
         "NS_L_bracket9_InteriorSurface",
         "NS_L_bracket10_InteriorSurface",
         "NS_L_bracket11_InteriorSurface",
         "NS_L_bracket12_InteriorSurface"
      ]
       
       
       
      source_location = ExtAPI.DataModel.GetObjectsByName("NS_Fuselage")[0]
       
      k=0
      for tname in target_names:
          k+=1
          target_location = ExtAPI.DataModel.GetObjectsByName(tname)[0]
          contact = Connections_1.AddContactRegion()
          contact.SourceLocation = source_location
          contact.ContactShellFace = ShellFaceType.Bottom
          contact.TargetLocation = target_location
          contact.ContactType = ContactType.Bonded
          contact.ContactFormulation = ContactFormulation.MPC
          contact.ConstraintType =  ContactConstraintType.ProjectedUncoupleUtoROT
          contact.PinballRegion=ContactPinballType.Radius
          contact.PinballRadius = Quantity(2,"mm")
          
              # Fuselage with exterior side of Interior_Brackets
      Connections_2 = Model.Connections.AddConnectionGroup()
      Connections_2.Name = "Fuselage_Interior_Interior_Bracket"
      Connections_2.Children
       
      target_names2 = [
          "NS_Interior_Bracket1_ExteriorSurface",
          "NS_Interior_Bracket2_ExteriorSurface",
         "NS_Interior_Bracket3_ExteriorSurface",
         "NS_Interior_Bracket4_ExteriorSurface",
         "NS_Interior_Bracket5_ExteriorSurface",
         "NS_Interior_Bracket6_ExteriorSurface"
      ]
       
       
       
      source_location = ExtAPI.DataModel.GetObjectsByName("NS_Fuselage")[0]
       
      k=0
      for tname in target_names2:
          k+=1
          target_location = ExtAPI.DataModel.GetObjectsByName(tname)[0]
          contact = Connections_2.AddContactRegion()
          contact.SourceLocation = source_location
          contact.ContactShellFace = ShellFaceType.Top
          contact.TargetLocation = target_location
          contact.ContactType = ContactType.Bonded
          contact.ContactFormulation = ContactFormulation.MPC
          contact.ConstraintType =  ContactConstraintType.ProjectedUncoupleUtoROT
          contact.PinballRegion=ContactPinballType.Radius
          contact.PinballRadius = Quantity(2,"mm")
          
                  # Left Wing L_brackets bottom side
      Connections_3 = Model.Connections.AddConnectionGroup()
      Connections_3.Name = "LeftWing_L_Brackets_1_2_3_4_5_6_BottomSurface"
      Connections_3.Children
       
      target_names3A = [
          "NS_L_bracket1_BottomSurface",
          "NS_L_bracket2_BottomSurface",
          "NS_L_bracket3_BottomSurface"
      ]
       
      target_names3B = [
          "NS_L_bracket4_BottomSurface",
          "NS_L_bracket5_BottomSurface",
          "NS_L_bracket6_BottomSurface"
      ]
       
       
      source_location = ExtAPI.DataModel.GetObjectsByName("NS_LeftWing")[0]
       
      k=0
      for tname in target_names3A:
          k+=1
          target_location = ExtAPI.DataModel.GetObjectsByName(tname)[0]
          contact = Connections_3.AddContactRegion()
          contact.SourceLocation = source_location
          contact.ContactShellFace = ShellFaceType.Bottom
          contact.TargetLocation = target_location
          contact.ContactType = ContactType.Bonded
          contact.ContactFormulation = ContactFormulation.MPC
          contact.ConstraintType =  ContactConstraintType.ProjectedUncoupleUtoROT
          contact.PinballRegion=ContactPinballType.Radius
          contact.PinballRadius = Quantity(2,"mm")
       
      k=0
      for tname in target_names3B:
          k+=1
          target_location = ExtAPI.DataModel.GetObjectsByName(tname)[0]
          contact = Connections_3.AddContactRegion()
          contact.SourceLocation = source_location
          contact.ContactShellFace = ShellFaceType.Top
          contact.TargetLocation = target_location
          contact.ContactType = ContactType.Bonded
          contact.ContactFormulation = ContactFormulation.MPC
          contact.ConstraintType =  ContactConstraintType.ProjectedUncoupleUtoROT
          contact.PinballRegion=ContactPinballType.Radius
          contact.PinballRadius = Quantity(2,"mm")
       
                      # Right Wing L_brackets bottom side
      Connections_4 = Model.Connections.AddConnectionGroup()
      Connections_4.Name = "RightWing_L_Brackets_7_8_9_10_11_12_BottomSurface"
      Connections_4.Children
       
      target_names4A = [
          "NS_L_bracket7_BottomSurface",
          "NS_L_bracket8_BottomSurface",
          "NS_L_bracket9_BottomSurface"
      ]
       
      target_names4B = [
          "NS_L_bracket10_BottomSurface",
          "NS_L_bracket11_BottomSurface",
          "NS_L_bracket12_BottomSurface"
      ]
       
       
      source_location = ExtAPI.DataModel.GetObjectsByName("NS_RightWing")[0]
       
      k=0
      for tname in target_names4A:
          k+=1
          target_location = ExtAPI.DataModel.GetObjectsByName(tname)[0]
          contact = Connections_4.AddContactRegion()
          contact.SourceLocation = source_location
          contact.ContactShellFace = ShellFaceType.Top
          contact.TargetLocation = target_location
          contact.ContactType = ContactType.Bonded
          contact.ContactFormulation = ContactFormulation.MPC
          contact.ConstraintType =  ContactConstraintType.ProjectedUncoupleUtoROT
          contact.PinballRegion=ContactPinballType.Radius
          contact.PinballRadius = Quantity(2,"mm")
       
      k=0
      for tname in target_names4B:
          k+=1
          target_location = ExtAPI.DataModel.GetObjectsByName(tname)[0]
          contact = Connections_4.AddContactRegion()
          contact.SourceLocation = source_location
          contact.ContactShellFace = ShellFaceType.Bottom
          contact.TargetLocation = target_location
          contact.ContactType = ContactType.Bonded
          contact.ContactFormulation = ContactFormulation.MPC
          contact.ConstraintType =  ContactConstraintType.ProjectedUncoupleUtoROT
          contact.PinballRegion=ContactPinballType.Radius
          contact.PinballRadius = Quantity(2,"mm")
          part_names=['Fuselage_Surface:1[Srf3]', 'Wing_Fuselage:1[Srf1]', 'Wing_Fuselage:2[Srf1]']
          parts = [ExtAPI.DataModel.GetObjectsByName(pn)[0] for pn in part_names]
      (I know I can also include creating Named Selections out of specific parts I just haven't implemented this yet)

      Thanks in advance

    • Ashish Khemka
      Forum Moderator

      Hello,

      Please ask your question on the following forum: Home - Community Forum

      Regards,

      Ashish Khemka

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
[bingo_chatbox]