# Thread: Shortening a Polyline & Dertermine angle of first part of Polyline ?

1. Login to Give a bone

## Shortening a Polyline & Dertermine angle of first part of Polyline ?

Guys,
I wish to draw a polyline from "a" to "b" and when drawn the polyline have lisp shorten the line 200mm in the driection the line is moving. I wish to insert a block at the inital star point and require the polyline to be shortned to fit the block. I need to work out the angle so i know what angle to insert the block.
Any assistance would be most grateful

Stephen

2. Login to Give a bone

## Re: Shortening a Polyline & Dertermine angle of first part of Polyline ?

Here is one way.

Code:
```(setq pt1 (getpoint "\n Pick first point: ")
pt2 (getpoint pt1 "\n Pick second point: "))
(if (> (setq d1 (distance pt1 pt2)) 200.0)
(progn
(setq newpt2 (polar pt1 (setq a1 (angle pt1 pt2))(- d1 200.0)))
(command "._pline" pt1 newpt2 "")
)
)```
This will drawing the shortened polyline, and a1 is the angle between the first point and the second point.

3. Login to Give a bone

## Re: Shortening a Polyline & Dertermine angle of first part of Polyline ?

Thank you rkmcswain,
Whilst that will work and am grateful for your reply. I am actually wanting to add this to a routine I already have. I use the command "pline" and draw a polyline, fillet it and then offset a copy both sides of the line to represent what would be flexible duct. I am not sure how to pull the dxf codes for the first and second points. I guess where I am really stuck is how to get the second point of the polyline. With getting that, I can then work out the angle, have the start point to insert the block representing the spigot. I then have no idea how to shorten the line from start point exactly 200mm. Saying that, that is in the code you have given me. I just want to be able to pull the dxf codes automatically without having to physically selet the points.
Would you be able to assist me further, with this ?

Stephen

Actually, I just looked at the code and it getting the points selected, shortening the distance and then drawing a new line over the top. I amactually wanting to shorten an already drawn polyline by 200mm from the start point at the same angle etc.

I hope this makes things clearer ?

Stephen

4. Login to Give a bone

## Re: Shortening a Polyline & Dertermine angle of first part of Polyline ?

Let's start over. You have an existing polyline, and you want to shorten it by 200 units?

Was this polyline constructed using code, or just by using the ._PLINE command and manually picking points?

If the former, then you should already know the two points of the pline. If the latter, then you need to select the pline and extract the two desired points? Is this all correct?

5. Login to Give a bone

## Re: Shortening a Polyline & Dertermine angle of first part of Polyline ?

rkmcswain,
Well the polyline has been drawn using code though also using the pline command. That said the polyline isn't a straight simple line it could be straight though could be a filleted zig zagof a polyline. This is where I am stuck, I don't know how to extract the next point with code. When I pull the dxf codes I have multiples of code "10".
Currently I am getting the start point from this part of the routine, varible "PST".
Part of this section is from a routine CAB did for someone else as part of a pipe routine:

(prompt "\n*** Draw The Flexible Duct.")
(command "pline")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
(setq ET (entlast))
(setq VLIST (cdrs 10 (entget ET))
PST (car VLIST)
PEND (car (reverse VLIST))
)
(if (= (cdr (assoc 0 (entget ET))) "LWPOLYLINE")
(progn
(command "fillet" "p" ET)
(offsetdouble ET HD)
(command "Change" ET "" "p" "lt" "FLEXCENTER1" "c" "21" "" "")
)
)

(defun cdrs (key LST / PAIR RTN)
(while (setq PAIR (assoc key LST))
(setq RTN (cons (cdr PAIR) RTN)
LST (cdr (member PAIR LST))
)
)
(reverse RTN)
)

I can't work out how to get the points with code, even if done whilst using code. If that makes sense ?

Stephen

6. Login to Give a bone

## Re: Shortening a Polyline & Dertermine angle of first part of Polyline ?

Originally Posted by stephen.coff
Well the polyline has been drawn using code though also using the pline command. That said the polyline isn't a straight simple line it could be straight though could be a filleted zig zagof a polyline. This is where I am stuck, I don't know how to extract the next point with code.
Don't worry about that. This will locate the point 200 units from the endpoint of the polyline, regardless of the number of segments.

Code:
```(setq obj (vlax-ename->vla-object (car (entsel))))
(vlax-curve-GetPointAtDist obj (- (vla-get-Length obj) 200.0))```
Now I guess the question is, how to shorten the polyline to this point.
This works for me...

Code:
`(command "._lengthen" "_De" "-200" (vlax-curve-getendpoint obj))`
...although I suspect you would have problems if there was another entity at the exact same coordinates as the endpoint of the polyline....

Too bad the "length" property is RO....

I suppose you could iterate the polyline coordinates backwards from the endpoint until you reach the point calculated in the first code snip... then reconstruct the polyline using all the original points up to the new point.

Check out also (vla-get-Coordinates)

7. Login to Give a bone

## Re: Shortening a Polyline & Dertermine angle of first part of Polyline ?

rkmcswain,
I am sure I am known on this forum as a real pain in the .....
While what you have given me helps a little not really. The code given works if the polyline is then selected by the user. I don't wan't to have to select it, the polyline is drawn using the routine and wish to just use the entlast command as the selction.

The last part works as a resolution of part of the problem, only part.

(setq et (entlast))
(command "._lengthen" "_De" "-200" et)

Excellent, the polyline is shortend 200mm from the starting point. Being that the polyline could be zig zagging all over the place. I figure I need the start point co-ordinates and the following point co-ordinates, to work out the angle ? Once I can work out the angle I know the correct angle to insert the spigot at the start of the polyline. This will also have given me the start point to locate the spigot on.

Stephen

8. Login to Give a bone

## Re: Shortening a Polyline & Dertermine angle of first part of Polyline ?

Originally Posted by stephen.coff
. . . Once I can work out the angle. . .

and replace (setq Param . . .
with
(setq Param (vlax-curve-getParamAtDist VlaObj 200 ) )

: ) Happy Computing !

kennet

9. Login to Give a bone

## Re: Shortening a Polyline & Dertermine angle of first part of Polyline ?

Kennet,
This is really starting to do my head in and stilkl not getting it. This is the only thing stopping the routine from working perfectly. I some how managed to work out how to get it all this far but can't work out how to use the answer you have given me.
I am not sure how to convert the answer given and reading it sounds as though it will never give me what I am looking for. I don't wish to select a point on the line rather have it all automated.

See attached routine.

10. Login to Give a bone

## Re: Shortening a Polyline & Dertermine angle of first part of Polyline ?

Originally Posted by stephen.coff
. . . I don't wish to select a point on the line. . .
you don't need to pick a point,
200 is the distance

Code:
```(vl-load-com )
draw the pline here
(setq VlaObj (vlax-ename->vla-object (entlast)) )
(setq LastEnt (entlast))
(setq Param (vlax-curve-getParamAtDist VlaObj 200 ) )
(setq AngDeg (* (/ (angle (vlax-curve-getFirstDeriv VlaObj Param ) '(0.0 0.0 0.0)) pi ) 180 ) )
(setq StartPoint (vlax-curve-getStartPoint VlaObj ) )
(command "._insert" "MyBlock" StartPoint "" AngDeg "" )
(command "._lengthen" "_De" "-200" LastEnt )```

: ) Happy Computing !

kennet

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•