Lisp for Change mline segment

Lisp for Change mline segment

Anonymous
Not applicable
3,195 Views
14 Replies
Message 1 of 15

Lisp for Change mline segment

Anonymous
Not applicable

Hai all,

 

Can anyone help me to get out from this....

 

I have several mline segments in my DWG. with mline style names ub203,ub305, like that....I have a lisp commands to draw mlines and the lisp command names are same as mline style names.

 

Now, I want to write another lisp to change this mlines from one style another. I need a program with following steps:

 

Step1

Cmd: chml

Get string "Enter the new size to update" (ub203/ub305/...something like that)

 

Step2

 

Entsel "select the mline to change" 

Get the layer property of the mline

Get the start and end point of the mline

 

Step 3

 

Draw a new mline By using a (UB203...Ub305 lisplisp command)

here I wants to enter a get string value to execute command

Keep the existing mline layer settings for new mline

Use start and end points of existing mline to draw a new mline

 

Step4

 

Delete the existing mline

 

Step 5

 

Repeat steps 2 to 4

 

Enter

 

Enter)

 

Can help me how to write this lisp?

 

 

 

0 Likes
Accepted solutions (1)
3,196 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable

Following lisp is my learning through this portal. Still, unable to identify my mistakes.

 

(defun c:chml()

(Setq siz (getstring "\nenter the new size to update: "))

(Setq obj (entsel "\nselect a mline to change :")

Lt1 (car obj)

DAT (entget lt1)

Pt1 (CDR (Assoc 10 DAT))

Pt2 (CDR (assoc 11 DAT))

(Entdel lt1)

(Command "_.mline" "j" "t" "st" siz "s" "1" pt1 pt2 "")

(Repeat obj)

)

)

 

 

0 Likes
Message 3 of 15

ВeekeeCZ
Consultant
Consultant

Hi, try this... it's replacing whole mline. It's for multiple selection. Not sure that i follow your steps... hope you dont mind.

 

Spoiler
; BeekeeCZ 2015/09
; Change MLine Style

(vl-load-com)

