DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Extending a line

Started by MarkX, September 06, 2011, 12:56:41 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MarkX

Ok. For what its worth, here's code to extend a line a specified distance, moving away from specified end. You will probably have to use gravity snap to specify the end of the line, because any other point on the line will  result in unknown results. Guess I could refine it, but it was mostly an introduction DC basic.

Mark


'LineExtend
'=====================================================
'PURPOSE:
'Asks for endpoint of line and desired line length.
'Then extends line moving outward from specified endpoint.
'=====================================================
'REM CREATE AN ARRAY TO STORE CURRENT POINT POSITIONS
DIM PT_X(5), PT_Y(5), PT_Z(5)   
'REM GET LINE
SETPOINT "Select your line at the end you'll extend." 1
POINTVAL XV, YV, ZV, 1
SYS(1)=0

'REM GET NEW LINE LENGTH
INPUT "How long is the new line?" NEW_LINE_LENGTH

'REM NOW FIND LINE ENTIY IDENTIFICATION
>getEntity
{
<pointXYZ [XV,YV,ZV]
<Type 1
<All 0
<MarkSkip 1
<MarkSkip 1
}
LINE_ID = SYS(1040)

'REM FILL POINT BUFFERS WITH LINE INFORMATION
ENTITY LINE_ID
NUM = SYS(1)
'Transfer point buffers to array
FOR J = 1 TO SYS(1)
POINTVAL PT_X(J), PT_Y(J), PT_Z(J), J
NEXT J

'REM FIGURE OUT WHICH END IS WHICH
IF PT_X(1) = XV AND PT_Y(1) =  YV AND PT_Z(1) = ZV THEN
END_PT = 2
START_PT = 1
ELSE
END_PT = 1
START_PT = 2
END IF

'REM CALCULATE CURRENT LINE LENGTH
DIST=Length(LINE_ID)

R=NEW_LINE_LENGTH/DIST                           
XN=PT_X(END_PT) - R*(PT_X(END_PT) - XV)
YN=PT_Y(END_PT) - R*(PT_Y(END_PT) - YV)
ZN=PT_Z(END_PT) - R*(PT_Z(END_PT) - ZV)

'REM EXTEND THE LINE
>Extend
{
<SelectOnly 0
<PointXYZ  [PT_X(START_PT),PT_Y(START_PT),PT_Z(START_PT) ]
<PointXYZ  [XN,YN,ZN ]
}

END