Jump to content

Bounding box coordinates


Recommended Posts

Have following code to get object's coordinate on sheet layer.

import vs 


def todo(h):
	p = vs.GetBBox(h)
	vs.AlrtDialog(p[0][0])
	vs.AlrtDialog(p[0][1])
	
vs.ForEachObjectInLayer(todo,2,0,3)

It works fine on most files until this one. It is the same code, but as shown on screenshot, instead of return -1", p[0][0] returns 377210.178727 

image.thumb.png.95a163eda91a506ac377968944be6401.png

 

Did I misunderstand how GETBBOX works. 

Link to comment

Are you sure that the selected object is the one the data is being returned for?  

 

For Each Object will run todo once for every object in the layer.

 

If you want to specify the selected object, use vs.FSActLayer.

 

Also, the last option of 3 for FEOIL is not defined in the function reference.  It MAY be giving you the combination of 1 & 2 so All Layers and Selected Layers.

 

And be very careful with Selection state. There can be things selected that you can not see. Such as in Symbol Definitions, groups, other layers. You can have selected objects that don't show up in the OIP.

  • Like 1
Link to comment

@Jiajing,

   I can confirm that @Pat Stanford is correct, in that the options for all of the FEOIL commands can be added together to give you combined attributes. In this case your Layer Options = 3 does in fact mean All Layers AND Visible Layers, which reduces to All Layers. Often, I'll use 3 in the Object Options to get me Visible AND Selected objects.

 

   It is possible to make ForEachObjectInLayer() act like FSActLayer if you return True from your "todo" function. When True is returned, processing stops. Returning nothing defaults to False, and all objects within the scope of the command get processed.

 

   Here's a variation of your script that shows all of the pertinent information in one Alert Dialog, including the object type number. I would recommend changing the last option to a 4, to only work on Editable layers. This avoids grabbing objects on Gray or Hidden layers.

import vs
CR = chr(13)	# Carriage Return char

def todo(h):
	p = vs.GetBBox(h)
	vs.AlrtDialog('BBox for Obj Type: ', vs.GetTypeN(h), CR, 'TL: ', p[0][0], ',  ', p[0][1], CR, 'BR: ', p[1][0], ',  ', p[1][1])
	return True
	
vs.ForEachObjectInLayer(todo,2,0,3) # Selected, Shallow, All & Visible layers

 

   And here's a simpler version of the same script, using vs.FSActLayer() (as Pat recommended.) This style of script is primarily used when you are working only on the Active Layer.

import vs
CR = chr(13)	# Carriage Return char

h = vs.FSActLayer()
p = vs.GetBBox(h)
vs.AlrtDialog('BBox for Obj Type: ', vs.GetTypeN(h), CR, 'TL: ', p[0][0], ',  ', p[0][1], CR, 'BR: ', p[1][0], ',  ', p[1][1])

 

Note: I always place a comment after the FEOIL commands to spell out the numeric meanings of the options. Unless your memory is perfect, this will save you tons of time in the future when you revisit your scripts so you don't have to relook up the command to find out what the numbers mean — again.

 

HTH,

Raymond

  • Like 1
Link to comment
  • 4 weeks later...
On 4/1/2023 at 5:11 AM, MullinRJ said:

@Jiajing,

   I can confirm that @Pat Stanford is correct, in that the options for all of the FEOIL commands can be added together to give you combined attributes. In this case your Layer Options = 3 does in fact mean All Layers AND Visible Layers, which reduces to All Layers. Often, I'll use 3 in the Object Options to get me Visible AND Selected objects.

 

   It is possible to make ForEachObjectInLayer() act like FSActLayer if you return True from your "todo" function. When True is returned, processing stops. Returning nothing defaults to False, and all objects within the scope of the command get processed.

 

   Here's a variation of your script that shows all of the pertinent information in one Alert Dialog, including the object type number. I would recommend changing the last option to a 4, to only work on Editable layers. This avoids grabbing objects on Gray or Hidden layers.

import vs
CR = chr(13)	# Carriage Return char

