Jump to content

leader to mleader routine changes??


Rsblades

Recommended Posts

ok, problem is this.. i have the routine for switching text/leader combos to mleaders however, i want to revise that to so it comes in right side up in a twisted view. heres the code:

 

(defun c:l2m ()
 (setq leader (entsel "\nPick Leader")
leader2 (entget (car leader))
pt1 (dxf 10 leader2)
layer  (dxf 8 leader2)
mtext (entsel "\nPick Text")
mtext2 (entget (car mtext))
pt2 (dxf 10 mtext2)
text (dxf 1 mtext2)
 )
 
 (command "-layer" "s" layer "")
 (command "mleader" pt1 pt2 text)
 (COMMAND "ERASE" mtext "")
 (command "erase" leader "")
)
(defun dxf(code elist) 
 (cdr (assoc code elist))
)

 

i previously created a routine that rotates the mleader to match the view in a twisted view drawing and sets the mleader style (let me remind you im pretty new at this so this routine is very basic):

 

(defun c:MLST ()(command "cmleaderstyle""stnd")
                 (command "ucs""v")
                 (initcommandversion 2)
                 (command "mleader" pause pause)
                 (command "ucs""w")
                 (prin1))

 

now i want to somehow combine the two so it changes leader/text combos to mleaders with the correct angle in a twisted drawing.. heres what i tried to come up with but it doesnt work properly for me when i run it:

 

(defun c:l2m ()
 (setq leader (entsel "\nPick Leader")
leader2 (entget (car leader))
pt1 (dxf 10 leader2)
layer  (dxf 8 leader2)
mtext (entsel "\nPick Text")
mtext2 (entget (car mtext))
pt2 (dxf 10 mtext2)
text (dxf 1 mtext2)
 )
 
 (command "-layer" "s" layer "")
  (command "cmleaderstyle""stnd");standard mleader
  (initcommandversion 2)
  (command "ucs""v")
  (command "mleader" pt1 pt2 text)
  (command "ucs""w")
 (COMMAND "ERASE" mtext "")
 (command "erase" leader "")
)
(defun dxf(code elist) 
 (cdr (assoc code elist))
)

 

when it goes to select the second point in the mleader the routine stops and does not use the set pt2 nor does it insert the text. on top of that it starts the mleader way off in space (something to do with setting the ucs after the pts have been set? idk) can someone give me an idea as to what i need to change or add or if its even possible to make this work?

Link to comment
Share on other sites

you just needed to translate your points back to world UCS

replace with this:

(command "mleader" (trans pt1 0 1) (trans pt2 0 1) text)

oh, make sure to ALWAYS localize your variables.

 

(defun c:l2m ( / leader leader2 ...and so on)

Link to comment
Share on other sites

here, i got a little carried away and thought i'd give a little help since you're new and actually trying to write your routines.

i tried to keep it as close to the way you wrote it (for easier processing), but i went through it step by step. since i wrote it from scratch, i used my style formatting for naming my variables (just to keep my head on straight, your variables were fine). i didn't introduce an error handler (trying to keep it as simple as possible), but if it were me, i'd add one.

 

(defun c:TEST (/            dxf          #OldCmdecho  #OldLayer
              #Leader      #LeaderEnt   #Mtext       #MtextEnt
              #Layer       #LeaderIns   #MtextIns    #MtextString
             )

 (defun dxf (code elist)
   (cdr (assoc code elist))
 ) ;_ defun

 ;; store cmdecho setting
 (setq #OldCmdecho (getvar "cmdecho")
       ;; store current layer
       #OldLayer   (getvar "clayer")
 ) ;_ setq

 ;; select leader & text object with a little error trapping
 ;; this way, the program won't continue if all required variables haven't been filled
 (if (and (setq #Leader (car (entsel "\nSelect leader: ")))
          ;; check to make "LEADER" selected and entget the selected leader
          (eq "LEADER" (dxf 0 (setq #LeaderEnt (entget #Leader))))
          ;; select mtext
          (setq #Mtext (car (entsel "\nSelect MText: ")))
          ;; check to make sure "MTEXT" selected and entget the selected mtext
          (eq "MTEXT" (dxf 0 (setq #MtextEnt (entget #Mtext))))
     ) ;_ and
   (progn
     ;; set cmdecho to 0, so 'command' execution is hidden
     (setvar "cmdecho" 0)
     ;; leader layer
     (setq #Layer       (dxf 8 #LeaderEnt)
           ;; insertion of leader
           #LeaderIns   (dxf 10 #LeaderEnt)
           ;; insertion of mtext
           #MtextIns    (dxf 10 #MtextEnt)
           ;; text inside mtext
           #MtextString (dxf 1 #MtextEnt)
     ) ;_ setq
     ;; set ucs to view
     (command "_.ucs" "_view")
     ;; set current layer to match selected leader
     (setvar "clayer" #Layer)
     ;; create mleader object (the "_non" are osnap overrides to ignore running osnaps)
     ;; the trans will translate the points to world ucs to ensure the mleader is drawn at same two points
     (command "_.mleader" "_non" (trans #LeaderIns 0 1) "_non" (trans #MtextIns 0 1) #MtextString)
     ;; delete leader & mtext
     (entdel #Leader)
     (entdel #Mtext)
     ;; reset ucs to previous
     (command "_.ucs" "_previous")
     ;; reset current layer
     (and #OldLayer (setvar "clayer" #OldLayer))
     ;; reset cmdecho
     (and #OldCmdecho (setvar "cmdecho" #OldCmdecho))
   ) ;_ progn
 ) ;_ if
 ;; exit quietly
 (princ)
) ;_ defun

i forgot to add the coding to set the current mleader style, but you can easily do that. btw, you can use (setvar "cmleaderstyle" "stnd") also. no need to use command.

 

hope this helps :)

Link to comment
Share on other sites

here, i got a little carried away and thought i'd give a little help since you're new and actually trying to write your routines.

i tried to keep it as close to the way you wrote it (for easier processing), but i went through it step by step. since i wrote it from scratch, i used my style formatting for naming my variables (just to keep my head on straight, your variables were fine). i didn't introduce an error handler (trying to keep it as simple as possible), but if it were me, i'd add one.

 

(defun c:TEST (/            dxf          #OldCmdecho  #OldLayer
              #Leader      #LeaderEnt   #Mtext       #MtextEnt
              #Layer       #LeaderIns   #MtextIns    #MtextString
             )

 (defun dxf (code elist)
   (cdr (assoc code elist))
 ) ;_ defun

 ;; store cmdecho setting
 (setq #OldCmdecho (getvar "cmdecho")
       ;; store current layer
       #OldLayer   (getvar "clayer")
 ) ;_ setq

 ;; select leader & text object with a little error trapping
 ;; this way, the program won't continue if all required variables haven't been filled
 (if (and (setq #Leader (car (entsel "\nSelect leader: ")))
          ;; check to make "LEADER" selected and entget the selected leader
          (eq "LEADER" (dxf 0 (setq #LeaderEnt (entget #Leader))))
          ;; select mtext
          (setq #Mtext (car (entsel "\nSelect MText: ")))
          ;; check to make sure "MTEXT" selected and entget the selected mtext
          (eq "MTEXT" (dxf 0 (setq #MtextEnt (entget #Mtext))))
     ) ;_ and
   (progn
     ;; set cmdecho to 0, so 'command' execution is hidden
     (setvar "cmdecho" 0)
     ;; leader layer
     (setq #Layer       (dxf 8 #LeaderEnt)
           ;; insertion of leader
           #LeaderIns   (dxf 10 #LeaderEnt)
           ;; insertion of mtext
           #MtextIns    (dxf 10 #MtextEnt)
           ;; text inside mtext
           #MtextString (dxf 1 #MtextEnt)
     ) ;_ setq
     ;; set ucs to view
     (command "_.ucs" "_view")
     ;; set current layer to match selected leader
     (setvar "clayer" #Layer)
     ;; create mleader object (the "_non" are osnap overrides to ignore running osnaps)
     ;; the trans will translate the points to world ucs to ensure the mleader is drawn at same two points
     (command "_.mleader" "_non" (trans #LeaderIns 0 1) "_non" (trans #MtextIns 0 1) #MtextString)
     ;; delete leader & mtext
     (entdel #Leader)
     (entdel #Mtext)
     ;; reset ucs to previous
     (command "_.ucs" "_previous")
     ;; reset current layer
     (and #OldLayer (setvar "clayer" #OldLayer))
     ;; reset cmdecho
     (and #OldCmdecho (setvar "cmdecho" #OldCmdecho))
   ) ;_ progn
 ) ;_ if
 ;; exit quietly
 (princ)
) ;_ defun

i forgot to add the coding to set the current mleader style, but you can easily do that. btw, you can use (setvar "cmleaderstyle" "stnd") also. no need to use command.

 

hope this helps :)

 

Wow that works Awesome :D thank you for your help really! Now, with mleaders they also have the option to use a block instead of text (like a construction note with a circle around a letter/number). would there be a way to allow the use to select a leader/attribute combo and make it to the mleader that uses the block? thats way over my head as to if that can be done or not ha. If not, then thank you for the help and if so could ya help me out? unless it would take to much time to write it then dont worry bout it haha.

Anyways, thanks again,

 

Ryan

Link to comment
Share on other sites

Wow that works Awesome :D thank you for your help really! Now, with mleaders they also have the option to use a block instead of text (like a construction note with a circle around a letter/number). would there be a way to allow the use to select a leader/attribute combo and make it to the mleader that uses the block? thats way over my head as to if that can be done or not ha. If not, then thank you for the help and if so could ya help me out? unless it would take to much time to write it then dont worry bout it haha.

Anyways, thanks again,

 

Ryan

a little more legwork, but feasible (as long as the block isn't annotative).

you'd just select the leader and instead of text, select the attributed block, extract all attribute data, then insert your mleader, filling in attribute data.

 

i might can scratch something out when i get home tonight.

Link to comment
Share on other sites

  • 9 months later...
here, i got a little carried away and thought i'd give a little help since you're new and actually trying to write your routines.

i tried to keep it as close to the way you wrote it (for easier processing), but i went through it step by step. since i wrote it from scratch, i used my style formatting for naming my variables (just to keep my head on straight, your variables were fine). i didn't introduce an error handler (trying to keep it as simple as possible), but if it were me, i'd add one.

 

(defun c:TEST (/            dxf          #OldCmdecho  #OldLayer
              #Leader      #LeaderEnt   #Mtext       #MtextEnt
              #Layer       #LeaderIns   #MtextIns    #MtextString
             )

 (defun dxf (code elist)
   (cdr (assoc code elist))
 ) ;_ defun

 ;; store cmdecho setting
 (setq #OldCmdecho (getvar "cmdecho")
       ;; store current layer
       #OldLayer   (getvar "clayer")
 ) ;_ setq

 ;; select leader & text object with a little error trapping
 ;; this way, the program won't continue if all required variables haven't been filled
 (if (and (setq #Leader (car (entsel "\nSelect leader: ")))
          ;; check to make "LEADER" selected and entget the selected leader
          (eq "LEADER" (dxf 0 (setq #LeaderEnt (entget #Leader))))
          ;; select mtext
          (setq #Mtext (car (entsel "\nSelect MText: ")))
          ;; check to make sure "MTEXT" selected and entget the selected mtext
          (eq "MTEXT" (dxf 0 (setq #MtextEnt (entget #Mtext))))
     ) ;_ and
   (progn
     ;; set cmdecho to 0, so 'command' execution is hidden
     (setvar "cmdecho" 0)
     ;; leader layer
     (setq #Layer       (dxf 8 #LeaderEnt)
           ;; insertion of leader
           #LeaderIns   (dxf 10 #LeaderEnt)
           ;; insertion of mtext
           #MtextIns    (dxf 10 #MtextEnt)
           ;; text inside mtext
           #MtextString (dxf 1 #MtextEnt)
     ) ;_ setq
     ;; set ucs to view
     (command "_.ucs" "_view")
     ;; set current layer to match selected leader
     (setvar "clayer" #Layer)
     ;; create mleader object (the "_non" are osnap overrides to ignore running osnaps)
     ;; the trans will translate the points to world ucs to ensure the mleader is drawn at same two points
     (command "_.mleader" "_non" (trans #LeaderIns 0 1) "_non" (trans #MtextIns 0 1) #MtextString)
     ;; delete leader & mtext
     (entdel #Leader)
     (entdel #Mtext)
     ;; reset ucs to previous
     (command "_.ucs" "_previous")
     ;; reset current layer
     (and #OldLayer (setvar "clayer" #OldLayer))
     ;; reset cmdecho
     (and #OldCmdecho (setvar "cmdecho" #OldCmdecho))
   ) ;_ progn
 ) ;_ if
 ;; exit quietly
 (princ)
) ;_ defun

i forgot to add the coding to set the current mleader style, but you can easily do that. btw, you can use (setvar "cmleaderstyle" "stnd") also. no need to use command.

 

hope this helps :)

 

Alan, Great code - works a treat. Much better than past solutions I have seen. Thank You!!

Link to comment
Share on other sites

I will, thanks.

 

I love digging up old gems :)

Me too.

 

Wow, in fact, I already had that one and couldn't find it...:oops:

HaHa, I've done that before.:lol:

Link to comment
Share on other sites

  • 11 months later...

I am looking for a routine to change the rotation of selected MLeaders to the current Dview twist.

 

Thanks in advance

Jim (Seattle):unsure:

Link to comment
Share on other sites

I am looking for a routine to change the rotation of selected MLeaders to the current Dview twist.

 

Thanks in advance

Jim (Seattle):unsure:

http://www.cadtutor.net/forum/showthread.php?41290-ZeroRotation.lsp-Set-rotation-of-objects-to-zero-%28based-on-current-UCS%29

 

BTW, since this request doesn't really fit with the thread, you should start your own.

Link to comment
Share on other sites

  • 6 months later...

It seems like this Leader to MLeader thing is a never ending task. I like this one more than the one I put together from various sources, mainly because I couldn't get "TRANS" to work. One thing I had added to mine was to set the text width. I actually used code straight from a post by Alan, so all the credit goes to him. Here it is if anyone else wants it:

(defun c:ltm2 (/            dxf          #OldCmdecho  #OldLayer
              #Leader      #LeaderEnt   #Mtext       #MtextEnt
              #Layer       #LeaderIns   #MtextIns    #MtextString
             )

 (vl-load-com)
 (defun dxf (code elist)
   (cdr (assoc code elist))
 ) ;_ defun

 ;; store cmdecho setting
 (setq #OldCmdecho (getvar "cmdecho")
       ;; store current layer
       #OldLayer   (getvar "clayer")
 ) ;_ setq

 ;; select leader & text object with a little error trapping
 ;; this way, the program won't continue if all required variables haven't been filled
 (if (and (setq #Leader (car (entsel "\nSelect leader: ")))
          ;; check to make "LEADER" selected and entget the selected leader
          (eq "LEADER" (dxf 0 (setq #LeaderEnt (entget #Leader))))
          ;; select mtext
          (setq #Mtext (car (entsel "\nSelect MText: ")))
          ;; check to make sure "MTEXT" selected and entget the selected mtext
          (eq "MTEXT" (dxf 0 (setq #MtextEnt (entget #Mtext))))
     ) ;_ and
   (progn
     ;; set cmdecho to 0, so 'command' execution is hidden
     (setvar "cmdecho" 0)
     ;; leader layer
     (setq #Layer       (dxf 8 #LeaderEnt)
           ;; insertion of leader
           #LeaderIns   (dxf 10 #LeaderEnt)
           ;; insertion of mtext
           #MtextIns    (dxf 10 #MtextEnt)
           ;; text inside mtext
           #MtextString (dxf 1 #MtextEnt)
           ;; width of text
           width        (dxf 41 #MtextEnt)
     ) ;_ setq
     ;; set ucs to view
     (command "_.ucs" "_view")
     ;; set current layer to match selected leader
     (setvar "clayer" #Layer)
     ;; create mleader object (the "_non" are osnap overrides to ignore running osnaps)
     ;; the trans will translate the points to world ucs to ensure the mleader is drawn at same two points
     (command "_.mleader" "_non" (trans #LeaderIns 0 1) "_non" (trans #MtextIns 0 1) #MtextString)

;;Following coding to set width from Alan J. Thompson, 11.05.09 modified by Matt Kearney
(if (and (setq ss (ssget "L" '((0 . "MTEXT,MULTILEADER"))))
(setq wd (initget 4)
wd (cond (width)
(0.)
)
)
)
(progn
(vlax-for x (setq ss (vla-get-activeselectionset
(cond (*AcadDoc*)
((setq *AcadDoc* (vla-get-activedocument
(vlax-get-acad-object)
)
)
)
)
)
)
(vl-catch-all-apply
(function vlax-put-property)
(list x
(cond ((eq (vla-get-objectname x) "AcDbMText") 'Width)
((eq (vla-get-objectname x) "AcDbMLeader") 'TextWidth)
)
wd
)
)
)
(vla-delete ss)
)
)

     ;; delete leader & mtext
     (entdel #Leader)
     (entdel #Mtext)
     ;; reset ucs to previous
     (command "_.ucs" "_previous")
     ;; reset current layer
     (and #OldLayer (setvar "clayer" #OldLayer))
     ;; reset cmdecho
     (and #OldCmdecho (setvar "cmdecho" #OldCmdecho))
   ) ;_ progn
 ) ;_ if
 ;; exit quietly
 (princ)
) ;_ defun

 

Enjoy.

Link to comment
Share on other sites

  • 3 years later...

I do not know why, but if the mtext contains an "enter", it eliminates almost all of the text. entsel/enget returns: (3 . "\\A1;FASTEN OUTER PLY OF 2-PLY SIDEWALL THRUST BEAM TO INNER PLY USING {\\H0.7x;\\S1/2;} QTY REQUIRED AT THE END OF THE BEAM USE ({\\C1;3}) ROWS OF 0.131\"x3\" NAILS @ 2\" O.C. MIN SPACING THRU SIDEWALL THRUST BEAM TO ENDWALL THRUST BEAM QTY PER CALCS MANUA") (1 . "L SECTION {\\C1;12} PG {\\C1;?} \\P{\\A0; }")

 

when it creates the mleader, the only text i get from above is "L SECTION 12 PG ?" attached to the leader.

 

Any help with this?

Link to comment
Share on other sites

The issue isn't the carriage return, it's that the text is longer than 250 characters. I'm a bit swamped right now to update this, but the fix would be to have the LISP look for the DXF 3 and if it's found, combine the text from any of those with the DXF 1 and then write that as the new text.

 

Sorry I cannot help more right now, but hopefully this helps you or someone else update the command.

 

Temporary fix, find and replace a common text string to shorten the mtext and then replace it with the original text after the mleader is created.

Link to comment
Share on other sites

God that code is UGLY!

 

Replace:

(dxf 1 #MtextEnt)

 

with:

(apply 'strcat
      (mapcar (function (lambda (x)
                          (if (member (car x) '(1 3))
                            (cdr x)
                            ""
                          )
                        )
              )
              #MtextEnt
      )
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...