Jump to content

Updating Co Ordinates


Recommended Posts

So I'm writing a script that requires the X and Y co ordinates for the Center of a Hanging Position, this I can get no problem using vs.HCenter() the problem i'm having is that if you have the position name turned on for that position, it takes that into account for the Center Co Ords (from what I understand this is because it's taking the center of the Bounding Box for the HP), meaning that the returned values aren't actually centered on the HP itself.

 

My work around for this was to add in something that turns off the HP Name whilst the script is running. This works fine, however the problem i'm having is the Co-Ords are not updating after I have disabled the POS Name until AFTER the script has finished running.

 

E.g:

Co Ords with POS Name turned on = 300, 100

Co Ords after POS Name Disabled = 300, 100

Manually getting HP Co Ords AFTER script has Finished = 100, 100

 

I've tried adding in vs.ResetObject() and vs.ReDrawSelection() but to no avail. 

Code Below:

 

import vs
objectHandle = vs.FSActLayer()
vs.SetRField(objectHandle, 'Light Position Obj', 'Position Summary', 'False')  # Sets Show Position Name to False 
vs.ResetObject(objectHandle)  
vs.RedrawSelection()
hpX, hpY = vs.HCenter(objectHandle)  # Gets Center of HP
symname = vs.GetRField(objectHandle,'Light Position Obj', "Symbol Name")  #  Gets the Symbol name from HP record
symHandle = vs.GetObject(symname)  # Gets the Symbol's handle from the POS name        
(p1X, p1Y), (p2X, p2Y) = vs.GetBBox(symHandle)  # Gets co ords of Bounding Box
vs.Message(str(p1X)+str(p1Y)+str(p2X)+str(p2Y))
vs.Rect(p1X,p1Y,p2X,p2Y)  # Creates Rectangle from Sym Def Bounding Box @ 0,0 on document
rectHandle = vs.LNewObj()  # Gets Handle for newly Created Rectangle
rectX, rectY = vs.HCenter(rectHandle)  # Get Center of newly created Rectangle
X = hpX - rectX  # Calculate X Distance
Y = hpY - rectY  # Calculate Y Distance
vs.Move3DObj(rectHandle,X,Y,0)  # Moves Rect to HP Center

Is there some other command I need to run to recalculate the objects Co Ordinates?

Link to comment

You are probably going to have to do the calculations yourself.

 

vs.GetSymLoc will return the insertion point of the hanging position.

 

vs.Fin3D will return a handle to the first object inside the hanging position. NextObj(Fin3D) will return the second object inside the Hanging position. In my very limited testing this is the hanging position symbol.

 

So you should be able to use NextObj(Fin3D) to get the information on the symbol and Add/Subtract that from the insertion point (assuming the insertion point is always at the same relative location) to find the center. If you also have to deal with rotation angles, then add some trig functions in.

 

Not simple, but it should be doable.

 

EXTREMELY lightly tested. Use with caution and make sure you test in your application for suitability of purpose.

 

Procedure Test;

Var	H1,H2:Handle;
	X1,Y1: Real;
	X2,Y2: Real;
	X3,Y3: Real;
	
Begin
	H2:=FSActLayer;
	H1:=NextObj(Fin3D(H2));
	If H1=Nil then AlrtDialog('Nil') else
	Begin
	GetSymLoc(H2, X2, Y2);
	HCenter(H1,X1,Y1);
	AlrtDialog(Concat('Insertion Point is: ', Num2Str(3,(X2)), ' - ', Num2Str(3,(Y2))));
	AlrtDialog(Concat('Symbol Dims are: ', Num2Str(3,(X3-X1)), ' - ', Num2Str(3,(Y3-Y1))));
	AlrtDialog(Concat('Center of HP is: ', Num2Str(3,(X2+X1)), ' - ', Num2Str(3,(Y2+Y1))));
	End;
End;

Run(Test);

 

  • Like 2
Link to comment

As Pat suggested GetSymLoc is the one you're wanting to use for plugin objects. I have no experience with Spotlight, so can't add to what Pat has mentioned apart from converting that into python:

h2 = vs.FSActLayer() # Plugin Object
h1 = vs.NextObj(vs.FIn3D(h2)) # Symbol With Plugin Object

if h1 is None:
    vs.AlrtDialog('Nil')
else:
    x2, y2 = vs.GetSymLoc(h2)
    x1, y1 = vs.HCenter(h1)

    vs.AlrtDialog("Insert Point is : {:.2f}, {:.2f}".format(x2, y2))
    vs.AlrtDialog("Symbol Dims : {:.2f}, {:.2f}".format(x2 - x1, y2 - y1))
    vs.AlrtDialog("Center of HP is : {:.2f}, {:.2f}".format(x2 + x1, y2 + y1))

 

  • Like 2
Link to comment

Thanks! You're script worked as expected! 

 

@Pat Stanford You were correct that NextObj(Fin3D) does return the Symbol for the Hanging Position, or interestingly the CustomObjectProfileGroup should the HP be made of multiple pieces of Truss Objects, which is extremely handy! I thought I was going to have to calculate the individual dimensions for each truss object and add them together for those kind of HPs! 

 

It's a shame that my method didn't work, would have been quite a simple solution to what I was trying to achieve! Luckily thanks to you're help, I found a different method that works just aswell, just with a few more lines of code!

 

Just for my own understanding does anyone know why the Co Ordinates don't update until after the script has run? I assume it's not so much that the geometry is not updating but instead whatever script Spotlight needs to run to recalculate the object after changing the record,  doesn't run until the users script has finished?

 

 

Link to comment

Scripts in VW are basically linear. The script runs and creates or changes objects, bu the drawing code is blocked until script execution completes. Even though you edited. the object (to turn off the label), the only version of the object that you can access is the unedited version that was available prior to the script running.

 

Reset Object, Redraw, and Redraw All can sometimes rest things enough to be able to be able to do what you need to in the middle of a script, but you can't depend on being able to change an object and get the new values until the next run of the script after the drawing routines have run.

 

We have all chased this before.I think the time this hit e hardest was wanting to duplicate a PIO and change the values. If I remember correctly this was not possible and the work around was to create a new custom object and set all the parameters.

 

Maybe someday VW will be multi-threaded enough that the "model" can update in parallel with script execution.

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