def todo(h):
	p = vs.GetBBox(h)
	vs.AlrtDialog('BBox for Obj Type: ', vs.GetTypeN(h), CR, 'TL: ', p[0][0], ',  ', p[0][1], CR, 'BR: ', p[1][0], ',  ', p[1][1])
	return True
	
vs.ForEachObjectInLayer(todo,2,0,3) # Selected, Shallow, All & Visible layers

 

   And here's a simpler version of the same script, using vs.FSActLayer() (as Pat recommended.) This style of script is primarily used when you are working only on the Active Layer.

import vs
CR = chr(13)	# Carriage Return char

h = vs.FSActLayer()
p = vs.GetBBox(h)
vs.AlrtDialog('BBox for Obj Type: ', vs.GetTypeN(h), CR, 'TL: ', p[0][0], ',  ', p[0][1], CR, 'BR: ', p[1][0], ',  ', p[1][1])

 

Note: I always place a comment after the FEOIL commands to spell out the numeric meanings of the options. Unless your memory is perfect, this will save you tons of time in the future when you revisit your scripts so you don't have to relook up the command to find out what the numbers mean — again.

 

HTH,

Raymond

Thank you, @Raymond and @Pat Stanford 

 

I agree that there maight be other element is selected which is not visible on OIP. I clean the file almost entirely,  would love to get more details on this specifc case

Attached is the file. 

 

* On sheet Layer, titled as  LX-7, there is a bit map, which locates at X: 0 and Y:0 on top left. I select the bitmap and run the script

       Q1: If there is other element which is selected but invisble, is it suppose to be more than one AlrtDia to display all items?  In this case, I only get one alert window, and TL is not 0,0 for some reason.

       Q2: I also check the appendex, GETTYPEN gives index of 14, which indicates it is a bitmap, but I am not sure if bounding box is giving the right info of selected bitmap. And I only have one bitmap on this document.

 

 I am with you all, but just trying to figure out what's the hidden item and how to get the right boudnbox of selected bit map 

 

Thank you

image.png

 

2010025715_TestFile.vwx

Edited by Jiajing
Link to comment

It is not operating the way I expected.  But I think your Return True is messing up your function and causing it to only operate once.

 

Make a group on the same layer and leave an object in it selected.

 

Try and run the script with only the bitmap selected but with different option for ForEachObjectInLayer.

 

I find that with the Return True, I only get the first object. If I remove the Return and set the FEOIL to be All Objects or All Visible Objects I get multiple Alerts.

 

But the Traverse options don't seem to work. Unless the Group itself ends up as part of the returned objects, the objects contained in the group are not processed.

 

@Sam Jones can you comment on your experience with non-visible selected objects?

Link to comment

Hello,

 

when you reset the user origin, you will get the right coordinates.

If you want to keep the user origin it seems like you can do something like this:

 

import vs
CR = chr(13)	# Carriage Return char

def todo(h):
	tl, br = vs.GetBBox(h) # Unpacking return values
	o = vs.GetOrigin() # Coordinates of user origin
	
	tl_o = (tl[0] + o[0], tl[1] + o[1])
	br_o = (br[0] + o[0], br[1] + o[1])
	
	vs.AlrtDialog('BBox for Obj Type: ', vs.GetTypeN(h), CR, 'TL: ', str(tl_o), CR, 'BR: ', str(br_o))
	return True
	
vs.ForEachObjectInLayer(todo,2,0,4) # Selected, Shallow, All & Visible layers

 

 

Regards,

Letti

Edited by Letti R
  • Like 1
Link to comment

@Letti R beat me to the crux of the answer. 

 

There is a caveat for using GetBBox. You need to adjust for the User Origin offset when on a Sheet Layer or inside a Symbol. When you are on Design Layers, you do not need to make the adjustment. So, you need to test for your location before calling GetBBox.

 

Also, if you definitely only want to measure the FIRST SELECTED OBJECT, then leave your return value as "True", as it will stop after processing the first selected object.

 

Raymond

 

 

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