DomC Posted February 23, 2016 Share Posted February 23, 2016 (edited) Hi I am trying to give vs.ForEachObject an additional argument. My Questions: 1. Is it Possible, to somehow use a search criteria example ('SEL=TRUE') for a "manually" created while loop? 2. Is there any chance, to add arguments in the vs.ForEachObject() loop? What I tried: vs.ForEachObject(GetParts, "SEL=TRUE") #This works option1='test' vs.ForEachObject(GetParts(h,option1), "SEL=TRUE") #Do not work (clear: because h is not referenced) option1='test' vs.ForEachObject(GetParts, "SEL=TRUE",option1) #Do not work option1='test' vs.ForEachObject(GetParts, "SEL=TRUE",option1) Is it just, i do not know enough about python or is just not possible because the ForEach-Functions, do not support that? Example Code(Python): sort='xy'#'yx', 'None' ObjList=[] BBoxList=[] ObjList_Sorted=[] width_list=[] height_list=[] def GetParts(h): #h ist handle to the ForEachObject Loop ObjList.append(h) p1,p2= vs.GetBBox(h) width=p2[0]-p1[0] height=p1[1]-p2[1] width_list.append(width) height_list.append(height) BBoxList.append((p1,p2)) h=vs.NextSObj(h) return() option1='test' vs.ForEachObject(GetParts, "SEL=TRUE") vs.AlrtDialog(str(width_list)) #Example while loop. It would be great, to loop objects with search criteria instead of vs.FSActLayer() etc. ObjList=[] BBoxList=[] ObjList_Sorted=[] width_list=[] height_list=[] def GetParts(h,option1): if h==None: #the same like vs.Handle(0) vs.AlrtDialog('please select object(s)') while h!=None: #the same like vs.Handle(0) ObjList.append(h) p1,p2= vs.GetBBox(h) width=p2[0]-p1[0] height=p1[1]-p2[1] width_list.append(width) height_list.append(height) BBoxList.append((p1,p2)) h=vs.NextSObj(h) return() h=vs.FSActLayer() GetParts(h,option1='test') vs.AlrtDialog(str(width_list)) Edited February 23, 2016 by DomC Quote Link to comment
JBenghiat Posted February 23, 2016 Share Posted February 23, 2016 In your examples, you don't really do anything with option1, so I'm not clear what you are trying to accomplish. The ForEach functions can only take one argument, the handle to process. Why not just set a variable and use it in your GetParts function? In your top code, you can just use option1, and it will evaluate to 'test.' Also note that you don't need to iterate handles with NextSObj -- the FEO function does this for you. You also may want to look at ForEachObjectInList / Layer. They offer some more robust options on which selected objects you process. Alternatively, use FEO simply to build your list of handles, and use a second function to iterate over your list and gather your data. Then you can use as many arguments as you want. HTH, Josh Quote Link to comment
DomC Posted February 23, 2016 Author Share Posted February 23, 2016 Hi Josh Your statements are perfectly helpful, thanks. I know, that option1 do nothing in my script. I Just evaluates the possibilities :-) I do not loved FEO, but now I understand it, it looks very powerful. As far as I can see, the good way is (as you said), to use FEO to very fast and easy to build handle lists. And then loop through them, to add objects (which is not a good idea inside the FEO loop) Thanks again Dom Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.