Change 2d polyline to line

Change 2d polyline to line

etilley327KA
Advocate Advocate
806 Views
13 Replies
Message 1 of 14

Change 2d polyline to line

etilley327KA
Advocate
Advocate

What's the simplest way to switch a 2D polyline to a line. I can just explode it usually, but the command in the lisp doesn't seem to work.

0 Likes
Accepted solutions (1)
807 Views
13 Replies
Replies (13)
Message 2 of 14

pendean
Community Legend
Community Legend
EXPLODE command always works.

No idea about your LISP though, you forgot to include it here for us to see what all it is supposed to do.
0 Likes
Message 3 of 14

etilley327KA
Advocate
Advocate

Apologies. 

 

(defun c:test (/ A 1stS 2ndS)
  (setq A (entsel))
(command "_.explode" A "")
(setq A (car A))
(command "_move" A "" "" "0,0,0.00")
(setq
          1stS (vlax-curve-getStartPoint A)
          2ndS (vlax-curve-getEndPoint A))
(princ 1stS)
(princ 2ndS)
)
0 Likes
Message 4 of 14

calderg1000
Mentor
Mentor

Regards @etilley327KA 

Try this code...

(defun c:xlp (/ s sp ep ln)
  (princ "\nSelect Lwpolyline:")
  (while (null (setq s (ssget "_+.:E:S" '((0 . "lwpolyline")))))
    (princ "\n¡Empty selection or not a valid Lwpolyline!")
  )
  (setq sp (vlax-curve-getstartpoint (ssname s 0))
        ep (vlax-curve-getendpoint (ssname s 0))
        ln (entmakex (list '(0 . "line")
                           (cons 10 sp)
                           (cons 11 ep)
                     )
           )
  )
  (entdel (ssname s 0))
  (princ)
)

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 5 of 14

calderg1000
Mentor
Mentor
Accepted solution

Dear @etilley327KA 

I made some small changes to your code. I don't understand why you move the exploded object to its same location "0.,0.,0"...?

 

(defun c:test (/ A 1stS 2ndS)
  (setq A (car (entsel)))
  (command "_.explode" A)
  (setq A (entlast))
  (command "_move" A "" "" "0.,0.,0.")
  (setq
    1stS (vlax-curve-getStartPoint A)
    2ndS (vlax-curve-getEndPoint A)
  )
  (princ 1stS)
  (princ 2ndS)
)

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 6 of 14

Kent1Cooper
Consultant
Consultant

When used in an AutoLisp (command) function, Explode can work on only one object [it surprised me a little that it will accept the list that is in your A variable, and didn't require just the entity name].  It doesn't take the Enter "" to complete the selection -- that will only recall your previous command, unwanted.

But once it has been Exploded, there is no (car A) any more.

Kent Cooper, AIA
Message 7 of 14

Moshe-A
Mentor
Mentor

@etilley327KA  hi,

 

Calling "explode" from (command) function has always behave differently e.g it explode only the first selected object and finish.

 

; example

(command "explode" "Last") 

 

there was no need to end the selection, why is that? Autodesk holds the  answer 😀

 

to overcome this (and for other command) they gave us (initcommandvertion) function (read on that in online help)

 

the following would work.

 

enjoy

moshe

 

(defun c:test (/ ss)
 (if (setq ss (ssget))
  (progn
   (initcommandversion 2)
   (command "explode" ss "")
  )
 )
)

 

Message 8 of 14

etilley327KA
Advocate
Advocate
Thanks, so I had to reset the variable after it exploded. I move it to the same location, but moved the elevation to zero.
0 Likes
Message 9 of 14

etilley327KA
Advocate
Advocate

I thought the move command was just adjusting the entity to zero Z, but now ive noticed that it started moving its location (X,Y). How might I adjust this so that it only moves on the Z?

0 Likes
Message 10 of 14

Kent1Cooper
Consultant
Consultant

@etilley327KA wrote:

.... How might I adjust this so that it only moves on the Z?


One way:

 

(command "_.move" A ""
  (setq p1 (cdr (assoc 10 (entget A)))); from its start point
  (list (car p1) (cadr p1) 0); to the same X & Y, but with Z = 0
)

 

You could use 11 instead of 10, to use the end point, if it matters.  It should matter only if the Line has unequal Z values for its two ends, but if that's true and you want both ends at Z=0, Move isn't going to do it for you -- there would need to be separate adjustments to the two ends.

Kent Cooper, AIA
Message 11 of 14

etilley327KA
Advocate
Advocate
Thats perfect
0 Likes
Message 12 of 14

calderg1000
Mentor
Mentor

Dear @etilley327KA 

Try this code

 

(defun c:test (/ A 1stS 2ndS)
  (setq A (car (entsel)))
  (command "_.explode" A)
  (command "_change" (entlast) "" "p" "e" "0" "")
  (setq
    1stS (vlax-curve-getStartPoint (entlast))
    2ndS (vlax-curve-getEndPoint (entlast))
  )
  (princ 1stS)
  (princ 2ndS)
  (princ)
)

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 13 of 14

Kent1Cooper
Consultant
Consultant

@calderg1000 wrote:
....
  (command "_change" (entlast) "" "p" "e" "0" "")
....

That's more concise than using MOVE, provided the Line in question has equal Z values at both ends, i.e. that it has an "elevation" property to change.  It won't work if the Z values differ.

Kent Cooper, AIA
0 Likes
Message 14 of 14

calderg1000
Mentor
Mentor

Dear @Kent1Cooper 

The request is to exploit a polyline, it is supposed to have a section and with elevation. To obtain a Line, therefore after exploiting its 2 vertices will have the same elevation.
I think you should specify:

;...
(setq A (car (entsel"\nSelect Lwpolyline:")))
;...

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes