Jump to content
Developer Wiki and Function Reference Links ×

control points 101


Recommended Posts

Pat

 

If you do MoveTo(ControlPoint01X,ControlPoint01Y); the object appears at the 0,0 of the control object.  But what if I want it someplace else relative to the control object?

 

I'm assuming if I write an offset from that it will regenerate to that offset even after the user moves the control point.  But I'm not sure.

Link to comment
5 minutes ago, Pat Stanford said:

Completely untested. VW not even running right now.

😀

 

But the control point is a parameter of the tool.  If I understand correctly you can't assign a value to it in the script, you would have to write it to a record field.

 

I guess what I'm asking is how does the door label get offset from the insertion point of the door by default and the door label appears to be centered on the control point?

Link to comment

I don't think you can assign control point values to a tool, because there is no object instance, but I have never tried.

 

I move the control points of PIO objects all the time.

 

OffsetX := 10;

OffSetY := 5;

GetSymLoc(theObject, ObjX, ObjY)

SetRField(theObject, 'TheObjectPIOName',  'ControlPoint01X',  ObjX + OffsetX)

SetRField(theObject, 'TheObjectPIOName',  'ControlPoint01Y',  ObjY + OffsetY)

 

  • Like 1
Link to comment

Is the object you are trying to relate to the control point part of the custom object with the control point or a second object that you are relating in a parent/child relationship?

 

In general, there is nothing special about a control point: think of it as a dimension field measuring from the origin (insertion point) of the PIO. The only difference is that in addition to manually typing a value in the OIP, the user can set those distance values via clicking on the drawing.

 

 

  • Like 1
Link to comment

In this example I have a custom path object.  I'd like to place labels offset from the beginning and end of the path object..

 

I've never used control points before and just discovered that MoveTo(ControlPoint01X,ControlPoint01Y); before creating the text object works.  I didn't realize - and probably don't fully understand yet - that you should write the offset to the record.  Doing the math in the MoveTo function puts the label in the correct place, but makes the labels not coincident with the control point.

Link to comment

So just use the SetRField to set the control point to be where you want the label and then use the control points to set the location of the text.

 

But actually that might not work. I seem to remember that setting values to parameters are not stored until the end of the PIO execution. So you probably need to read the original control points into variables and then modify the variables to get the location to write the text and to also set the control point values before the end of the PIO.

  • Like 1
Link to comment

Do you want the labels to be part of the object ?

 

If yes, then: (I do the following with cable objects all the time.)

Do you want the user to be able to change the location of the label based on the user moving the control point?

If not, forget about the control point and write the place at the location of the first vertex and the last vertex.

If so, on creation, set the control points to the location of the first vertex and the last vertex, and from then on always place the text at the location of the control points. GetRField(theObj, theObjPIOName, 'ControlPoint01X').   

 

If no, then: (I do the following with Truss Labels all the time);

just find the location of the path object vertices and write the labels to those locations.

 

  • Like 1
Link to comment

I'm still not clear if the text blocks are part of the path object or separate objects on top of the path object.

 

I'm also not sure about your scenario: you say that you're inserting text at the control point, but that the control point needs to be moved to the text (?).

 

Or are you trying to set the label center to a default location on insertion that is based on the object's geometry?

  • Like 1
Link to comment

Thanks, Sam.  I'll try that.

 

Josh, I'm trying to place 2 text labels with control points so the user can adjust.  One is offset -xx,yy from the beginning of the custom path object and one is offset xx,yy from the end of the custom path object.

 

So the second option.   A default location based on the object's geometry.

Link to comment

So, do I assume correctly that the labels are part of the object?

 

You're going to want to define four dimension parameters to display the object. Hide the control point fields from the user in the OIP. The real work comes with enabling state events for your object and parsing them in the reset event.

 

If the object is created: use PointAlongPoly() to find initial control point values and write them to both the control point and the offset fields. Label 1, the control point = the offset. Label 2, the control point = the coordinate of the endpoint + the offset.

 

If the user has edited one of the offset fields: calculate the control point and write to field. Just treat the control point field like any other distance field.

 

If the user has edited one of the control point fields: calculate the offsets and write to the offset fields.

  • Like 1
Link to comment

So it would seem that the trick for you is to get a handle to the path of the path object.

For a path object:

your first vertex will be (0,0) so just add the offset to that (negative numbers to move left or down).

your last vertex will be Get 

     NumVertices:= GetVertNum(PathHd);

     GetPolyPt(PathHd,NumVertices,LastVertX, LastVertY);

          add the offset to that (negative numbers to move left or down).

Link to comment
  • 1 month later...

OK.  I think part of my confusion is whenever I change anything in the definition of the control point it adds an extra Y to the name of the y control point.  

 

image.thumb.png.d882afc33f1b7a586985c1ba4622db7a.png

 

Is this a known issue?

 

