How to promote imported bolt load in ansys mechanical using script
Currently, i'm now using python script to modifiy ansys mechanical model setup.
I want to promote bolt load to static structural, as is shown in the image below.
imported bolt load is already obtained, but the following code is not working.
====
- run the code in Shell
bolt = DataModel.GetObjectsByType(DataModelObjectCategory.ImportedBoltPretensions)
bolt[0].Promote([0], 1, 1)
This causes a collapse of mechanical.
How to correct the code?
Answers
-
For any reproducible action where you are getting Mechanical to crash via the API you should contact your local Ansys support and open a service ticket. This would be related to a defect and should be logged for future fix.
Unfortunately I don't know of a work around for this problem at the moment, but there may be options I am not aware of.
0 -
Below is the workaround that could help. It uses JavaScript. Using JavaScript is not supported officially by Ansys, but you can try and see if this helps.
!---------------------------------------------------------------------------------
bolt_pret = Tree.FirstActiveObject # Assuming Imported bolt pretension object is selected in treecmds = "DS.Script.ExternalModelWorksheetPerformPromoteOperations({}, {});"
options = bolt_pret.InternalObject.PromoteOrCreateOptions
nOptions = options.Count()environments = Model.Analyses
nEnvironments = environments.Countbelow loops checks for the compatibility of object to be promoted with analysis type
Tree.Refresh()
for ioption in range(1, nOptions+1):
if bolt_pret.InternalObject.PromoteOrCreateOptionInEnvironment(options.Item(ioption)):
for iEnv in range(1, nEnvironments+1):
if bolt_pret[0].InternalObject.CanPromoteOrCreate(ioption,environments[iEnv-1].Id):
new_cmds = cmds.format(ioption,environments[iEnv-1].Id)
ExtAPI.Application.ScriptByName("jscript").ExecuteCommand(new_cmds)____0 -
Unfortunately, the Mechanical is crashing when you use Python API. We have a jscript based solution for you though.
Please note that we do not support using jscript and it may change in future. Please let me know how it goes.
Here is the snippet:
imported_bolt_pretension_object = DataModel.GetObjectsByType(DataModelObjectCategory.ImportedBoltPretensions)
bolt_pret = imported_bolt_pretension_object[0]
bolt_pret.Activate()
bolt_pret = Tree.FirstActiveObject
cmds = "DS.Script.ExternalModelWorksheetPerformPromoteOperations({}, {});"
options = bolt_pret.InternalObject.PromoteOrCreateOptions
nOptions = options.Count()environments = Model.Analyses
nEnvironments = environments.Countbelow loops checks for the compatibility of object to be promoted with analysis type
Tree.Refresh()
for ioption in range(1, nOptions+1):
if bolt_pret.InternalObject.PromoteOrCreateOptionInEnvironment(options.Item(ioption)):
for iEnv in range(1, nEnvironments+1):
if bolt_pret[0].InternalObject.CanPromoteOrCreate(ioption,environments[iEnv-1].Id):
new_cmds = cmds.format(ioption,environments[iEnv-1].Id)
ExtAPI.Application.ScriptByName("jscript").ExecuteCommand(new_cmds)0