Jump to content

Hello Community!

This Thursday, October 21st, from 6 pm to 7 pm EDT, we will be performing an update on the Vectorworks Community Board. During this time, the site will be unavailable.

looping though selected items


Recommended Posts

Posted (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 by Jayme McColgan
Solved my issue
Link to comment

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).

  • Like 1
Link to comment
Posted (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:ForEachObject
https://developer.vectorworks.net/index.php/Python

https://developer.vectorworks.net/index.php/VS:Function_Reference

 

Edited by Tobias Döngi
  • Like 1
Link to comment
Posted (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)

 

Screen Shot 2021-05-30 at 8.50.50 PM.png

Edited by Jayme McColgan
Link to comment
Posted (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 by Tobias Döngi
  • Like 1
Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...