I was never able to get GetRField  do some math SetRfield MoveTo BeginText … to work.  

 

But just doing the math and doing a MoveTo works.

 

Edit:  I'm wrong doing the math results in handles that are offset from the labels.

Link to comment

I'm trying to write a tool the puts Begin Here at the beginning of the control polyline and End Here at the end of the polyline.

 

Any help on where to put the GetRField and SetRField would be MUCH appreciated.  The math I'm doing doesn't work.😖

 

PS.  the 1" offset from the beginning and end of the polyline are because it often returns an incorrect tangent at the ends.

 

Quote


Procedure Test;

VAR


SeatNumH, ObjectHandle, tempHandle,            
ControlGeometry,                                 
objectHand, recordHand, wallHand            : HANDLE;

XCordOffset, YCordOffset,                    
Rx,Ry,                                                
ControlLength                                 : REAL;

BTest                                        : BOOLEAN;    

PtAlongPath, TangentAtPoint                    : VECTOR;

Sx,Sy,                
objectName,            
CurrentClass                                : STRING;

Pt                                            : POINT;


BEGIN

CurrentClass := ActiveClass;

BTest := GetCustomObjectInfo(objectName, objectHand, recordHand, wallHand);

ControlGeometry := GetCustomObjectPath(objectHand);


ControlLength := HLength(ControlGeometry);

BTest := PointAlongPoly(ControlGeometry,1", PtAlongPath,TangentAtPoint);


    MoveTo(pControlPoint01X-24,pControlPoint01YY-24);
    BeginText;
    'BEGIN HERE'
    EndText;
    
    SetTextVerticalAlign(LNewObj,3);
    SetTextJust(LNewObj,2);
    SetPenColorByClass(LNewObj);
    SetFPatByClass(LNewObj);
    SetFillColorByClass(LNewObj);
    SetTextStyleByClass(LNewObj);
                                        


BTest := PointAlongPoly(ControlGeometry,ControlLength - 1", PtAlongPath,TangentAtPoint);

Sx:=GetRField(objectHand, 'BeginningAndEnd', 'pControlPoint02X');
Rx := Str2Num(Sx);

Sy:=GetRField(objectHand, 'BeginningAndEnd', 'pControlPoint02YY');
Ry := Str2Num(Sy);


    
    MoveTo(pControlPoint02X+PtAlongPath.x+24,pControlPoint02YY+PtAlongPath.y+24);
    BeginText;
    'END HERE'
    EndText;
    
    SetTextVerticalAlign(LNewObj,3);
    SetTextJust(LNewObj,2);
    SetPenColorByClass(LNewObj);
    SetFPatByClass(LNewObj);
    SetFillColorByClass(LNewObj);
    SetTextStyleByClass(LNewObj);
                                        


END;                                    

RUN(Test);
 

 

Link to comment

Hmmm. This doesn't happen for me - just the one Y. Made a second Control Point set and they labelled as expected; 'ControlPoint02X' and 'ControlPoint02Y'

 

I've just finished battling Control Points for one of my recent scripts. Snippets attached below (where relevant) - I can send you the full script via email if you need to break it apart (few relations would have to be made for forum posting!). But never had to write back to the control points...

 

------

 

    cpx,cpy,ctx,cty,control_round        :REAL; {Collection of Control Points}

 

-----

 

            
            cpx := PControlPoint01X;
            cpy := PControlPoint01Y;
            control_round := PControl_Round;

 

-----

 

            {Creating the Control Point Box and Text}
        
            IF show_title OR show_descr OR show_cat = TRUE THEN BEGIN
        
            { set the text properties }
            TextSize(10);
            TextRotate(0);
            TextJust(2);
            TextVerticalAlign(1);
            TextOrigin(cpx,cpy);
            
            label_concat:= '';
            IF show_title = TRUE THEN BEGIN
            label_concat:= Concat(label_concat,title_descr,CHR(13));
            end;
            IF show_descr = TRUE THEN BEGIN
            label_concat:= Concat(label_concat,body_descr,CHR(13));
            end;
            IF show_cat = TRUE THEN BEGIN
            label_concat:= Concat(label_concat,category_descr,CHR(13));
            end;
            
            CreateText(label_concat);
            
            cptext := LNewObj;
            
            { get the bounding box of the text }
            GetBBox(LNewObj,t1x,t1y,t2x,t2y);
        
            RRect(t1x-control_round,t1y+control_round,t2x+control_round,t2y-control_round,control_round,control_round);
            HMoveForward(cptext,TRUE);
            {message(Concat(t1x,' ',t1y,' ',t2x,' ',t2y));}
                END;        

 

------

 

 

It's dirty but seems to work for me and my floating info box.

 

#SorryNotSorry (bad codes are what I do!)

 

J

 

Screen Shot 2019-09-19 at 12.58.24 pm.png

Edited by James Russell
Wrote this in-between your posts!
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...