Results 1 to 9 of 9

Thread: mleader style switch

  1. #1
    100 Club
    Join Date
    2015-08
    Location
    birmingham, alabama
    Posts
    131
    Login to Give a bone
    0

    Default mleader style switch

    hi,
    can anyone help me make code to change the textstyle of a mleader? all i want is to change the font of existing mleaders. i'm able to manually do so thru the properties box, but i need a routine to help with the volume of swaps needed.

    thanx in advance,
    karl

  2. #2
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: mleader style switch

    Try this code , it works for texts , leader and mleaders ..

    Code:
    (defun c:Test (/ style found ss in sn)
      (vl-load-com)
      ;;; Tharwat 11. Aug. 2012 ;;;
      (if (and (setq style (lisped "Enter Text style here "))
               (setq found (tblsearch "style" style))
               (setq ss (ssget "_:L" '((0 . "*TEXT,MULTILEADER"))))
          )
        (repeat (setq in (sslength ss))
          (if
            (eq (cdr
                  (assoc 0 (entget (setq sn (ssname ss (setq in (1- in))))))
                )
                "MULTILEADER"
            )
             (vla-put-textstylename (vlax-ename->vla-object sn) style)
             (vla-put-stylename (vlax-ename->vla-object sn) style)
          )
        )
        (cond ((not found)
               (princ "\n Text style is not found in the drawing ... ")
              )
              ((not ss) (princ "\n Nothing selected ..."))
        )
      )
      (princ)
    )

  3. #3
    100 Club
    Join Date
    2015-08
    Location
    birmingham, alabama
    Posts
    131
    Login to Give a bone
    0

    Default Re: mleader style switch

    thank you Tharwat.
    i'm a newbie on Vlisp and your code was the charm.
    we're using revit for more projects, but are using acad for the details (for now). revit doesn't like the shape files of acad (romans, etc.) so we have to swap true type files for the fonts. i'm handling most other issues for automatic conversion but mleaders was a bit of a bother. thank you again for the code and may God bless your day.

    karl

  4. #4
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: mleader style switch

    You're welcome anytime Karl .

    I am really happy that my code got your acceptance .

    Tharwat

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: mleader style switch

    Tharwat -

    If you're going to iterate the entire Selection Set, and covert each EName to Vla-Object, then you might consider instead simply iterating the ActiveSelectionSet Collection Object (just be sure to use the Delete Method on that Object's variable to remove from AutoCAD's available SelectionSet Objects).

    Also, you might incorporate a StartUndoMark and EndUndoMark on the ActiveDocument Object, so the user can effectively reverse the changes made (if they so desire).

    Cheers!

  6. #6
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: mleader style switch

    Quote Originally Posted by RenderMan View Post
    Tharwat -

    If you're going to iterate the entire Selection Set, and covert each EName to Vla-Object, then you might consider instead simply iterating the ActiveSelectionSet Collection Object (just be sure to use the Delete Method on that Object's variable to remove from AutoCAD's available SelectionSet Objects).

    Also, you might incorporate a StartUndoMark and EndUndoMark on the ActiveDocument Object, so the user can effectively reverse the changes made (if they so desire).

    Cheers!
    I should agree with you since every object in the selection set must be convert it to vla-object . so here it goes with vla functions .

    Code:
    (defun c:Test (/ style found ss)
    ;;; Tharwat 12. Aug. 2012 ;;;
      (vl-load-com)
      (defun *error* (msg)
        (or	(wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
    	(princ (strcat "\n** Error: " msg " **"))
        )
        (princ)
      )
      (if (not acdoc)
        (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
      )
      (if (and (setq style (lisped "Enter Text style here "))
    	   (setq found (tblsearch "style" style))
    	   (ssget "_:L" '((0 . "*TEXT,MULTILEADER")))
          )
        (progn
          (vla-StartUndoMark acdoc)
          (vlax-for	x (setq ss (vla-get-ActiveSelectionSet acdoc))
    	(if (eq (vla-get-objectname x) "AcDbMLeader")
    	  (vla-put-textstylename x style)
    	  (vla-put-stylename x style)
    	)
          )
          (vla-delete ss)
          (vla-EndUndoMark acdoc)
        )
        (cond ((not found)
    	   (alert "*** Text style is not found in the drawing ... ***")
    	  )
    	  (t (princ "\n Nothing selected ..."))
        )
      )
      (princ)
    )

  7. #7
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: mleader style switch

    ... An alternative:

    Code:
    (vl-load-com)
    
    (defun c:STS () (c:SwitchTextStyle))
    (defun c:SwitchTextStyle (/ *error* ss style acDoc)
      (princ "\rSWITCHTEXTSTYLE ")
    
      (defun *error* (msg)
        (if (and ss (= (type ss) 'VLA_OBJECT))
          (vla-delete ss)
        )
        (if acDoc
          (vla-endundomark acDoc)
        )
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
        )
        (princ)
      )
    
      (if (and (setq ss (ssget "_:L" '((0 . "MTEXT,TEXT,MULTILEADER"))))
               (setq style (getstring T "\nEnter text style: "))
               (tblsearch "style" style)
          )
         (progn
           (vla-startundomark
             (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
           )
           (vlax-for x (setq ss (vla-get-activeselectionset acDoc))
             (vl-catch-all-apply
               (if (= "AcDbMLeader" (vla-get-objectname x))
                 'vla-put-textstylename
                 'vla-put-stylename
               )
               (list x style)
             )
           )
           (*error* nil)
         )
         (cond (style (*error* "Text style not found"))
               (ss (*error* "No text style entered"))
               ((*error* "Nothing selected"))
         )
      )
    )
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  8. #8
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: mleader style switch

    Quote Originally Posted by RenderMan View Post
    ... An alternative:
    Hi Renderman .

    Alternative means better , but i didn't see that difference

    Just as a matter of discussion and I could be wrong .

    The first use of the variable ss for the first selection set is not needed since you have already used it for the vla-activeselectionset .
    Is not it better to pull out the variable acDoc out of the main code to the top of the routine and make it global
    to avoid singing it every every time users run the code ?

    Many thanks

  9. #9
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: mleader style switch

    Quote Originally Posted by Tharwat View Post
    Alternative means better , but i didn't see that difference
    Consider the usage of the *error* function in your routine, then in mine.

    Quote Originally Posted by Tharwat View Post
    Just as a matter of discussion and I could be wrong .

    The first use of the variable ss for the first selection set is not needed since you have already used it for the vla-activeselectionset .
    This has been a topic on many occasions... Given that the 'ss' variable is used in the CONDitional 'else' expression, I stand by using this variable within the IF statement's test expression. Overwriting this variable within the 'then' expression is simply logical, and minimizes the number of variables used.

    Technically speaking, one does not need to use 'ss' prior to getting the ActiveSelectionSet Object... I simply prefer to do so as a best practice.

    Quote Originally Posted by Tharwat View Post
    Is not it better to pull out the variable acDoc out of the main code to the top of the routine and make it global
    to avoid singing it every every time users run the code ?
    I have differing views on this topic.

    For public code posted online, I am not a fan of dumping global variables in others' environments, and will intentionally add the necessary code to obtain the needed Objects instead.

    For my own personal use, I do use global variables for same. I just do not feel that it is helpful for others (especially beginners).
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Similar Threads

  1. MLEADER Text Style
    By Wish List System in forum AutoCAD Wish List
    Replies: 6
    Last Post: 2019-05-01, 04:15 PM
  2. 2014: Mleader style has changed
    By Chud in forum AutoCAD Civil 3D - General
    Replies: 3
    Last Post: 2014-09-10, 08:16 PM
  3. MLeader Style Question...
    By dsthilare in forum AutoCAD Annotation
    Replies: 1
    Last Post: 2011-05-08, 04:39 PM
  4. Import a MLeader Style?
    By darthyoga in forum AutoCAD General
    Replies: 17
    Last Post: 2008-09-19, 04:49 PM
  5. Set-up width of MText in MLeader Style
    By pbrumberg in forum AutoCAD Annotation
    Replies: 7
    Last Post: 2007-06-05, 07:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •