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

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
-
def UpdateModel(analysis): cmds = """ AllSys=GetAllSystems() for sys in AllSys: if sys.DisplayText=='%s': modelComponent1 = sys.GetComponent(Name="Model") modelComponent1.Update(AllDependencies=True) """%(analysis.SystemCaption) def Internal_UpdateModel(): import wbjn wbjn.ExecuteCommand(ExtAPI, cmds) thread = System.Threading.Thread(System.Threading.ThreadStart(Internal_UpdateModel)) thread.Start() analysis0 = ExtAPI.DataModel.AnalysisList[0] 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-file1 -
I made a few tweaks for robustness:
def UpdateModel(model): WBcmds = """ import clr clr.AddReference("Ans.UI") clr.AddReference("Ans.ProjectSchematic") import Ansys.UI import Ansys.ProjectSchematic view1 = Ansys.UI.UIManager.Instance.GetActiveWorkspace().GetView(Ansys.ProjectSchematic.View.ProjectSchematicView.ViewName) coord_map = dict(view1.CoordinateMap) coord_map2 = {Ansys.UI.IDManager.GetAlphabeticLabelFromCoordinate(coord_map[key]):key for key in coord_map if str(type(key)) == "<type 'DataReference'>" } coord_map2["<$cell_id$>"].Update() """.replace("<$cell_id$>", model.CellId) def Internal_UpdateModel(): import wbjn wbjn.ExecuteCommand(ExtAPI, WBcmds) thread = System.Threading.Thread(System.Threading.ThreadStart(Internal_UpdateModel)) thread.Start() UpdateModel(ExtAPI.DataModel.Project.Model)
1
Answers
-
Thanks! For other's reference, if you use the
CoordinateMap
method from the linked discussion, the object returned bycoord_map2[coord]
corresponds to the model component. Here's what I ended up with:import wbjn def updt_mdl(mdl): WBcmds = """ import clr clr.AddReference("Ans.UI") clr.AddReference("Ans.ProjectSchematic") import Ansys.UI import Ansys.ProjectSchematic view1 = Ansys.UI.UIManager.Instance.GetActiveWorkspace().GetView(Ansys.ProjectSchematic.View.ProjectSchematicView.ViewName) coord_map = dict(view1.CoordinateMap) coord_map2 = {Ansys.UI.IDManager.GetAlphabeticLabelFromCoordinate(coord_map[key]):key for key in coord_map} coord_map2["<$cell_id$>"].Update() """.replace("<$cell_id$>", mdl.CellId) return wbjn.ExecuteCommand(ExtAPI, WBcmds) updt_mdl(ExtAPI.DataModel.Project.Model)
1