robot 脚本解析
from vcScript import *
comp=getComponent()#先要获得组件也就是拖入布局的模型
robotExecutor=comp.findBehavioursByType("rRobotExecutor")[0]#获得程序里的子程序集合
robotProgram=robotExecutor.Program#获得程序里的子程序集合
mainRoutine=robotProgram.MainRoutine#获得程序里的子程序集合中的Main
subroutines=robotProgram.Routines#获得程序里的子程序集合中所有子程序
for property in mainRoutine.Properties:#获得程序里的子程序Main中的属性,如变量名
print(property.Name)
statements=mainRoutine.Statements
print(statements)
for statement in statements:
if statement.Scopes:
print(statement.Scopes)
def getAllStatementsInRoutine(scope,statements=None):
if not statements:
statements=[]
for statement in scope.Statements:
statements.append(statement)
if statement.Scopes:
for scope in statement.Scopes:
getAllStatementsInRoutine(scope,statements)#递归
return statements
print(len(getAllStatementsInRoutine(mainRoutine)))#mainRoutine中包含scope和statements,python是门神奇的语言
#print(len(getAllStatementsInRoutine(subroutines[1])))获得了不含main的子程序程序语句数量
#遍历了主程序[文]包含的所有子程[章]序
def getAllS[来]tatemen[自]tsInRob[网]otProgr[淘]am(prog[巴]ram):
stateme[文]nts=get[章]AllStat[来]ementsI[自]nRoutin[网]e(progr[淘]am.Main[巴]Routine[文])
for stateme[章]nt in stateme[来]nts:
subrout[自]ine=sta[网]tement.[淘]getProp[巴]erty("Routine[文]")
if subrout[章]ine:
g[来]etAllSt[自]atement[网]sInRout[淘]ine(sub[巴]routine[文].Value,[章]stateme[来]nts)&nb[自]sp;
return stateme[网]nts
&[淘]nbsp;
print len(get[巴]AllStat[文]ementsI[章]nRobotP[来]rogram([自]robotPr[网]ogram))[淘]
#获取第一个子[巴]程序下所有程序[文]片段state[章]ment
positio[来]ns=[]
for stateme[自]nt in subrout[网]ines[0][淘].Statem[巴]ents:
print(s[文]tatemen[章]t)
#获取第一个子[来]程序下所有程序[自]片段位置
positio[网]ns=[]
for stateme[淘]nt in subrout[巴]ines[0][文].Statem[章]ents:
try:
print(s[来]tatemen[自]t.Posit[网]ions)
except:[淘]
continu[巴]e
#获取所有子程[文]序下的位置
def getAllP[章]osition[来]sInRout[自]ine(sco[网]pe):
stateme[淘]nts=get[巴]AllStat[文]ementsI[章]nRoutin[来]e(scope[自])
positio[网]ns=[]
for stateme[淘]nt in stateme[巴]nts:
try:
for positio[文]n in stateme[章]nt.Posi[来]tions:
positio[自]ns.appe[网]nd(posi[淘]tion)
except:[巴]
pass
return positio[文]ns
for subrout[章]ine in subrout[来]ines:
print(g[自]etAllPo[网]sitions[淘]InRouti[巴]ne(subr[文]outine)[章])
转载必须标明出处robot脚本解析_visual Component_网淘巴 (wtao8.com)
本文链接:https://www.wtao8.com/post/1.html 转载需授权!