Gonda Posted September 17, 2014 Share Posted September 17, 2014 Hi All, So, when working with Python scripts, is there any way to access current states of things? Specifically, I'm working on a tool that will take multiple selected objects, read information from them, compute and then modify the objects. What I'm running into is that it seems that most functions want a handle to an object to do anything useful...I've found I can use a custom selection via criteria; however, I can't find a way to get from a selection based on criteria to object handles. In a perfect world there would be some object or method (ie vs.CurrentSelection(). ) that would return either a single object handle or a list of multiple object handles...any thoughts and/or am I missing something obvious? Thanks, Jon Gonda Quote Link to comment
Vectorworks, Inc Employee klinzey Posted September 17, 2014 Vectorworks, Inc Employee Share Posted September 17, 2014 Take a look at ForEachObject(). It uses criteria, to return the handles one by one in the callback function. Quote Link to comment
Pat Stanford Posted September 17, 2014 Share Posted September 17, 2014 In Vectorscript one way would be to get a handle to the first object using FSActLayer and then step through the selected object using NextSObj. You are done when the handle from NextSObj returns NIL. Be careful using these if your routines modify the objects enough that the handle list might change. This is especially important if you are deleting objects or changing their selection state. Sometimes you need to start at the end of the list and work backwards using PrevSObj. Quote Link to comment
JBenghiat Posted September 19, 2014 Share Posted September 19, 2014 In addition to ForEachObject(), which steps through objects based on criteria, look at ForEachObjectInList() and ForEachObjectInLayer(), which can get the current selection. One complication to parsing selected objects, if VW will hold the selection state of objects on inactive layers. You need to specify whether to include these objects or not. If you're working on Python, you can easily use the FEO calls to load handles into a list and then iterate through the list. You can also use the FEO calls with lambda functions if your modification is simple. -Josh 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.