Jump to content

Auto-fill distance to object in symbol


Recommended Posts

  • Vectorworks, Inc Employee

I THINK there is a way to do this with custom symbol records, but the tool I can think of that does this by default is the Stake object, which you should have if you own Designer or Landmark. It has a Label Reference option in the Object Info palette called "Label Reference" which does this if you set it to Coordinates (X,Y):

 

58f0c8091e313_ScreenShot2017-04-14at9_00_08AM.png.883a807e8a2d567391239ce827463613.png

Link to comment

OK, try this. I am including both the script for a PIO and the vso file. If you use the script, you will need to us the Plug-in editor and make a new Point object. It needs a single Parameter of type Control Point.  By changing the defaults before inserting "Distance From" objects, you can control the initial placement of the text from the locus point.

 

This object inserts a locus point a the point clicked (it takes a double click because VW objects are intended to be able to be rotated on insertion. Better to insert vertically and then rotate is necessary. I then adds a text block showing the distance from the origin (0,0) point of the file in the current document units.

 

Let me know if this does or does not fit your needs.

Procedure DistanceFrom;
{©2017, Patrick Stanford, pat@coviana.com  Licensed under the LGPL}
{No Warranty Expressed or Implied. Test thoroughly before using on production data}
{Make a backup copy before running}
{May change data in hidden but selected objects in groups, symbols, etc.}
{Do no operate heavy machinery while using. May cause drowsiness}

{Lightly commented for use in learning VectoScript}

{Puts a locus and a text block showing the distance from the origin (0,0) of the drawing at the location double clicked.}
{Second click is necessary to account for the rotation input of PIOs. While the PIO may be rotated on insertion,}
{the control point for moving the text block does not work properly on those instances. If the PIO is inserted "vertical"}
{and the rotated, the control points continue to work. This appears to be plane related.}

Var		X1,Y1,X2,Y2, Dist: Real;	{X1,Y1 are location of PIO object, X2,Y2 are the point it measures from}
		S1, S2: String;				{S1 is the name of the PIO, S2 is the string used to display the distance}
		H1, H2, H3: Handle;			{H1 is the handle to the PIO instance. H2 and H3 are used by GetCustomObjectInfo}
		B1: Boolean;				{B1 is a dummy boolean required for the return data of GetCustomObjectInfo}
		
Begin
	PushAttrs;		{save drawing settings so the changes we make don't effect drawing environment}
	B1:=GetCustomObjectInfo(S1, H1, H2, H3);   {Get info (name and handle) to the PIO instance}
	GetSymLoc(H1,X1,Y1);		{Get the location of the PIO instance}
	Locus(0,0);					{Draw a locus at the center of the PIO Instance. PIOs have their own internal coodinates}
	X2:=0;						{Set the point to measure from. These two lines can be changed to allow measureing}
	Y2:=0;						{From a different point. Perhaps a named locus would be best}
	Dist:=Distance(X1,Y1,X2,Y2);{Get the distance as a number}
	S2:=Num2StrF(Dist);			{Convert the numerical distance into a string using the current document unit settings}
	FillPat(0);					{Set the text to no fill}
	TextJust(2);				{Set the text justification to center}
	TextVerticalAlign(2);		{Set the vertical justification to top baseline so above the insertion point}	
	Message(Date(2,2),'  ',GetLScale(GetLayer(H1)), '  ',Num2StrF(GetLScale(GetLayer(H1))));
	TextOrigin(pControlPoint01X,pControlPoint01Y);	{Set the text origin point to use the ControlPoint values}
	CreateText(S2);				{Create the text block showing the distance}
	PopAttrs;		{restore the original drawing settings we might have changed}		
End;

Run(DistanceFrom);

 

Distance from (0,0).vso

  • Like 2
Link to comment
2 hours ago, Pat Stanford said:

OK, try this. I am including both the script for a PIO and the vso file. If you use the script, you will need to us the Plug-in editor and make a new Point object. It needs a single Parameter of type Control Point.  By changing the defaults before inserting "Distance From" objects, you can control the initial placement of the text from the locus point.

 

This object inserts a locus point a the point clicked (it takes a double click because VW objects are intended to be able to be rotated on insertion. Better to insert vertically and then rotate is necessary. I then adds a text block showing the distance from the origin (0,0) point of the file in the current document units.

 

Let me know if this does or does not fit your needs.


Procedure DistanceFrom;
{©2017, Patrick Stanford, pat@coviana.com  Licensed under the LGPL}
{No Warranty Expressed or Implied. Test thoroughly before using on production data}
{Make a backup copy before running}
{May change data in hidden but selected objects in groups, symbols, etc.}
{Do no operate heavy machinery while using. May cause drowsiness}

{Lightly commented for use in learning VectoScript}

{Puts a locus and a text block showing the distance from the origin (0,0) of the drawing at the location double clicked.}
{Second click is necessary to account for the rotation input of PIOs. While the PIO may be rotated on insertion,}
{the control point for moving the text block does not work properly on those instances. If the PIO is inserted "vertical"}
{and the rotated, the control points continue to work. This appears to be plane related.}

Var		X1,Y1,X2,Y2, Dist: Real;	{X1,Y1 are location of PIO object, X2,Y2 are the point it measures from}
		S1, S2: String;				{S1 is the name of the PIO, S2 is the string used to display the distance}
		H1, H2, H3: Handle;			{H1 is the handle to the PIO instance. H2 and H3 are used by GetCustomObjectInfo}
		B1: Boolean;				{B1 is a dummy boolean required for the return data of GetCustomObjectInfo}
		
Begin
	PushAttrs;		{save drawing settings so the changes we make don't effect drawing environment}
	B1:=GetCustomObjectInfo(S1, H1, H2, H3);   {Get info (name and handle) to the PIO instance}
	GetSymLoc(H1,X1,Y1);		{Get the location of the PIO instance}
	Locus(0,0);					{Draw a locus at the center of the PIO Instance. PIOs have their own internal coodinates}
	X2:=0;						{Set the point to measure from. These two lines can be changed to allow measureing}
	Y2:=0;						{From a different point. Perhaps a named locus would be best}
	Dist:=Distance(X1,Y1,X2,Y2);{Get the distance as a number}
	S2:=Num2StrF(Dist);			{Convert the numerical distance into a string using the current document unit settings}
	FillPat(0);					{Set the text to no fill}
	TextJust(2);				{Set the text justification to center}
	TextVerticalAlign(2);		{Set the vertical justification to top baseline so above the insertion point}	
	Message(Date(2,2),'  ',GetLScale(GetLayer(H1)), '  ',Num2StrF(GetLScale(GetLayer(H1))));
	TextOrigin(pControlPoint01X,pControlPoint01Y);	{Set the text origin point to use the ControlPoint values}
	CreateText(S2);				{Create the text block showing the distance}
	PopAttrs;		{restore the original drawing settings we might have changed}		
End;

Run(DistanceFrom);

 

Distance from (0,0).vso

Wow, thanks!!

 

And for the icing on the cake.. is there a way to merge it with a symbol I've created?

So that the placing the plugin will place the text and the symbol?

 

Thanks again Pat!

Link to comment

If you want to include your symbol in the PIO, add the following line:

 

Symbol('Symbol-1',0,0,0);

 

With 'Symbol-1' replaced with your symbol name (in single quotes). My recommendation is to add this line right after the Locus(0,0) line. If your symbol has a different insertion point, change the first two zeros to whatever offset you need. The last one is for rotation, the first two are the X and Y insertion points.

 

The Distance PIO does not operate properly inside of a symbol, but it should be able to be rewritten to work that way also. Then you could add the distance into your symbol instead of the other way around.

  • Like 1
Link to comment
5 hours ago, Pat Stanford said:

If you want to include your symbol in the PIO, add the following line:

 

Symbol('Symbol-1',0,0,0);

 

With 'Symbol-1' replaced with your symbol name (in single quotes). My recommendation is to add this line right after the Locus(0,0) line. If your symbol has a different insertion point, change the first two zeros to whatever offset you need. The last one is for rotation, the first two are the X and Y insertion points.

 

The Distance PIO does not operate properly inside of a symbol, but it should be able to be rewritten to work that way also. Then you could add the distance into your symbol instead of the other way around.

Perfect!

 

I see you talk about referencing a 'named locus' as the measure from point. Is there a way to make the 0, 0 of a sheet layer that is different to the design layers as that locus? 

 

Thanks again Pat, this has been a HUGE help!

Link to comment

If you replace the two lines setting X2 and Y2 with:

 

GetLocPt(GetObject('PTS_(0,0)'),X2,Y2);

 

Then the distances measured will be from a locus point that is named PTS_(0,0).  You can change the name to whatever you want. If you want to use a symbols insertion point instead of a locus point, change the GetLocPt to GetSymLoc.  The symbol instance will need to have a name assigned.

  • Like 1
Link to comment
On 4/16/2017 at 1:07 AM, Pat Stanford said:

If you replace the two lines setting X2 and Y2 with:

 

GetLocPt(GetObject('PTS_(0,0)'),X2,Y2);

 

Then the distances measured will be from a locus point that is named PTS_(0,0).  You can change the name to whatever you want. If you want to use a symbols insertion point instead of a locus point, change the GetLocPt to GetSymLoc.  The symbol instance will need to have a name assigned.

Hi Pat,

 

This has been a huge help.

 

I was wondering if you knew anyway to automate this a bit more, having it insert symbols at x, y coordinates from a worksheet?

 

This has saved me hours, but if I can automate it, days could be saved! haha

 

Again, thank you so much for your help!

 

Callum

 

 

 

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