Can I update/generate/etc. an entire model except for the analyses?

Member Posts: 33
10 Comments Name Dropper Photogenic
**

I have a script that creates objects of a wide variety of different types, and I would like to update, generate, or otherwise "solve" those objects except for the analysis/analyses itself/themselves. For example, I can execute ExtAPI.DataModel.Project.Model.NamedSelections.GenerateAllNamedSelections() to generate all the named selections, ExtAPI.DataModel.Project.Model.PartTransformGroup.TransformGeometry() to perform the geometry transformations, and ExtAPI.DataModel.Project.Model.mesh.GenerateMesh() to generate the mesh, but it'd be better if I could do something like ExtAPI.DataModel.Project.Model.GenerateModel() to perform all these tasks and others with the exception of actually running the simulation(s).

I suppose, ultimately what I'm looking for is a means of executing the "Update" function in Workbench on the "Model" cell (see below) from inside Mechanical.

Best Answers

  • Member, Employee, GitHub-issue-creator Posts: 353
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    Answer ✓
    1. def UpdateModel(analysis):
    2. cmds = """
    3. AllSys=GetAllSystems()
    4. for sys in AllSys:
    5. if sys.DisplayText=='%s':
    6. modelComponent1 = sys.GetComponent(Name="Model")
    7. modelComponent1.Update(AllDependencies=True)
    8. """%(analysis.SystemCaption)
    9. def Internal_UpdateModel():
    10. import wbjn
    11. wbjn.ExecuteCommand(ExtAPI, cmds)
    12. thread = System.Threading.Thread(System.Threading.ThreadStart(Internal_UpdateModel))
    13. thread.Start()
    14.  
    15. analysis0 = ExtAPI.DataModel.AnalysisList[0]
    16. UpdateModel(analysis0)

    This assumes that the analysis blocks on the Project Page have unique display names. If you want to make it more robust, you could identify the analysis block using analysis.CellId instead. See https://discuss.ansys.com/discussion/2476/in-workbench-mechanical-scripting-how-can-i-get-the-location-of-an-external-data-file

  • Member, Employee, GitHub-issue-creator Posts: 353
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    Answer ✓

    I made a few tweaks for robustness:

    1. def UpdateModel(model):
    2. WBcmds = """
    3. import clr
    4. clr.AddReference("Ans.UI")
    5. clr.AddReference("Ans.ProjectSchematic")
    6. import Ansys.UI
    7. import Ansys.ProjectSchematic
    8.  
    9. view1 = Ansys.UI.UIManager.Instance.GetActiveWorkspace().GetView(Ansys.ProjectSchematic.View.ProjectSchematicView.ViewName)
    10. coord_map = dict(view1.CoordinateMap)
    11. coord_map2 = {Ansys.UI.IDManager.GetAlphabeticLabelFromCoordinate(coord_map[key]):key for key in coord_map if str(type(key)) == "<type 'DataReference'>" }
    12.  
    13. coord_map2["<$cell_id$>"].Update()
    14. """.replace("<$cell_id$>", model.CellId)
    15.  
    16. def Internal_UpdateModel():
    17. import wbjn
    18. wbjn.ExecuteCommand(ExtAPI, WBcmds)
    19. thread = System.Threading.Thread(System.Threading.ThreadStart(Internal_UpdateModel))
    20. thread.Start()
    21.  
    22.  
    23. UpdateModel(ExtAPI.DataModel.Project.Model)

Answers

  • Member Posts: 33
    10 Comments Name Dropper Photogenic
    **

    Thanks! For other's reference, if you use the CoordinateMap method from the linked discussion, the object returned by coord_map2[coord] corresponds to the model component. Here's what I ended up with:

    1. import wbjn
    2.  
    3. def updt_mdl(mdl):
    4. WBcmds = """
    5. import clr
    6.  
    7. clr.AddReference("Ans.UI")
    8. clr.AddReference("Ans.ProjectSchematic")
    9.  
    10. import Ansys.UI
    11. import Ansys.ProjectSchematic
    12.  
    13. view1 = Ansys.UI.UIManager.Instance.GetActiveWorkspace().GetView(Ansys.ProjectSchematic.View.ProjectSchematicView.ViewName)
    14.  
    15. coord_map = dict(view1.CoordinateMap)
    16. coord_map2 = {Ansys.UI.IDManager.GetAlphabeticLabelFromCoordinate(coord_map[key]):key for key in coord_map}
    17.  
    18. coord_map2["<$cell_id$>"].Update()
    19. """.replace("<$cell_id$>", mdl.CellId)
    20. return wbjn.ExecuteCommand(ExtAPI, WBcmds)
    21.  
    22. updt_mdl(ExtAPI.DataModel.Project.Model)

Welcome!

It looks like you're new here. Sign in or register to get started.