In Workbench Mechanical scripting, how can I get the location of an external data file?

Options
Landon Mitchell Kanner
Landon Mitchell Kanner Member, Employee Posts: 208
First Answer First Comment 5 Likes First Anniversary

Here is my project page schematic:

I want to get this file location:

From the Mechanical model where it is use:

Answers

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 208
    First Answer First Comment 5 Likes First Anniversary
    edited September 2023
    Options
    def GetImportedLoadMainFile(ImportedLoadGroup):
        import wbjn
        coord = ImportedLoadGroup.Source.Split(':')[0]
        WBcmds = '''
    coord = "<$coord$>"
    import clr
    clr.AddReference("Ans.UI")
    import Ansys.UI
    clr.AddReference("Ans.ProjectSchematic")
    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}
    setup1 = coord_map2[coord]
    try: setup1 = setup1.GetContainer()
    except: pass
    externalLoadData1 = setup1.GetExternalLoadData()
    externalLoadFileData1 = externalLoadData1.GetExternalLoadFileData(Name="ExternalLoadFileData")
    file = externalLoadFileData1.File.Location
    returnValue(file)
    '''.replace('<$coord$>',coord)
        return wbjn.ExecuteCommand(ExtAPI,WBcmds)
    
    
    impload = ExtAPI.DataModel.GetObjectsByType(Ansys.ACT.Automation.Mechanical.ImportedLoads.ImportedLoadGroup)[0]
    impload_file = GetImportedLoadMainFile(impload)