TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: V-Man on October 11, 2011, 09:09:27 AM

Title: Create Lwpolyline from selection
Post by: V-Man on October 11, 2011, 09:09:27 AM

I have a need for a routine to select an "Mpolygon" and based on the selection have it create a "LwPolyline" out of it via automated, not by user selection. So the end result would be an exact copy (per say) of the object except now it's a "LwPolyline.
Title: Re: Create Lwpolyline from selection
Post by: Lee Mac on October 11, 2011, 09:21:20 AM
What is an 'MPolygon' ?
Title: Re: Create Lwpolyline from selection
Post by: MP on October 11, 2011, 09:26:59 AM
dunno, but it sounds special
Title: Re: Create Lwpolyline from selection
Post by: Lee Mac on October 11, 2011, 09:40:56 AM
dunno, but it sounds special

Seeing as it starts with the letters 'MP' .. :lol:
Title: Re: Create Lwpolyline from selection
Post by: V-Man on October 11, 2011, 09:42:53 AM

I am sorry guys, this is a AutoCAD MAP function.
Title: Re: Create Lwpolyline from selection
Post by: MP on October 11, 2011, 09:55:22 AM
Seeing as it starts with the letters 'MP' .. :lol:

prolly rides to school on the short bus
Title: Re: Create Lwpolyline from selection
Post by: didier on October 17, 2011, 05:50:31 AM
Coucou

you can "explode" the "MPOLYGON"
it becomes a polyline.

please, excuse my bad English.

amicalement
Title: Re: Create Lwpolyline from selection
Post by: gile on October 17, 2011, 06:30:15 AM
Hi,

Quote
What is an 'MPolygon' ?
Quote
dunno, but it sounds special

You can see here (http://www.theswamp.org/index.php?topic=29131.msg346914#msg346914)that MPolygons which are MAP entities can be supported by AutoCAD (Vanilla).
The LISP routine is only a simple example, in reply #10, you can find a little .NET DLL where the PL2MPG command is defined. This command will convert polylines (2d) and circles into Mpolygons.
Title: Re: Create Lwpolyline from selection
Post by: Lee Mac on October 17, 2011, 06:39:23 AM
gile, I think you forgot to add the hyperlink to your post  :wink:

EDIT: Thanks for updating :)
Title: Re: Create Lwpolyline from selection
Post by: gile on October 17, 2011, 07:00:15 AM
Oopsss !
Repared.
Title: Re: Create Lwpolyline from selection
Post by: kraz on October 18, 2011, 07:23:24 AM
In my short english, you mean mpolygon convert into lwpolyline...right?
if you want to that, here are my convert prog.
Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:mp2lwp( / v8 sn ss i sl vtx pl)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun GetMPolyVtx (ent / v11 x y xylist v10s v nx ny)
  (defun mPolyVtx(Ent / AA X vtxlist)
    (setq VtxList '())
    (IF (= "MPOLYGON" (CDR (ASSOC 0 Ent)))
       (mapcar '(lambda (x) (if (= 10 (car x)) (setq VtxList (append VtxList (list (cdr x))) ) ) ) Ent)
       (PROGN
        (SETQ AA (ENTGET(ENTNEXT (CDR (ASSOC -1 Ent)))))
        (WHILE (/= "SEQEND" (CDR (ASSOC 0 AA)))
         (setq VtxList (append VtxList (list (cdr (ASSOC 10 AA)))))
         (SETQ AA (ENTGET(ENTNEXT (CDR (ASSOC -1 AA)))))
        )
      )
    );IF
     VtxList
  )
  (setq v11 (cdr (assoc 11 ent)));;mpolygon center point
  (setq x (car v11))
  (setq y (cadr v11))
  (setq xylist (list))
  (setq v10s (mpolyvtx ent))
  (foreach v v10s
    (setq x1 (car v) y1 (cadr v))
    (setq nx (+ x x1) ny (+ y y1))
    (setq xylist (append xylist (list (list nx ny 0))))
  )
  xylist
)
(defun make_pline (pte_list lay color cls / pl_source ptelen cnt ptele pte_list ptes epl8 epl62 )
 (setq pl_source (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 67 0)
                 (cons 62 color) (cons 8 lay) (cons 100 "AcDbPolyline")))
 (setq ptelen (length pte_list)
       cnt 0)
 (setq pl_source (append pl_source (list (cons 90 ptelen))))
 (if (or (eq cls "c")(eq cls "C")(eq cls "1")(eq cls 1))
  (progn
   (setq cls 1)
   (setq pl_source (append pl_source (list (cons 70 cls))))
  )
 )
 (while (< cnt ptelen)
   (setq ptele (car pte_list)
         pte_list (cdr pte_list)
        ptes (cons 10 ptele)
        pl_source (append pl_source (list ptes))
         cnt (+ cnt 1)
  )
 );;while end
 (entmake pl_source)
 (entlast)
);entmake_pline
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (princ "\n SELECT MPOLYGON >> ")
 (setq ss (ssget (list (cons 0 "MPOLYGON")))
       sl (sslength ss)
       i 0
 )
 (repeat sl
  (setq sn (ssname ss i)
        i (1+ i)
        vtx (cdr (getmpolyvtx (entget sn)))
        vtx (append vtx (list (nth 0 vtx)))
        v8 (cdr (assoc 8 (entget sn)))
        pl (make_pline vtx v8 256 "c")
  )
  (entdel sn)
 );repeat end
 (princ "\n...COMPLETE...")(princ)
)
Title: Re: Create Lwpolyline from selection
Post by: V-Man on October 20, 2011, 12:40:59 PM

Quote
In my short english, you mean mpolygon convert into lwpolyline...right?
if you want to that, here are my convert prog.

Yes, and Thank you. This works perfect.
Title: Re: Create Lwpolyline from selection
Post by: alanjt on October 20, 2011, 12:54:32 PM
Just explode it.