Jump to content

Space sorting script


Recommended Posts

Hi all,

I'm pretty new to direct scripting in Vectorworks, but always wanted to learn. As a first attempt I wanted to create a simple script that searches for "spaces" and assigns them to appropriate class depending on Net Area. In my file there is an example that should assign Spaces with area <10m2 to the RED class and rest to the BLUE class.

But, obviously, it fails since I' pretty green in this Area 🙂 Can someone give me a hint, not the solution, something that will help me to write this script?

Space sorting script.vwx

Link to comment

@Pat Stanford, thanks

So I think I don't really get the "handle" idea.

I tried to write a similar code for rectangles:

RectCount = int (vs.Count('Rect'))
RectList = []

for i in range (RectCount):
	obj = vs.GetObject((T=RECT)) 
	area = vs.HAreaN(obj)
	RectList.append([obj,area])
	
for j in range (len(RectList)):
	if RectList[j][1] < 10.00:
		vs.SetClass(RectList[j], 'RED')
	elif RectList[j][1] >= 10.00:
		vs.SetClass(RectList[j], 'BLUE')

but I don't know how to describe a criteria to search for specified object (e.g. rectangle).

Edited by Grzegorz Krzemien
Link to comment

Managed to do this in a different way:

First - same idea, but with Rectangles:

import vs

def RectSort (h):
	area = vs.HAreaN(h)
	if area < 10000000:
		vs.SetClass(h, 'RED')
	if area >= 10000000:
		vs.SetClass(h, 'BLUE')
	
vs.ForEachObject(RectSort, "T=RECT")

Works great.

I tried to recreate this, but instead of using rectangles, I wanted to use Spaces.

import vs

def SpaceSort(h):
	area = vs.Space_GetNetArea(h)
	if area < 10000000:
		vs.SetClass(h, 'RED')
	if area >= 10000000:
		vs.SetClass(h, 'BLUE')
	
vs.ForEachObject(SpaceSort, PON='Space')

But it fails. There is something wrong with criteria I think, but I don't know what.

I couldn't find "Space" object on this page:

https://developer.vectorworks.net/index.php/VS:Search_Criteria#Search_Criteria_Sub_Types

so I assume, I create a criteria in a wrong way.

Edited by Grzegorz Krzemien
Link to comment

Try this:

 

import vs

def SpaceSort(h):
	area = vs.Space_GetNetArea(h)
	if area < 10000000:
		vs.SetClass(h, 'RED')
	if area >= 10000000:
		vs.SetClass(h, 'BLUE')
	
vs.ForEachObject(SpaceSort,(("PON=Space")))

 

Like Pat, I'm sort of feeling my way in the dark with Python, but this works for me.

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