Jump to content
Developer Wiki and Function Reference Links ×

Plug In Objects Creation?


pfalvi

Recommended Posts

Hi there!

 

I'm slowly digging into this all, trying to do some basic things before I go for more complicated scripting to make sure I understand how it works.

 

Right now I'm trying to insert a symbol and a text field into the drawing, and let the text field be adjustable in the OIP. So far what I'm seeing is that it will draw the symbol and text field as two separate objects (symbol and text field respectively), where I'd like to have them be one object together. 

 

Below is the code I'm using- it's a Point object so far.

 

PROCEDURE InsertMSArrow;
{Inserts an specified Symbol arrow
 and adds a User Definable Text Field}

VAR X1, Y1, X2, Y2 :Real;
    textData :String;

BEGIN
  GetPt(X1,Y1); {gets point from mouse click}
  Symbol('JMC MS Arrow', X1, Y1, 0);
  GetPt(X2,Y2); {gets point from mouse click}
  MoveTo(X2,Y2);
  CreateText(pTextData);
End;

Run(InsertMSArrow);

 

What can I do to make this function properly? I'm sure I'm missing something pretty basic.  (Eventually, I'd love to be able to click once, and then click to set the rotation of the object together, if that matters for advice!)

 

Thanks! I'm hoping once I get past some of this stuff, I can hit the ground running!

Link to comment

@pfalvi,

   I'm going to describe the manual way first.

 

1) Create your symbol with geometry AND a text field. The text can have anything in it as it's just a place holder at this point.

2) Create a Record Format with one field (type text). The default you type in for the record will be the default text you see when the symbol is placed in the drawing. It can be blank.

3) Edit the symbol and select the Text object. Select menu item Modify > Link text to record... Choose the new record format and the field and click the OK button.

4) Exit the symbol.

5) With the symbol selected, open the DATA pane of the OIP. Select the record format (if there are more records attached to your symbol), and change the text to the right of the field name below. You may have to adjust the pane dividers to see everything. Press ENTER and your new text will display next to your symbol. You can now change the text in the OIP for each symbol in your drawing without affecting previously placed symbols.

 

Putting these steps into a script can be done, but it is more difficult. Off the top of my head I don't remember exactly how it's done, but I've done it before, so I know it's possible. Write back with more questions.

 

Raymond

  • Like 1
Link to comment

Hey Raymond,

 

Thanks for this! I’ve done it that way before, but my long term goal is to make a script based PIO to make the text be read normally no matter how the object is rotated. I think I found the code to make the rotation happen, but (I think) I’d need it to be built into an PIO object first. 
 

I’m also hoping to eventually be able to control the color of the geometry inside the object on a per instance basis, which I don’t think I can do as a symbol.

 

Thanks!

Link to comment

Super Duper Extremely Incredibly Short Version:

 

In the Plug-In Manager make a new Plugin.  Make it a point type to start. You might find that a rectangle type that lets you click 3 points might make it easier to set your rotation in the future, but start simple.

 

Make a new Parameter named TextData.  You will access this using the pTextData in your script.  Get rid of the TextData variable.  Setting this as a a parameter will make it show in the OIP unless you take extra steps to remove it.

 

You can add a second Parameter for the Symbol Name. If you have a limited number of options you can manually make a Pop-up list for the parameter.

 

Click the Edit Script... button in the Plugin Manager and paste the script you have into the editor window.

 

Once you have this done you will have the basics of the PIO.  Edit your workspace to add it to a tool palette and you should be set to go.

 

 

Link to comment

Hey Pat,

 

Thanks for your response!

 

My code now looks like this:

PROCEDURE InsertMSArrow;
{Inserts an specified Symbol arrow
 and adds a User Definable Text Field}

VAR X1, Y1, X2, Y2 :Real;

BEGIN
  GetPt(X1,Y1); {gets point from mouse click}
  Symbol('JMC MS Arrow', X1, Y1, 0);
  GetPt(X2,Y2); {gets point from mouse click}
  MoveTo(X2,Y2);
  CreateText(pTextData);
End;

Run(InsertMSArrow);

But the object shows me the attached when inserted. I'm not seeing a field in the OIP for the TextData, and they appear to be two separate objects.

 

Any thoughts?

PIO OIP Error.png

Link to comment

I didn't read you script well enough. The PIO handles a lot of the GetPt for you.  The simplest version of your script is:

 

PROCEDURE InsertMSArrow;
{Inserts an specified Symbol arrow
 and adds a User Definable Text Field}

VAR X1, Y1, X2, Y2 :Real;

BEGIN
  Symbol(pThisSymDef, 0, 0, 0);
  MoveTo(pX1,pY1);
  CreateText(pTextData);
End;

Run(InsertMSArrow);

 

And it needs the following parameters set up.

image.png.d64a9e03b1d753bd6cfb8a3298d68aee.png

 

Change the Choices to the names of the Symbols you want to be able to insert.

 

The PIO will insert where you click for the PIO which is the zero,zero point of the local coordinated inside the PIO.  The text will then be moved by the X1 and Y1 values from that point.

 

Once you have this figured out, then you can move on to do the more detailed stuff like calculating where you want the text relative to the symbol size and rotating the symbol.

 

To do the rotation you probably are going to want to use the Rectangle PIO which will give you a LineLength and BoxWidth parameter. From there you can use Trigonometry to figure out the angle the symbol should be inserted at.

 

HTH.

  • Like 1
Link to comment
  • 2 months later...

Hi there,

 

@Pat Stanford I'm trying to understand how plugins work and have a question about your answer above.

 

Where can we find the information which indicates for example that it is necessary to put a "p" in front of "ThisSymDef" and "TextData" in the script?

 

The "p" tells the script to look in the settings tab of the plugin definition?

 

I know these are basic questions but this information is important before you can understand more complicated posts like the ones below:

 

How to make a PIO Styled?

 

User:CBM-c-/Plug-in with widget basic example

 

Thanks!

Link to comment

Yes, if you use a value with a "p" in front of it, VS treats that as a Field in the Plug-In Parameter record.  The other thing to note about that is that these values are only read at the beginning of the script execution and then stored back at the end of the script execution. So you can't use them as variables.  If you need to modify them during the script run, you need to store the value into a variable, manipulate the variable and then store the variable back to the parameter at the end of the script.

 

I don't remember where I learned about this originally. I will try and look for some resources later tonight.

Link to comment

I finally found where I learned most of what I know about PIOs.  It was a hardcover book that came with VW 8.5 named "Custom Solutions in VectorWorks 8.5".  The only possibly source I have for it right now is a used hard copy from ABE Books.

 

https://www.abebooks.com/servlet/BookDetailsPL?bi=17509651018&cm_sp=collections-_-4ByJeqQKGdHYqPhsRpovo2_item_1_5-_-bdp

 

They only have one copy available, so if you want it, be quick.

 

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