Page 1 of 2 12 LastLast
Results 1 to 10 of 15

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

  1. #1
    I could stop if I wanted to
    Join Date
    2005-08
    Posts
    378
    Login to Give a bone
    0

    Cool 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. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,779
    Login to Give a bone
    0

    Default 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.
    R.K. McSwain | CAD Panacea |

  3. #3
    I could stop if I wanted to
    Join Date
    2005-08
    Posts
    378
    Login to Give a bone
    0

    Cool 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
    Last edited by stephen.coff; 2007-09-07 at 09:58 PM.

  4. #4
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,779
    Login to Give a bone
    0

    Default 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?
    R.K. McSwain | CAD Panacea |

  5. #5
    I could stop if I wanted to
    Join Date
    2005-08
    Posts
    378
    Login to Give a bone
    0

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

    rkmcswain,
    Thanks for the quick reply.
    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:

    (setvar "FILLETRAD" D)
    (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. #6
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,779
    Login to Give a bone
    0

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

    Quote Originally Posted by stephen.coff View Post
    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)
    R.K. McSwain | CAD Panacea |

  7. #7
    I could stop if I wanted to
    Join Date
    2005-08
    Posts
    378
    Login to Give a bone
    0

    Cool 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. #8
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

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

    Quote Originally Posted by stephen.coff View Post
    . . . Once I can work out the angle. . .
    Use vlax-curve-getFirstDeriv, read this LINK

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

    : ) Happy Computing !

    kennet
    Last edited by kennet.sjoberg; 2007-09-08 at 05:59 AM. Reason: added: (vlax-curve-getParamAtDist curve-obj dist)
    The essential thing is what you write in the post. . . .not the numbers of posts.

  9. #9
    I could stop if I wanted to
    Join Date
    2005-08
    Posts
    378
    Login to Give a bone
    0

    Default 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.
    Attached Files Attached Files

  10. #10
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

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

    Quote Originally Posted by stephen.coff View Post
    . . . I don't wish to select a point on the line. . .
    you don't need to pick a point,
    read again please (setq Param (vlax-curve-getParamAtDist VlaObj 200 ) )
    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
    Last edited by kennet.sjoberg; 2007-09-08 at 01:28 PM. Reason: added code
    The essential thing is what you write in the post. . . .not the numbers of posts.

Page 1 of 2 12 LastLast

Similar Threads

  1. 2013: z value at intersection points in 3d polyline and polyline
    By jaychandran in forum AutoCAD Civil 3D - General
    Replies: 1
    Last Post: 2013-10-30, 05:20 PM
  2. Replies: 0
    Last Post: 2012-01-26, 04:49 PM
  3. Replies: 10
    Last Post: 2007-02-07, 02:55 PM
  4. Angle of an embeded line or polyline
    By cadconcepts in forum AutoLISP
    Replies: 1
    Last Post: 2006-02-24, 02:46 AM

Posting Permissions

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