Discussion Groups

All Discussion Groups » Visual LISP, AutoLISP and General Customization Issues

Thread: PLINE to MLINE


Permlink Replies: 4 - Last Post: Feb 5, 2003 7:19 AM Last Post By: elefebvre
elefebvre

Posts: 153
Registered: 11/27/03
PLINE to MLINE
Posted: Feb 5, 2003 12:48 AM
  Click to reply to this thread Reply
I want to chnage all my plines (and also normal lines) to mlines with a lisp routine, or anyting else if that does exist. I can easily retrieve the coordinates of every vertix of the pline, but how do I get it to create and Mline? I use a repeat function that runs the loop as many times as there are vertices, but how do I get these to the mline command?

any help would be very much appreciated.

PS: i attached a rough version of the routine
Burke, Joe
Re: PLINE to MLINE
Posted: Feb 5, 2003 3:59 AM   in response to: elefebvre in response to: elefebvre
  Click to reply to this thread Reply
elefebvre,

Here's a bit more conventional approach. The mline is one object, given a
lwpline as the source object. I think that was your question?

Note: if a pline is closed, the mline will not include the closing segment.
The program should check for closed. If so, add the first point to the end
of the point list. Following is a function which checks for closed.

;arguments poly: lwpolyline ename
;returns T if pline is closed, nil if not
(defun isclosed (poly)
(if (= "LWPOLYLINE" (cdr (assoc 0 (entget poly))))
(= 1 (logand 1 (cdr (assoc 70 (entget poly)))))
) ;if
) ;end

Ask questions if any of this isn't clear.

Joe Burke


; CHANGE LINE/PLINE TO MLINE
(defun c:lml ()

;returns list associated with a DXF code
;arguments key: DXF code, alist: object data list
(defun massoc (key alist / x nlist)
(foreach x alist
(if (eq key (car x))
(setq nlist (cons (cdr x) nlist))
)
)
(reverse nlist)
) ;end

;(setq s (ssget))
(setq s (ssget '((0 . "LINE,LWPOLYLINE"))))
(setq teller 0)
(repeat (sslength s)
(setq en (ssname s teller))
(setq ent (entget en))
(if (= "LINE" (cdr (assoc 0 ent)))
(setq PtLst (list (cdr (assoc 10 ent)) (cdr (assoc 11 ent))))
) ;if
(if (= "LWPOLYLINE" (cdr (assoc 0 ent)))
(setq PtLst (massoc 10 ent))
) ;if
(command "mline" (foreach pt PtLst (command pt))) ;point list fed to
mline
;(command "erase" en "")
(entdel en)
(setq teller (1+ teller))
) ;repeat
(princ)
) ;end

elefebvre

Posts: 153
Registered: 11/27/03
Re:
Posted: Feb 5, 2003 4:53 AM   in response to: Burke, Joe in response to: Burke, Joe
  Click to reply to this thread Reply
Hey Joe, thanks a bunch!

one thing though, the mline appears about 90° rotated around (I guess) about the center area of the object.

Any reasons why?
Burke, Joe
Re:
Posted: Feb 5, 2003 5:39 AM   in response to: elefebvre in response to: elefebvre
  Click to reply to this thread Reply
elefebvre,

You're welcome.

The most likely reason for this:

one thing though, the mline appears about 90° rotated around (I guess)
about the center area of the object.
Any reasons why?


Because you may be working in a rotated UCS. The fix for that is as follows:

(setq s (ssget '((0 . "LINE,LWPOLYLINE"))))
(setq teller 0)
(repeat (sslength s)
(setq en (ssname s teller))
(setq ent (entget en))
(if (= "LINE" (cdr (assoc 0 ent)))
(setq PtLst (list (cdr (assoc 10 ent)) (cdr (assoc 11 ent))))
) ;if
(if (= "LWPOLYLINE" (cdr (assoc 0 ent)))
(setq PtLst (massoc 10 ent))
) ;if
(setq TempLst PtLst) ;added from here
(setq PtLst nil)
(foreach x TempLst
(setq PtLst (cons (trans x 0 1) Ptlst))) ;to here
(command "mline" (foreach pt PtLst (command pt))) ;point list to mline
(entdel en)
(setq teller (1+ teller))
) ;repeat
(princ)
) ;end

elefebvre

Posts: 153
Registered: 11/27/03
Re:
Posted: Feb 5, 2003 7:19 AM   in response to: Burke, Joe in response to: Burke, Joe
  Click to reply to this thread Reply
works great! thanks a lot!!