How to create material
The materials can be created using the following method, but it fails when specifying the material name as a variable.
(When adding materialname = "bb" and rewriting matl1 = engineeringData1.CreateMaterial(Name= "aa")
as matl1 = engineeringData1.CreateMaterial(Name= materialname), it fails.)
Please tell me the solution.
import wbjn
pyCmd = '''
system1 = GetSystem(Name="SYS 5")
engineeringData1 = system1.GetContainer(ComponentName="Engineering Data")
matl1 = engineeringData1.CreateMaterial(Name= "aa")
matlProp1 = matl1.CreateProperty(
Name="Mooney-Rivlin",
Definition="2 Parameter",
Qualifiers={"Definition": "2 Parameter", "Behavior": ""})
matlProp1.SetData(
Index=-1,
Variables=["Material Constant C10"],
Values=[["0.69 [MPa]"]])
matlProp1.SetData(
Variables=["Material Constant C01"],
Values=[["0 [MPa]"]])
matlProp1.SetData(
Variables=["Incompressibility Parameter D1"],
Values=[["0 [MPa^-1]"]])
'''
wbjn.ExecuteCommand(ExtAPI, pyCmd)
Answers
-
Hi
The code you posted seems ok and runs from both WB and within Mechanical (script console).
Can you explain in more detail where the issue is in much more detail?
Also add a series of steps which cause this issue so forum members can reproduce it,In that way it is easier for forum members to provide feedback.
Erik
0 -
Hi Erik.
This code fails when executed.
(The bold text indicates the changes from the previous version.)import wbjn
materialname = "bb"
pyCmd = '''
system1 = GetSystem(Name="SYS 5")
engineeringData1 = system1.GetContainer(ComponentName="Engineering Data")
matl1 = engineeringData1.CreateMaterial(Name= materialname)
matlProp1 = matl1.CreateProperty(
Name="Mooney-Rivlin",
Definition="2 Parameter",
Qualifiers={"Definition": "2 Parameter", "Behavior": ""})
matlProp1.SetData(
Index=-1,
Variables=["Material Constant C10"],
Values=[["0.69 [MPa]"]])
matlProp1.SetData(
Variables=["Material Constant C01"],
Values=[["0 [MPa]"]])
matlProp1.SetData(
Variables=["Incompressibility Parameter D1"],
Values=[["0 [MPa^-1]"]])
'''
wbjn.ExecuteCommand(ExtAPI, pyCmd)1 -
Hello. Maybe this is the problem?
import wbjn materialname = "bb" pyCmd = ''' system1 = GetSystem(Name="SYS 5") engineeringData1 = system1.GetContainer(ComponentName="Engineering Data") matl1 = engineeringData1.CreateMaterial(Name="{}") matlProp1 = matl1.CreateProperty( Name="Mooney-Rivlin", Definition="2 Parameter", Qualifiers={{"Definition": "2 Parameter", "Behavior": ""}}) matlProp1.SetData( Index=-1, Variables=["Material Constant C10"], Values=[["0.69 [MPa]"]]) matlProp1.SetData( Variables=["Material Constant C01"], Values=[["0 [MPa]"]]) matlProp1.SetData( Variables=["Incompressibility Parameter D1"], Values=[["0 [MPa^-1]"]]) '''.format(materialname) wbjn.ExecuteCommand(ExtAPI, pyCmd)
1 -
I added string formatting to write the value of materialName into the string variable pyCmd.
0 -
Very helpful AlexGh - that works good
0 -
Thank you!!!
It worked well.1