Jump to content
Developer Wiki and Function Reference Links ×

Connect polyline endpoint to object/symbol


boro

Recommended Posts

Hi,

I am trying to create a tool similar to the Flowchart Link Tool. This Tool is not as a standard tool in the Basic Toolset you can find it in the Plug-In Manager.

Basically I would like to draw a polyline between two symbols and "connect" the endpoints of the line to the symbols.

So when I move the symbols, the end point of the line moves with the symbol and the line will be scaled.

 

I think I need to give the symbols a unique name (figured that out already) but I do not have any idea how to "connect" the point to the named object.

 

Could anybody point me to the right direction and is this even possible with Vectorscript or do I need to use the SDK?

Thanks!

Link to comment

Hi,

as I know there is no way to get Events with VectorScript so it will not be possible to trigger your PIO when a symbol changes.

In the SDK you would create a class that inherits from  VCOMImmediateImpl<IObjUpdateSupport> to catch global events.

    class UpdateSupportProvider : public VCOMImmediateImpl<IObjUpdateSupport>
    {
    public:
        UpdateSupportProvider(CallBackPtr);
        virtual        ~UpdateSupportProvider();

        // IObjUpdateSupport
    public:
        virtual void VCOM_CALLTYPE    Init(IObjUpdateSupportContext* pContext);
        virtual void VCOM_CALLTYPE    OnNotification(IObjUpdateSupportContext* pContext);
        virtual void VCOM_CALLTYPE    OnState(IObjUpdateSupportContext* pContext, const ObjectState& state);
      ...

 

Edited by PatW
Link to comment

Boro,

   I just tried this for the first time and it seems to work. Use the Constrain Coincident tool to attach one endpoint of a Line to Symbol A and use it again to attach the other end of the Line to Symbol B. Now when you move either Symbol A or Symbol B the endpoints of the Line will move to stay "attached" to each symbol. It works when done manually. I assume it can be scripted.

 

   Additionally, if you move the Line, then both symbols will move, too.

 

Good luck,

Raymond

Edited by MullinRJ
Link to comment

I just had a brief play also (thanks for dragging me into this @MullinRJ).

 

Raymond is correct with a polyline when you move one of the symbols, the polyline does not scale and the second symbol moves to keep the relative position the same.

 

BUT - You can make your own Sudo-Polyline by drawing the segments and then joining them with Constrain Coincident also.

 

Another hint. Put a Locus in the symbol if there is not already an end or corner point that you want the "polyline" to stick to. Otherwise, the Constrain Coincident seems to think that anywhere on the perimeter of a rectangle or circle is an equally good point to be coincident.

 

 

Link to comment

Thanks for all the answers,

I tried to automate the constrain coincident within a script, with no success.

I always ended up with the message "This constraint is not valid", no matter on which object I tried it(Polygon, Polyline, Rectangle, Line).

Unfortunately the VS Function Reference is not a great help.

Here is my test code.

PROCEDURE test;

VAR
pointX1			:REAL;
pointY1			:REAL;
pointX2			:REAL;
pointY2			:REAL;

symbolHandle1		:HANDLE;
symbolHandle2		:HANDLE;
result				:BOOLEAN;

BEGIN
	DSelectAll;
	GetPT(pointX1, pointY1);
	symbolHandle1 := PickObject(pointX1, pointY1);
	GetPT(pointX2, pointY2);
	symbolHandle2 := PickObject(pointX2, pointY2);

	result := SetBinaryConstraint(1, symbolHandle1, symbolHandle2, 0,0,0,0,0,0);
END;

RUN(test);

 

Edited by boro
Link to comment

@boro,

   It took a bit of trial and error for me to figure out how the SetBinaryConsrtaint() function works, but I finally got it. It is NOT intuitive! Here is a very simple example showing how to join the endpoints of two lines together. 

PROCEDURE SBC_1_Example;
{ Constrain two lines to share a common point. }
{ In this example, Pt1 of Line 1 (obj1VertA = 1) is to be coincident to Pt2 of Line 2 (obj2VertA = 2). }
{ Line 1 will move so its StartPoint is coincident with Line 2's EndPoint. Line 2 will not move. }
{ The angles of both lines will remain unchanged. }
{  }
{ Select two lines and run the script. Line 1 is the first selected object and Line 2 is the second. }
{ For option 1 (Coincident Points), the second vertex of each object is not needed, so -1 is passed to }
{ the "obj1VertB" and "obj2VertB" parameters, while 0 is passed to both "containedObj" parameters. }
{  }
{ At the end of the script, the Message Window shows the function's result (T/F) amd the numeric type }
{ of each selected object (LineType = 2).}
{ 27 Apr 2019 - Raymond J Mullin } 
VAR
	H1, H2	:HANDLE;
	result	:BOOLEAN;
BEGIN
	H1 := FSActLayer;		{ Line 1 handle }
	H2 := NextSObj(H1);		{ Line 2 handle }
	
	result := SetBinaryConstraint(1, H1, H2, 1, -1, 2, -1, 0, 0);
	message(result, '  ', GetTypeN(H1), '  ', GetTypeN(H2));
END;
RUN(SBC_1_Example);

 

HTH,

Raymond

Link to comment

@MullinRJ

thanks again for your help, works great!

Here is an example on how to use the SetBinaryConstraint function with a symbol and a line. 

I had one symbol that gave me the "This constraint is not valid" message.

All the others symbols I tried, worked just fine...I will look into this the next week.

Keep in mind with this code you need to select the symbol first, then the line.

 

PROCEDURE test_CCSymbolandLine;
	
VAR
symbolHandle, lineHandle	:HANDLE;
x1, y1, x2, y2 				:REAL;
index 				:INTEGER; 
containedObj 		:LONGINT;
result				:BOOLEAN;
	
BEGIN
	{select the symbol first}
	GetPT(x1, y1);
	symbolHandle := PickObject(x1, y1);
	HCenter(symbolHandle, x1, y1);
	
	{then select the line}
	GetPT(x2, y2);
	lineHandle := PickObject(x2, y2);
	
	GetClosestPt(symbolHandle, x1, y1, index, containedObj);
	result := SetBinaryConstraint(1, symbolHandle, lineHandle, index, -1, 1, -1, containedObj, 0);
	message(result, '  ', GetTypeN(symbolHandle), '  ', GetTypeN(lineHandle));
	
END;
RUN(test_CCSymbolandLine);

 

 

Edited by boro
Link to comment
1 hour ago, Pat Stanford said:

It looks like the tricky part is having to pass the -1 to the unused vertices in the SetBinaryConstraint call.  

 

Hi @Pat Stanford , you guessed it. I initially got hung up using "0". Once I used -1, it got easier. The second and third modes, Collinear and Parallel were much easier to guess how they worked, and with the tech note using symbol wasn't too hard either.

 

1 hour ago, Pat Stanford said:

Can you think of any case where you would need to enter two points on an individual object to create a constraint?

 

Not to make two points of the same object coincident, but the call uses two points on an object to define an edge for Parallel, and Collinear. I'm not sure that's wha you mean, though.

 

Raymond

Link to comment
1 hour ago, MullinRJ said:

 

Hi @Pat Stanford , you guessed it. I initially got hung up using "0". Once I used -1, it got easier. The second and third modes, Collinear and Parallel were much easier to guess how they worked, and with the tech note using symbol wasn't too hard either.

 

 

Not to make two points of the same object coincident, but the call uses two points on an object to define an edge for Parallel, and Collinear. I'm not sure that's wha you mean, though.

 

Raymond

Parallel and Collinear are exactly the options that I could not think of when I was looking at the call.

 

Thanks for the deep dive.

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