Jump to content
avictorgm

set active a rectangle

Recommended Posts

Hello again,

 

I have. a code to go thru every element / symbol in my layer until it finds a rectangle.

then, I just need to get selected only this element.

 

A) I use X = 10 just to put a number. I need to count the number of elements.

 

the script works well until B) where it doesn't get the rectangle to zoom it whit the next line

 

Some ideas?

import vs
x = 10;
#-A)----------I need to count the number of objects in the layer

#vs.AlrtDialog(vs.Concat('Nr of objects is: ',  ***Count of all the elements in the layer*** ))
vs.DSelectAll

vs.LActLayer()

OBJETO = vs.LActLayer()
SymbolName = vs.GetSymName(OBJETO)

while x > 0:
	ElementTYPE = vs.GetType(OBJETO)
	if ElementTYPE == 15:
		SymbolName = vs.GetSymName(OBJETO)
		vs.AlrtDialog(vs.Concat(str(ElementTYPE), " Name: ", str(SymbolName)))
		#vs.AlrtDialog(vs.Concat('Object is a ', objectTypes[vs.GetType(h)]))
	
	
	if ElementTYPE == 3:
		
		vs.AlrtDialog(str('Recuadro encontrado'))
		vs.AlrtDialog(str(ElementTYPE))
		#B).........I wanna set active the rectangle
		vs.GetObject()
		vs.DoMenuTextByName('Fit To Objects', 0);
		
		break
	
	OBJETO = vs.PrevObj(OBJETO)
	
	x = x - 1

 

Share this post


Link to post

Three modifications that should help:

 

Don’t forget the parentheses in vs.DSelectAll()

 

Instead of using the arbitrary x to govern the loop, use:

while OBJECTO != 0:

This will both ensure the script loops through all objects and prevent error if the number of objects is less than 10. 

Technically, the check should be OBJECTO != vs.Handle(0)

 

vs.GetObject() returns the handle to a named object and should take a string as its parameter. What you want is:

vs.SetSelect(OBJECTO)

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×