Workbench script (createautomaticconnections) does not work

Options
Erik Kostson
Erik Kostson Member, Employee Posts: 124
First Answer Name Dropper First Anniversary Ansys Employee
edited June 2023 in Structures

I am running the below wbjn script from workbench and I think all works except of the CreateAutomaticConnections() call as no contacts are created. The same script (cmd) runs fine within mechanical scripting console.

import clr
clr.AddReference("Ansys.ACT.Core")
import Ansys.ACT.Core
appAPI = Ansys.ACT.Core.ApplicationRepository.GetApplication("Project")
ExtAPI = appAPI.GetExtensionApi(None)
cmd='''
ch=ExtAPI.DataModel.Project.Model.Connections.Children
if len(ch)>0:
    for chi in ch:
        chi.Delete()
else:
    print("No connections")
ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS
connections=ExtAPI.DataModel.Project.Model.Connections
connectionsg = connections.AddConnectionGroup()
connectionsg.Name="My_Contacts"
connectionsg.ToleranceType = ContactToleranceType.Value
connectionsg.ToleranceValue = Quantity(0.11, "m")
ExtAPI.DataModel.Project.Model.Connections.CreateAutomaticConnections()
'''
system = GetSystem(Name="SYS")
model = system.GetContainer(ComponentName="Model")
model.SendCommand(Language="Python", Command=cmd)

Best Answer

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 124
    First Answer Name Dropper First Anniversary Ansys Employee
    edited June 2023 Answer ✓
    Options

    We need to run it in interactive mode. To do that, replace the last 3 lines in the script above with the following lines below, then it is fine and the contacts are generated:


    system = GetSystem(Name="SYS")
    model = system.GetContainer(ComponentName="Model")
    model.Edit(Interactive=True)
    model.SendCommand(Language="Python", Command=cmd)
    model.Exit()