Ansys Learning Forum › Forums › Discuss Simulation › General Mechanical › Mechanical Scripting: Pressure Import componentwise › Reply To: Mechanical Scripting: Pressure Import componentwise
		
		
				
		
		
		
		
		
		
		
			February 7, 2024 at 3:45 pm		
	
			Subscriber		
		
	Â
Hello,
thank you for your support.
The first part works, but I still cannot change the components of the pressure. When I try to add it to the code like that:
Â
mechScriptCmds="""
wbAnalysisName = '{3}'
for item in ExtAPI.DataModel.AnalysisList:
    if item.SystemCaption == wbAnalysisName:
        analysis = item
mycaption = analysis.SystemCaption
ExtAPI.Log.WriteMessage(mycaption)
with Transaction():
    import glob
    import os
    DataPath = r'{0}'
    DataExtension = '{1}'
    allfiles = glob.glob1(DataPath,"*." + DataExtension)
    allfiles.sort(key=lambda f: int(''.join(filter(str.isdigit, f))))
    numfilestoload = len(allfiles)
    importedloadobjects = [child for child in analysis.Children if child.DataModelObjectCategory.ToString() == "ImportedLoadGroup"]
    usedimportedloadobj = importedloadobjects[-1]
    importedPres = usedimportedloadobj.AddImportedPressure()
    DefineByProp = importedPres.PropertyByName('PROPID_DefineByType')
    DefineByProp = 0    # 0="Components", 2="Normal To"
    namedsel_importedload = ExtAPI.DataModel.GetObjectsByName('{2}')[0]
    importedPres.Location = namedsel_importedload
    table = importedPres.GetTableByName("")
    for i in range(numfilestoload-1):
        table.Add(None)
    for i in range(numfilestoload):
        table[i][0] = "File"+str(i+1)+":"+str(allfiles[i])
        table[i][1] = "File"+str(i+2)+":"+str(allfiles[i+1])
        table[i][2] = "File"+str(i+3)+":"+str(allfiles[i+2])
        table[i][3] = (i+1)*100
    importedPres.ImportLoad()
""".format(DataPath,DataExtension,namedSelectionUsed,systemName)
model2 = system2.GetContainer(ComponentName="Model") 
model2.SendCommand(Language="Python", Command=mechScriptCmds) 
Â
When I run it nothing happens. I have of course tried several writing variations, but it doesn’t work. The components are apparently not turned on and therefore no further columns are created.
I also tried it like that, but it also doesnt work… I have seen this spelling several times, but never for imported pressure
Â
ImportedPres.DefineBy = LoadDefineBy.ComponentsÂ
Best regards
Dayana
Â
Â