我是个初学者,有点迷恋我写的代码。我正在为一些软件编写一个插件,试图从它的类中提取一些数据。在
这里有一个语句列表,我正在使用operator for执行。我对两种类型的语句感兴趣,分别是VC_STATEMENT_LINMOTION和VC_STATEMENT_PTPMOTION(还有许多其他类型)。
首先,在我的代码中,我看到这两种类型的语句中哪一种先出现。如果它是LinMotion,那么,我将获得这个LinMotion语句的一些提取值(通过转到那个函数(def get_initalvalues()),直到代码“满足”PtpMotion语句。完成后,它将转到def get_conf()函数,从中提取PtpMotion的数据。另外,在get_conf()中,如果满足后面的LinMotion,则从上一次迭代的PtpMotion获取数据。在
但它不起作用。在
我知道这听起来很重)。也许是我自己把它弄得太复杂了,解决办法也更简单了。在for statement in main_routine.Statements:
if statement.Type == VC_STATEMENT_LINMOTION or statement.Type == VC_STATEMENT_PTPMOTION:
def get_conf(*args):
global output
if statement.Type == VC_STATEMENT_PTPMOTION:
ptp_motion_conf = ""
Extracted string data is assigned to ptp_motion_conf which is later added to overall output
output += ptp_motion_conf
elif statement.Type == VC_STATEMENT_LINMOTION:
output += ptp_motion_conf #using data of VC_STATEMENT_PTPMOTION from last iteration
def get_initialconf(*args):
global output
if statement.Type == VC_STATEMENT_LINMOTION:
...
elif statement.Type == VC_STATEMENT_PTPMOTION:
get_conf()
statements = [] # getting list of statements to know which of LinMotion or PtpMotion goes first
for statement in main_routine.Statements:
statements.append(statement.Type)
if statements.index("LinMotion") < statements.index("PtpMotion"): #statement LinMotion goes first
get_initialconf()
elif statements.index("LinMotion") > statements.index("PtpMotion"):#statement PtpMotion goes first
get_conf()
我将尝试在示例中显示:
如果LinMotions语句先执行,则在ptp操作之前:
LinMotion(一些特殊的初始数据)
LinMotion(仍然是初始数据)
...
在所有其他LinMotion语句中,prog仍然使用初始数据,直到PtpMotion语句出现:
PtpMotion(它自己的PtpMotion数据)
如果LinMotion再次出现,则使用上一个PtpMotion语句中的数据
如果PtpMotion语句先在LinMotion之前,则
PtpMotion(它自己的PtpMotion数据)
如果出现Linmotion,则使用上一个PtpMotion语句中的数据