Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
New Member
parker.depriest
Posts: 1
Registered: ‎12-11-2012
Message 1 of 3 (703 Views)

Set MLeader to Existing MLeader Style via LISP

703 Views, 2 Replies
12-11-2012 11:38 AM

Hello,

 

I am trying to create a lisp routine that sets all existing MLEADERs to a certain pre-set MLEADERSTYLE, the equivalent of doing a Quick Select for Mleaders, and setting the style under the properties window.

 

I was able to write a similar routine that selects all dimensions and sets them to a certain DIMSTYLE, using entmod and DXF code 3 for dimstyle.  So far, I have not been able to find a group code for MLEADERSTYLE 

 

 Any help would be greatly appreciated!

 

 

 

(defun C:dimstylechange (/ ENTITIES NO_OF_ENTITIES SSPOSITION ENTITY_NAME
OLD_ENTLIST NEW_STYLE NEW_ENTLIST)

(setvar "CMDECHO" 0)

(setq ENTITIES (ssget "X" '((0 . "DIMENSION"))))

(setq NO_OF_ENTITIES (sslength ENTITIES))

(setq SSPOSITION 0)

(repeat NO_OF_ENTITIES

;***CHANGE STYLE***
(setq ENTITY_NAME (ssname ENTITIES SSPOSITION))
(setq OLD_ENTLIST (entget ENTITY_NAME))
(setq OLD_STYLE (assoc 3 OLD_ENTLIST))
(setq NEW_STYLE (cons 3 "BCR 11x17"))
(setq NEW_ENTLIST (subst NEW_STYLE OLD_STYLE OLD_ENTLIST))

(entmod NEW_ENTLIST)


;***CHANGE LAYER***
(setq OLD_ENTLIST (entget ENTITY_NAME))
(setq OLD_STYLE (assoc 8 OLD_ENTLIST))
(setq NEW_STYLE (cons 8 "DIM"))
(setq NEW_ENTLIST (subst NEW_STYLE OLD_STYLE OLD_ENTLIST))

(entmod NEW_ENTLIST)

(setq SSPOSITION (1+ SSPOSITION))
)

 

(command ".CHPROP" ENTITIES "" "C" "BYLAYER" "LT" "BYLAYER" "")

(princ (strcat "\n..." (rtos NO_OF_ENTITIES 2 0) " Dimension(s) changed..."))

(setvar "CMDECHO" 1)

(princ)

)

*Expert Elite*
Kent1Cooper
Posts: 5,871
Registered: ‎09-13-2004
Message 2 of 3 (683 Views)

Re: Set MLeader to Existing MLeader Style via LISP

12-11-2012 01:09 PM in reply to: parker.depriest

parker.depriest wrote:

....  So far, I have not been able to find a group code for MLEADERSTYLE 

....


I don't have MLeaders [too old a version of AutoCAD], but I wonder whether that might be available with a little less work as a VLA Property.  Try drawing an MLeader [so it's the last thing in the drawing], then doing:

 

(vlax-dump-object (vlax-ename->vla-object (entlast)))

 

and see whether any of the listed Properties contains the current style.  [For Text and Mtext and Dimensions, the Property is called "StyleName", and it could very well be the same for MLeaders.]  If it does, you can use a (vla-put...) operation on a vla-object conversion of each MLeader found, instead of the whole (entget)/(subst)/(entmod) procedure.

Kent Cooper
Mentor
phanaem
Posts: 153
Registered: ‎02-06-2007
Message 3 of 3 (675 Views)

Re: Set MLeader to Existing MLeader Style via LISP

12-11-2012 02:29 PM in reply to: parker.depriest

How often do you need to do that? Maybe a Quick Select and change style in properties dialog is enough.

But if you have some reasons to use lisp, try this:

(defun C:TEST ( / *error* acDoc l new e ss)
  (setq acDoc (vla-get-activeDocument (vlax-get-acad-object)))
  (vla-StartUndoMark acDoc)
  
  (defun *error* (msg)
    (princ msg)
    (vla-EndUndoMark acDoc)
    )
  
  (if
    (ssget "_X" '((0 . "MULTILEADER")))
     (progn
       (princ "\n\n\n****Mleader Styles****\n\n")
       (setq l (mapcar
                 (function
                   (lambda (s)
                     (princ (strcat "   " (cdr s) "\n"))
                     (cdr s)
                   )
                 )
                 (vl-remove-if
                   '(lambda (x) (/= (car x) 3))
                   (dictsearch (namedobjdict) "ACAD_MLEADERSTYLE")
                 )
               )
       )
       (textscr)
       (if
         (member (setq new (getstring T "\nEnter new style name: ")) l)
          (progn
            (vlax-for e (setq ss (vla-get-ActiveSelectionSet acDoc))
              (vla-put-StyleName e new)
            )
            (vla-delete ss)
          )
          (princ "\nStayle name not found.")
       )
       (graphscr)
     )
  )
  (princ)
)
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.