Jump to content

Calculating Objects that overlap


Recommended Posts

Hi All

 

Apologies if this has been covered somewhere else, though I'm struggling to find any similar topics, could just be i'm not using the right terminology.

 

I'm trying to recreate the functionality similar to that of Spotlight Hanging Positions and their ability to automatically assign Positions to Fixtures that overlap with the HP. e.g:

I want to have a "base" PIO and when I insert a different PIO (Say PIO 2) into the drawing, PIO 2 calculates if it overlaps with any "Base" PIO's and if so queries said "Base" object and retrieves some information from it.  

 

The bit I'm struggling with is how to go about working out what objects overlap with said PIO 2. I suppose I could get PIO 2's bounding box co ords and then somehow query if there are any other objects within those same Coordinates. But I though I'd ask if anyone has any better ideas before I go down this route?

 

Thanks In advance! 

Link to comment

You'll want to use https://developer.vectorworks.net/index.php/VS:FindObjAtPt_Create and the associated calls.

 

If you're looking for object detection at a certain point, that's a lot easier than detecting true overlap between objects (which would require building the list of objects with this call and then checking the bounding boxes of all objects).

 

Remember, unless you're just looking for the overlap with a custom insertion tool, you need to translate between the PIO's internal coordinates and the external world.

 

Link to comment

Thanks Josh

 

I've been having a play with FindObjAtPt_Create, and I'm struggling to understand how the radius parameters works. I've drawn a circle with a radius of 20000mm, and placed a number of objects within it and outside (see below image), however the results I'm getting are not as expected. If I set the functions radius to 20000 it still picks up objects slightly out of that radius, for instance the object with the red circle around it gets picked up even though the distance from centre (which is the location i'm selecting each time for the starting co ordinates) is 22608.

 

Strangely even though it's picking up objects further away than the overall Circle, it's not picking the containing circle itself... 

 

Also from what I can tell I need to set the radius large enough to encompass the entire object for it to be included in the list.

 

image.thumb.png.78b8eab2d830313f2294232d70920fa9.png

 

I've adapted the code from the example on the wiki as below: 

import vs


def PickPointCallback(pt):
	startContainer = vs.Handle();
	
	list = vs.FindObjAtPt_Create(startContainer, 1, 0, pt[0], pt[1], 20000)
	cnt = vs.FindObjAtPt_GetCount(list)
	vs.AlrtDialog("Initial Co ords: "+str(pt[0])+ ' '+str(pt[1]))
	for i in range(cnt):
		hObj = vs.FindObjAtPt_GetObj( list, i )
		x2,y2 = vs.HCenter(hObj)
		d = vs.Distance(pt[0], pt[1], x2, y2)
		
		vs.AlrtDialog( 'Index: ' + str(i) + ' Obj Type: ' + str(vs.GetTypeN(hObj)) + ' Dist: '+str(d) )

	vs.FindObjAtPt_Delete( list )


vs.GetPt( PickPointCallback )

 

Link to comment

As Pat mentions, the notes indicate that this only works for certain object types. PIO's IS one of them — my guess is that it's looking for objects with a defined insertion point.

 

I don't know how the algorithm works, but possible a 20m radius is too large to be accurate. The call is intended for finding objects near a certain point, so generally looking at a radius of 500mm or less.

Link to comment
47 minutes ago, Pat Stanford said:

No real help here, but have you read the notes on FOAP_Create on the Developer site?

I have not seen the notes, do you have a link to them? I had a search on developer.vectorworks.com for them but it doesn't seem to return any results?

 

15 hours ago, JBenghiat said:

As Pat mentions, the notes indicate that this only works for certain object types. PIO's IS one of them — my guess is that it's looking for objects with a defined insertion point.

 I think what i've discovered is that using Circles as my testing object, was a poor choice, from what I can gather FindObjAtPt_Create will only return a circle object if the radius intersects with perimeter of said object. 

 

Luckily with both PIOs and Rectangles (which are the two main object types i'm interested in right now) the function does return any part of the object that is within the radius.

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