How to promote imported bolt load in ansys mechanical using script

zhen
zhen Member Posts: 2
First Comment
**
edited February 24 in Structures

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

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 339
    25 Answers 100 Comments 25 Likes First Anniversary
    ✭✭✭✭

    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.

  • raviraj3997
    raviraj3997 Member, Employee Posts: 1
    First Comment First Anniversary Ansys Employee
    ✭✭✭

    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 tree

    cmds = "DS.Script.ExternalModelWorksheetPerformPromoteOperations({}, {});"

    options = bolt_pret.InternalObject.PromoteOrCreateOptions
    nOptions = options.Count()

    environments = Model.Analyses
    nEnvironments = environments.Count

    below 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)____

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 85
    10 Comments 5 Answers First Anniversary Solution Developer Community of Practice Member
    ✭✭✭✭

    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.Count

    below 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)