[英]Python scripting in ABAQUS
I have a python script to create ABAQUS model and run a job. 我有一个Python脚本来创建ABAQUS模型并运行作业。
I want to create a loop over a variable 我想在变量上创建一个循环
index=1:1:4, 索引= 1:1:4,
create four different models and run the four jobs for each model. 创建四个不同的模型,并为每个模型运行四个作业。
A model is named 'Model-1' for instance in the following line: 例如,以下行中的模型名为“ Model-1”:
##-----------------------------------------------------------------------
mdb.models['Model-1'].ConstrainedSketch(name='__profile__', sheetSize=sqrlen)
##-----------------------------------------------------------------------
In creating a loop, I create a string as follows: 在创建循环时,我将创建一个字符串,如下所示:
##-----------------------------------------------------------------------
index='1'
modelname='\''+'Model' + index+ '\''
# Square Part is created
mdb.models[modelname].ConstrainedSketch(name='__profile__', sheetSize=sqrlen)
##-------------------------------------------------------------------------
When I run the script in ABAQUS, it gives error saying 'Model1'as follows: 当我在ABAQUS中运行脚本时,出现如下错误:“ Model1”:
##-------------------------------------------------------------------------
File "d:/abaqus_working_directory/scripting_example/simulation/scripting_loop.py", line 22, in <module>
mdb.models[modelname].ConstrainedSketch(name='__profile__', sheetSize=sqrlen) #### sqrlen
KeyError: 'Model1'
Exit from main file [Kernel]: d:/abaqus_working_directory/scripting_example/simulation/scripting_loop.py
##-------------------------------------------------------------------------
I want to use the string modelname( with value ='Model-1') instead of writing 'Model-1' in the python script 我想使用字符串modelname(值='Model-1')而不是在python脚本中编写'Model-1'
mdb.models['Model-1'].ConstrainedSketch(name=....)
mdb.models[modelname].ConstrainedSketch(name=...)
when it is called. 当它被调用时。
Any help is deeply appreciated. 任何帮助深表感谢。
Sincerely, Me. 真诚的,我。
You are mixing two different names, Model-1
and Model1
您正在混合使用两个不同的名称, Model-1
和Model1
In your loop creation, include -
in the modelname
. 在循环创建中,在modelname
包含-
。 You can do something like this: 您可以执行以下操作:
##-----------------------------------------------------------------------
index='1'
modelname='\''+'Model-' + index+ '\''
# Square Part is created
mdb.models[modelname].ConstrainedSketch(name='__profile__', sheetSize=sqrlen)
##-------------------------------------------------------------------------
Also, you should use 另外,您应该使用
modelname='Model-' + index
since that will give you a string without the extra quotes. 因为那样会给你一个没有多余引号的字符串。
don't work with the string names at all. 根本不使用字符串名称。 Early in the script define: 在脚本的早期定义:
model=mdb.models['Model-1']
then do for example: 然后例如:
model.ConstrainedSketch..
if you are working with multiple models then similarly create a list of model objects. 如果使用多个模型,则类似地创建模型对象列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.