Jayme McColgan Posted May 28, 2021 Share Posted May 28, 2021 (edited) so i've been using Vectorworks for a few years and decided to make some python scripts. i understand python but i've having a hard time getting off the ground. i've made some basic scripts but I'm ready to start making useable ones now... what i want to do is to select some objects and get some basic info about them (location, size, ect.) and add some symbols based off the positions of the selected items. I'm stuck on step one of looping through the selected objects. any help would be appreciated. Solution: OBJECTS = [] def start(): vs.ForEachObject(collect, '((VSEL=TRUE))') def collect(handle): ### Get Selected PIO Record name hrecdef = vs.GetParametricRecord(handle) recname = vs.GetName(hrecdef) if recname == "Focus Point Object": fpoint_info = [] fpoint_x, fpoint_y, fpoint_z = vs.GetSymLoc3D(handle) fpoint_rot = vs.GetSymRot(handle) fpoint_info.append(handle) fpoint_info.append(fpoint_x) fpoint_info.append(fpoint_y) fpoint_info.append(fpoint_z) fpoint_info.append(fpoint_rot) OBJECTS.append(fpoint_info) Edited August 10, 2021 by Jayme McColgan Solved my issue Quote Link to comment
Pat Stanford Posted May 28, 2021 Share Posted May 28, 2021 Look at vs.ForEachObect (and the associated ForEachObjectInLayer and ForEachObjectInList). ForEachObject takes a criteria (probably Sel=True or VSel=True [Visible Selected] in your case). It than passes the handle to a subroutine. You can then do anything you want in that subroutine on the object passed or any other object(s). 1 Quote Link to comment
Tobias Döngi Posted May 28, 2021 Share Posted May 28, 2021 (edited) Hi Jayme, there is no specific method like vs.GetSelectedObjects() for retrieving the objects conveniently. Instead of that you iterate all objects in a specific context and match them against a search criteria. I.e. all rectangles in document or a given layer and so on. So what you want is traversing all objects in the current document and collect all selected ones. Following script does the trick: OBJECTS = [] def collect(handle): OBJECTS.append(handle) vs.ForEachObject(collect, '((VSEL=TRUE))') vs.AlrtDialog('Num selected objects: {}'.format(len(OBJECTS))) Check out those resources for additional help: https://developer.vectorworks.net/index.php/VS:ForEachObjecthttps://developer.vectorworks.net/index.php/Python https://developer.vectorworks.net/index.php/VS:Function_Reference Edited May 28, 2021 by Tobias Döngi 1 Quote Link to comment
Tobias Döngi Posted May 28, 2021 Share Posted May 28, 2021 (edited) You can configure the search criteria by clicking the small clipboard button within the script editor, like shown below: Edited May 28, 2021 by Tobias Döngi Quote Link to comment
Jayme McColgan Posted May 30, 2021 Author Share Posted May 30, 2021 @Tobias Döngi so what is the handle parameter the first function is referencing? is that what is currently selected? Quote Link to comment
Jayme McColgan Posted May 31, 2021 Author Share Posted May 31, 2021 (edited) ok so i have a few more questions about some things i can't find. what should i be using to set the Z height of a symbol? UPDATE: solved this. vs.Symbol(symbolName, x,y , -22.5) last = vs.LNewObj() vs.Move3DObj(last, 0, 0, 180) what should i be using to get the symbol type? the name that is just below class and layer. (normally its polyline, focus point, 2d/3d object, ect.) can i inset a symbol from a drawing thats in my favorites folder? this one is more of a general python question but i need to find the length of the side of a 90º triangle only knowing the length of 1 side and 2 of the angles. ive tried what i though was correct but doesn't seem to come up with the right answer... ive attached a picture and the code i tried for reference. in the image I'm trying to find the length of the A side. import math angle_a = 22.5 b = 56 a = b * math.tan(angle_a) Edited May 31, 2021 by Jayme McColgan Quote Link to comment
Tobias Döngi Posted May 31, 2021 Share Posted May 31, 2021 (edited) 12 hours ago, Jayme McColgan said: so what is the handle parameter the first function is referencing? is that what is currently selected? The first method is a callback function. That means VW will call it for every object matching the search criteria. So the handle is a pointer to one currently selected VW object. 8 hours ago, Jayme McColgan said: what should i be using to get the symbol type? I strongly encourage you to use the small clipboard button. There you will also find a menu named "Procedures". Having a look at the "Object Info" topic provides you with vs.GetTypeN(h). You have to provide it with above mentioned handle and you'll get the object type. 8 hours ago, Jayme McColgan said: can i inset a symbol from a drawing thats in my favorites folder? Yes you can but you have to create a resource list and import the symbol into the current document first. After that you can place the symbol within the drawing. 8 hours ago, Jayme McColgan said: this one is more of a general python question but i need to find the length of the side of a 90º triangle only knowing the length of 1 side and 2 of the angles. ive tried what i though was correct but doesn't seem to come up with the right answer... ive attached a picture and the code i tried for reference. in the image I'm trying to find the length of the A side. math.tan() expects radians you are providing degrees. You can convert it by using math.radians(angle_a.) Edited May 31, 2021 by Tobias Döngi 1 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.