(defun c:CHMLS ( / *error* LM:UniqueFuzz nVAR oVAR adoc ss edo edn a tmp vrts)

  ; ----
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (mapcar 'setvar nVAR oVAR)
    (vla-endundomark adoc)
    (princ))

  ;----- Lee Mac, http://www.lee-mac.com/uniqueduplicate.html
  (defun LM:UniqueFuzz (l f)
    (if l (cons (car l)
		(LM:UniqueFuzz (vl-remove-if (function (lambda ( x ) (equal x (car l) f))) (cdr l))
		               f))))
  
  ; ----
  ; ----
  
  (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
  (setq oVAR (mapcar 'getvar (setq nVAR '(CMDECHO OSMODE ORTHOMODE SNAPMODE BLIPMODE CMLSTYLE CMLJUST CMLSCALE))))
  
  
  (if (and (princ "\nNeed MLINEs,")
           (setq ss (ssget ":L" '((0 . "MLINE"))))
           (setq #nstyle (if (= "" (setq tmp (getstring (strcat "\nChange style to <" (cond (#nstyle) ("N/A")) ">: "))))
                           (cond (#nstyle)
                                 (nil))
                           tmp))
           (dictsearch (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_MLINESTYLE"))) #nstyle)
           )
    (progn
      (repeat (setq i (sslength ss))
        
        (setq edo (entget (ssname ss (setq i (1- i))))
              vrts (LM:UniqueFuzz (mapcar 'cdr (vl-remove-if-not '(lambda (x) (member (car x) '(10 11))) edo)) 0.001))
        
        (mapcar 'setvar nVAR (list 1 0 0 0 0 #nstyle (cdr (assoc 70 edo)) (cdr (assoc 40 edo))))
        (command "_.MLINE") (apply 'command vrts) (command)
        (setq edn (entget (entlast)))
        
        (entmod (foreach e (vl-remove 'nil (mapcar '(lambda (x) (assoc x edo)) '(6 8 62 39 43 48 370 71)))
                  (setq edn (if (setq a (assoc (car e) edn))
                              (subst  e
                                      a
                                      edn)
                              (append edn
                                      (list e))))))
      )
      (command "_.ERASE" ss ""))
    (cond ((not ss)
           (princ "No MLINEs selected."))
          ((not (dictsearch (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_MLINESTYLE"))) #nstyle))
           (princ (strcat #nstyle " mline style does not exists/loaded."))
           (setq #nstyle nil)))
    )
  (*error* "end")
)

      

 

0 Likes
Message 4 of 15

Anonymous
Not applicable

First of all, thank you so much Beekeecz for your reply. I am unable to test this today. Tomorrow I'll  post my comment regard this.

 

But, I have couple of quaries.

1. Where I can put my new mlstyle names? I wants to keep this as a user input. I am at the elementary level. So, unable to understand your lisp is easily.

 

2. Is this program will change the all Mlines in the drawing? Because my requirement is to change the selective line segments only. But the segments are noncontinuous.

0 Likes
Message 5 of 15

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

First of all, thank you so much Beekeecz for your reply. I am unable to test this today. Tomorrow I'll  post my comment regard this.

 

But, I have couple of quaries.

1. Where I can put my new mlstyle names? I wants to keep this as a user input. I am at the elementary level. So, unable to understand your lisp is easily.

>> Yes, the user is prompted for that. You can set some as default.

 

2. Is this program will change the all Mlines in the drawing? Because my requirement is to change the selective line segments only. But the segments are noncontinuous.

>> No, just selected ones. I have asked you before, but you never explaind what you mean by MLINE SEGMENT. So by your previous statements I figured that you mean MLINE WITH SINGLE SEGMENT by that. But maybe I am wrong and your MLINEs have more than 1 segment and you want to change just one of them...


 

0 Likes
Message 6 of 15

Anonymous
Not applicable

Thanks Beekeecz. I apologize for not to explain clearly. Yes. My drawing contains single mline segment (not a continuous line) at several places. Some places with ub203 style and some places with ub305 style and so on..Based on the design requirement, I have to change from Ub203 to ub305,or UB457 like that....

 

Hope this will clear to you..

 

Unable to send you the DWG becaz of not  having a  net access in my office.

0 Likes
Message 7 of 15

Anonymous
Not applicable

Excellent. It's working awsome Beekeecz.

 

 

Except one thing. The lisp placing the new mlines at the location of where the existing mlines created. My problem is the existing mlines in my drawings were already modified (moved/trimmed/ extended) here and there. 

 

What I understood is,  this program only identifies the originated start and end point of the elements and not the current start and end point of the elements.

 

Is there any solution to change this?

0 Likes
Message 8 of 15

ВeekeeCZ
Consultant
Consultant
Accepted solution

Test this one. (command name changed to CHML)

 

Spoiler
; BeekeeCZ 2015/09
; updated for UCS 2022/06
; CHange MLine style

(vl-load-com)

(defun c:CHML ( / *error* LM:UniqueFuzz nVAR oVAR adoc ss edo edn a tmp vrts)

  ; ----
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (mapcar 'setvar nVAR oVAR)
    (vla-endundomark adoc)
    (princ))

  ;----- Lee Mac, http://www.lee-mac.com/uniqueduplicate.html
  (defun LM:UniqueFuzz (l f)
    (if l (cons (car l)
		(LM:UniqueFuzz (vl-remove-if (function (lambda ( x ) (equal x (car l) f))) (cdr l))
		               f))))
  
  ; ----
  ; ----
  
  (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
  (setq oVAR (mapcar 'getvar (setq nVAR '(CMDECHO OSMODE ORTHOMODE SNAPMODE BLIPMODE CMLSTYLE CMLJUST CMLSCALE))))
  
  
  (if (and (princ "\nNeed MLINEs,")
           (setq ss (ssget ":L" '((0 . "MLINE"))))
           (setq #nstyle (if (= "" (setq tmp (getstring (strcat "\nChange style to <" (cond (#nstyle) ("N/A")) ">: ")))) ; Default style: Replace N/A
                           (cond (#nstyle)
                                 (nil))											 ; Default style: Replace nil
                           tmp))
           (dictsearch (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_MLINESTYLE"))) #nstyle)
	   (mapcar 'setvar '(CMDECHO OSMODE ORTHOMODE SNAPMODE BLIPMODE) (list 0 0 0 0 0))
	   
           )
    (progn
      (repeat (setq i (sslength ss))
        
        (setq edo (entget (ssname ss (setq i (1- i))))
              vrts (LM:UniqueFuzz (mapcar 'cdr (vl-remove-if-not '(lambda (x) (member (car x) '(11))) edo)) 0.001)
	      vrts (mapcar '(lambda (x) (trans x 0 1)) vrts))
        
        (mapcar 'setvar '(CMLSTYLE CMLJUST CMLSCALE) (list #nstyle (cdr (assoc 70 edo)) (cdr (assoc 40 edo))))
        (command "_.MLINE") (apply 'command vrts) (command)
        (setq edn (entget (entlast)))
        
        (entmod (foreach e (vl-remove 'nil (mapcar '(lambda (x) (assoc x edo)) '(6 8 62 39 43 48 370 71)))
                  (setq edn (if (setq a (assoc (car e) edn))
                              (subst  e
                                      a
                                      edn)
                              (append edn
                                      (list e))))))
      )
      (command "_.ERASE" ss ""))
    (cond ((not ss)
           (princ "No MLINEs selected."))
          ((not (dictsearch (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_MLINESTYLE"))) #nstyle))
           (princ (strcat #nstyle " mline style does not exists/loaded."))
           (setq #nstyle nil)))
    )
  (*error* "end")
)
Message 9 of 15

Anonymous
Not applicable

Excellent. You saved lot of manhours for us. Once again Thank you so much.

 

I wish to learn this program. Unable to understand some of functions/arguments used in the program. Especially, the functions of vla-startundomark and Wcmatch. Also, where I can get the information about assoc-1? I only know the assoc-10 and assoc-11 which is for start and end points.is it right? 

 

if this lisp is possible, I dont know  why AutoCAD not included an option to modify the  mlstyles through Ctrl+1 command. 

 

0 Likes
Message 10 of 15

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

...

I wish to learn this program. Unable to understand some of functions/arguments used in the program. Especially, the functions of vla-startundomark and Wcmatch. Also, where I can get the information about assoc-1? I only know the assoc-10 and assoc-11 which is for start and end points.is it right? 

...


>>  vla-startundomark

I don't know much about these ActiveX functions... just a few lines a commands is saw somewhere.. These two lines

 

(vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
(vla-endundomark adoc)

are marks for undo function... from start till end it's one undo step. You can use (command "_.UNDO" "_Be") and (command "_.UNDO" "_E"), but these leaves report in command line.

 

>> WCMATCH

This is function for text match. Very usefull. You can use a lot of wild-cards. See help

 

>>  (assoc -1 ed)

This is way how to get entity name from entity's definiton list. But usually you use (car (entsel)) or (ssname ss i) for the same. Compare these two lines

 

(car (entsel))
(cdr (assoc -1 (entget (car (entsel)))))

... you'll get the same - entity name.

 

>> (assoc 10 ed) (assoc 11 ed)

Just for LINE applies that 10 is start point, 11 the end. Type for "LINE dxf" in help and you'll see all codes...

But e.g. LWPOLYLINE (type name for regular polyline) has no 11 point and all verteces are 10. There is multiple 10 point in LWPOLYLINE definition. See help

And our MLINE have 10 as start point and multiple 11 as verteces. I my routine I seperated both 10 and 11, but then you reported problems with trimmed MLINEs - my solution was take just 11 points because 10 keeps always as (former) beginnig, eve it was trimmed and real beginning is somewhere else (defined by first 11 point). So...

Btw. TEXT has also 10 and 11. 10 is insertion point, 11 alignment point...

INSERT (block) 10 for insert point

CIRCLE 10 for center point

ARC 10  for center point as well. And end point are defined by angle! See... To get that is probably best use (vlax-curve-getStartPoint en) and (vlax-curve-getEndPoint en). Anyway, read about them here, because these are very simple to use and get some geometrics about curves - all, not just arc, polylines, lines, splines...

 

Hope this helps... and sorry for my english.

 

0 Likes
Message 11 of 15

braudpat
Mentor
Mentor

 

Hello from France

 

Here you will find 2 Lisp/VLisp french routines :

http://forums.autodesk.com/t5/autocad-2013-2014-2015-2016/how-to-change-a-multi-line-element-from-on...

- CMLS : Change Multi-Line Style - You already have one !

- PO2ML : Convert 2D Polyline (without Arc) to Multi-Line ...

Maybe PO2ML could help you in your day-to-day work !?

 

Regards, Patrice (I am not an Autodesk Advisor)

 

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 12 of 15

Anonymous
Not applicable

Thanks. You have explicated well.

 

One more question. What exactly the leemac program (LM:uniqueFuzz) is doing in our program. The only information I known is used for recursive.

 

 

0 Likes
Message 13 of 15

Anonymous
Not applicable

Thanks for your post Mr.braudpat.

 

I tried your lisp. It's converting the polyline in to mline. But, not properly. The converted line displays only  single line not a mluti line. I have checked the property and its showing as multi line.  Also, if i try to draw any new multi line the same problem continues.

0 Likes
Message 14 of 15

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

Thanks. You have explicated well.

 

One more question. What exactly the leemac program (LM:uniqueFuzz) is doing in our program. The only information I known is used for recursive.

 


When the routine took all 10s and 11s points, then some of those were multiple (same point as 10 and 11 as well). So Lee's sub made this list unique. But after modification for taking just 11s points, this probably could be omitted.

0 Likes
Message 15 of 15

braudpat
Mentor
Mentor

 

Hello

 

SORRY but I am using these 2 french routines since MANY years without problems !

 

Please look at this info which is into my message : 

>>> Please don't forget to adjust AFTER the MLine Scale (Property) because it is reseted to ZERO by CMLS ! <<<

>>> Please don't forget to adjust AFTER the MLine Scale (Property) because it is reseted to ZERO by PO2ML ! <<<

 

You have ONLY to change the MLine Scale Propery to a correct value : 10 / 20 / etc

 

Regards, Patrice (I am not an Autodesk/AutoCAD Forums)

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes