Jump to content
Developer Wiki and Function Reference Links ×

GetLine not ending after first click


Nora

Recommended Posts

Hi There,

 

I am trying to make a callout style tool using the plugin manager and vectorscript, however I can't seem to work out how to make the main part of my plugin place after only two clicks.

 

I am trying to click at one point, where I want the start of my line, and then click a second point, where I want the end of my line and the rest of the object to place,

 

However I click once, and it starts getline fine, but after I click a second time getline disappears and then I have to click a third time for my object to place and the line to draw, but the third click won't be where I'd like it to be.

 

my code is:
with ptx1,pty1 being the initial first click, and ptx,pty being the second

{Draws Initial Line}
	GetLine(ptx1,pty1, ptx, pty);
	REPEAT
	UNTIL
	MouseDown(ptx,pty);
	MoveTo(ptx1,pty1);
	LineTo(ptx,pty);

 

Any help would be great.

 

 

I also can't seem to make the object one thing with parameters editable in the shape window, but thats an issue for later.

 

Cheers,
Nora

Link to comment

Hello @Nora,

   Here is a sample script that shows how to use the GetLine call with a single MouseDown event followed by a subsequent MouseUp event. 

 

   There is one caveat you will need to understand, if you cancel the GetLine call before it completes, say by hitting the ESC key between MouseDown and MouseUp events, the script will end prematurely and the drawing mode will not be restored. This is only a problem is the original drawing mode was ClickClick to begin with.

 

   If this creates a serious problem for you or users of your script, write back. There are ways to mitigate this vulnerability, but more code is needed.

 

PROCEDURE xxx;
{ Code snippet to test GetLine() procedure. }
{ If you normally use the Click-Click drawing mode, this code will change the drawing mode to }
{ Click-Drag for draiwng one Line, then revert back to Click-Click drawing when the script is done. }
{ If you normally use Click-Click drawing, you will see no change in behavior when drawing the line }
{ in this script. }
{ 04 Oct 2023 - Raymond Mullin }
VAR
	Pref0 :Boolean;
	ptx1, pty1, ptx, pty :Real;
BEGIN
	Pref0 := GetPref(0);	{ save state of Pref0 - Enable click drag drawing } 
	SetPref(0, True);	{ set drawing mode to ClickDrag }
	
	GetLine(ptx1, pty1, ptx, pty);
	MoveTo(ptx1, pty1);
	LineTo(ptx, pty);

	SetPref(0, Pref0);	{ restore state of Pref0 - Enable click drag drawing } 
END;
Run(xxx);

 

HTH,

Raymond

  • Like 1
Link to comment

The only other thing I am struggling to learn, is how do I turn this into one object?

When I use my tool it just places all these as separate objects (lines, symbols, and text) but I would like it to be one object so when I click it I can update the parameters and have it "redraw" itself.

 

The other thing is would it be possible for me to move the group of symbols but keep the arrow pointing at the same point, the only way I can think of is to have it waiting for if the group is moved and then redrawing the line, but I fear that would slow down the document quite a bit if I have lots of these on the drawing.

 

Thanks for the help!

ScreenShot2023-10-05at11_25_29AM.png.f40768f9f41ff43f2f5e64e426c02551.pngScreenShot2023-10-05at11_28_43AM.png.d8f992d73ea8a73643ddd954498fe22b.png

Link to comment

From your description, you will want to create a Plug-in object. There are several levels of complexity, from simple objects or collections of objects, to event-enabled objects. 

 

To start, open the Plug-in Manager, Cmd-Shift-Z on Mac, or Ctrl-Shift-Z on PC, or use menu Tools>Plug-ins>Plug-in Manager. There you can create one of the following types.

image.png.8d1d5031637d5bce5c4dbf962c309900.png

 

There are three basic types, Menu Commands, Tools, and Objects.

 

Commands (or Menu Commands) are typically procedural scripts and can be used to change VW settings, or operate on existing objects. Their advantage over scripts saved in a script palette is they are stored in the VW program and displayed in a VW menu, so they are available to all open files.

 

Plug-in Tools are interactive and allow you to create or modify objects using the mouse. 

 

Plug-in Objects (PIOs) allow you to create custom objects more complex than the basic tools that ship with the software. 

 

Not knowing exactly what you want to draw, I will not suggest a PIO type for you at this moment. To become more familiar with how they are structured, create one and look at the interface. Once created, click on the various buttons on the bottom of the Plug-in Manager screen. 

 

The Edit Definition... button opens a dialog with 6 panes. You will create your custom variables in the Parameters pane. These parameters are the values that will appear in the OIP when your object is selected. Create some dummy parameters and note how many parameter types there are. Then open all the other panes and look each over.

 

image.png.7a13a4061f79470b6bb823fcc78e9d84.png

 

 

The other button of interest is the Edit Script... button. This is where you place your VectorScript, or Python, code. It's the same window you use when you are editing scripts in a Script Palette.

 

The Parameters pane and and the Script Editor window are where you'll spend most of your time editing. Until you get in a little further, I should probably stop here. Poke around a bit, and send back more questions. The more complicated your Plug-in becomes, the more you will use the other parts of the Plug-in Editor, but for simple PIOs, the Parameters pane and the Script Editor will be mostly what you'll need to use.

 

There's a lot to digest, but luckily there are a lot of people in this community willing to help. Also, if you haven't already, read the first pinned post in the Vectorscript Forum - "What do I do with a Vectorscript, anyway?" by @Pat Stanford where he references the original post by @Robert Anderson which is really hiding in the Archive section of the Forum, under the Resource Share - Vectorscript section, where nobody will ever find it, so thanks to Pat for making it accessible. It's a bit dated, but still relevant.

 

Welcome to VW scripting, 

Raymond

  • Like 2
Link to comment

(writing on an alt account as I'm not at work(

Thanks for your response Raymond, what you have written is basically where I am at, I have a PIO with parameters (shown in second picture) that I can change from the toolbar before placing the object at my mouse position (object shown in first pic)

 

the problem is that I want to be able to change these parameters in the object info palete after it has been placed, as it would be great to change these as updates to the site come in. essentially it's a callout that shows the quantities and labels of GPOs in a location.

 

As of right now when I place it it puts the symbols, lines, and text as seperate objects, but I can't work out how to make them one unified modifiable object.

 

I'm having difficulties defining objects in code and selecting or modifying them.

 

for example I'd like to be able to grab the group of icons and move them, but have the arrow pointing at the same place.

 

Tha is for your advise so far, and hopefully you'll be able to help further, I really appreciate the feedback and help I've been getting from this community so far and one day I'd like to be able to contribute as well!

 

Cheers,

Nora

  • Like 1
Link to comment

It sounds like you have created a PIC (Plug-in Command). What you want to create is a PIO (Plug-in Object).

 

Basically the same script will work, but as a PIO, the objects you create will all be wrapped in the PIO so that when you move one they all move.  It is a little bit like a modifiable symbol.  

 

Any parameter you want to have displayed in the OIP (Object Info Palette) you specify as a Parameter in the Plug-in Editor. You then use the name of the parameter preceded by the letter p to access those values in the script.

 

Warning: Pseudocode follows:

 

I want to create a text block that I can change the value of in the OIP.

 

I create a new Point PIO (Point means you only have to click once to place the object).

I goto the Edit Definition button and then the Parameter pane and create a Parameter named MyText and give it a type of text. 

 

In the script, where I would usually have to define a Var  for MyText, I just skip that part and use the name pMyText instead.

 

So in this case the script can be very simple (all of the Procedure/Begin/End/Run removed for clarity):

Procedure MyText;

Begin

CreateText(pMyText);

End;

Run(MyText)

 

Then edit your workspace and add the PIO to a toolset.  When you click on the PIO in the tool set you will get an "outline" of the object (in this case just a dashed text rectangle).  It takes two clicks to place the object. The first to set the location, the second to set the rotation.

 

Then you can change the text in the OIP and the object in the drawing will update automatically.

 

You can then expand the Definitons/Parameters to add as many other parameters as you want. And you can expand the script to include as many text blocks and as much other stuff as you want to draw.

 

HTH.

  • Like 4
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...