tbexon Posted March 3, 2021 Share Posted March 3, 2021 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! Quote Link to comment
JBenghiat Posted March 3, 2021 Share Posted March 3, 2021 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. Quote Link to comment
tbexon Posted March 4, 2021 Author Share Posted March 4, 2021 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. 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 ) Quote Link to comment
Pat Stanford Posted March 4, 2021 Share Posted March 4, 2021 No real help here, but have you read the notes on FOAP_Create on the Developer site? Quote Link to comment
JBenghiat Posted March 4, 2021 Share Posted March 4, 2021 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. Quote Link to comment
tbexon Posted March 5, 2021 Author Share Posted March 5, 2021 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. Quote Link to comment
Pat Stanford Posted March 5, 2021 Share Posted March 5, 2021 See the Remarks section: https://developer.vectorworks.net/index.php/VS:ForEachObjectAtPoint 1 Quote Link to comment
Recommended Posts
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.