Hello everyone!
I'm trying to create an autolisp that is able to transform a polyline in input into a multiline.
The following is the code I could think of but it's not working properly.
It should ask as input the pline/plines to transform in mlines, mlstyle, justification, scale and if it should delete the plines or not.
If the inputs about style, justification and scale are not entered it should use the default or active style/just/scale.
Does anyone have any tips/tricks to correct it?
Many thanks in advance!
(defun pl2ml (/ pl sel mlstyle justify scale del)
(setq pl (entsel "\nSelect polyline(s) to convert: "))
(setq sel (ssget "_X" pl))
(if (not sel)
(progn
(princ "\nNo polylines selected.")
(exit)
)
)
(setq mlstyle (getstring "\nEnter multiline style name (blank for current style): "))
(if (or (null mlstyle) (= (strlen mlstyle) 0))
(setq mlstyle (cdr (assoc 2 (tblsearch "STYLE" (getvar "CURMLSTYLE")))))
)
(setq justify (getkword "\nEnter justification [Top/Zero/Bottom]: "))
(if (or (null justify) (= (strlen justify) 0))
(setq justify "Zero")
)
(setq scale (getreal "\nEnter multiline scale (blank for current scale): "))
(if (or (null scale) (= scale 0.0))
(setq scale (getvar "DIMSCALE"))
)
(setq del (getkword "\nErase polylines? [Yes/No]: "))
(if (or (null del) (= (strlen del) 0))
(setq del "No")
)
(setq count 0)
(setq sslen (sslength sel))
(repeat sslen
(setq obj (ssname sel count))
(setq pline (vlax-ename->vla-object obj))
(setq pcount (vla-get-Vertices pline))
(setq newml (vla-addobject (vla-get-ActiveSpace (vla-get-DocumentManager (vlax-get-acad-object))) acMultiline))
(vla-put-StyleName newml mlstyle)
(vla-put-Justification newml (vlax-variant-value (assoc justify '(("Top" . acMLineTop") ("Zero" . acMLineZero) ("Bottom" . acMLineBottom))))))
(vla-put-Scale newml scale)
(repeat (1- pcount)
(setq sp (vla-get-Vertex pline (- pcount 1)))
(setq ep (vla-get-Vertex pline pcount))
(vla-addMLine newml sp ep)
(setq pcount (1- pcount))
)
(setq count (1+ count))
)
(if (= del "Yes")
(progn
(setq sslen (sslength sel))
(repeat sslen
(setq obj (ssname sel (1- sslen)))
(command "_.erase" obj "")
(setq sslen (1- sslen))
)
)
)
(princ)
)
Solved! Go to Solution.
Solved by maxim_k. Go to Solution.
I just found this discussion on the forum. The code works, I'm searching for a way to implement that with more inputs.
Hi @LucaCornia ,
@LucaCornia wrote:......I'm searching for a way to implement that with more inputs.
Something like this:
; 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 '((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
(initget "T Z B")
(setq justify (getkword "\nEnter justification [Top/Zero/Bottom]: "))
(if (or (null justify) (= (strlen justify) 0))
(setq justify "Zero")
)
(setq scale (getreal "\nEnter multiline scale (blank for current scale): "))
(if (or (null scale) (= scale 0.0))
(setq scale (getvar "DIMSCALE"))
)
(command "mline" "_J" justify "_S" scale
;(command "mline"
(foreach pt PtLst (command pt))) ;point list to mline
(entdel en)
(setq teller (1+ teller))
) ;repeat
(princ)
) ;end
It's great, it works wonders! Thank you very much, you have been of great help!
Can't find what you're looking for? Ask the community or share your knowledge.