Is there any API to extract contact initial information using Mechanical scripting?

Options
Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 813
First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member

Or alternatively is it possible to extract a .txt file for contact information?

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 813
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Options

    Below code can be adapted.

    import os
    
    def create_Folders(Folder_Path,Folder_Name):
        directory = os.path.join(Folder_Path,Folder_Name)
        check_folder = os.path.isdir(directory)
        if not check_folder:
            os.makedirs(directory)
    
        return directory
    
    def _getWd():
        #same folder with .project file
        wd = ExtAPI.DataModel.Project.Model.Analyses[0].WorkingDir
        return wd
    
    Model = ExtAPI.DataModel.Project.Model
    ContactTool = Model.Connections.GetChildren[Ansys.ACT.Automation.Mechanical.Connections.ContactTool](True)
    
    try:
        ContactTool[0].Delete()
        Model.Connections.AddContactTool()
    except:
        pass
    
    ContactTool = Model.Connections.GetChildren[Ansys.ACT.Automation.Mechanical.Connections.ContactTool](True)
    if(len(ContactTool) == 0):
        Model.Connections.AddContactTool()
        ContactTool = Model.Connections.GetChildren[Ansys.ACT.Automation.Mechanical.Connections.ContactTool](True)
    
    
    ContactTool[0].GenerateInitialContactResults() #With this API active window is shifting to Contact Tool but our aim is to have active window on Initial Information
    ExtAPI.DataModel.Tree.Refresh()
    ContactTool[0].Children[0].Activate()
    #ExtAPI.Application.ScriptByName("jscript").ExecuteCommand('DS.Script.doDetermineContactInitialStatus();') # Alternative to make Initial Information as active window
    
    folder_path = create_Folders(_getWd(),"Checker Tool")
    #ExtAPI.DataModel.Tree.Refresh()
    _contact_out_file = os.path.join(folder_path,'_contact_info.txt').Replace("\\","/")
    ExtAPI.Application.ScriptByName("jscript").ExecuteCommand('WB.PreferenceMgr.Preference("PID_Open_Excel") = 0;') # Blocking Excel from opening after export
    ExtAPI.Application.ScriptByName("jscript").ExecuteCommand('DS.Script.toggleWorksheetVisibilityInContexMenu();')  # Turn on worksheet mode with "Result Summary" section selected
    ExtAPI.Application.ScriptByName("jscript").ExecuteCommand('DS.Script.doExportWorksheetToTextFile("'+_contact_out_file+'");') # Exporting result, replace path in this line