Jump to content

Multi-Leader Rotated to View


adrath

Recommended Posts

Hey all! I'm working on creating my own version of a LISP routine I used at a previous employer that would allow the user to place a multi-leader rotated to the current view. In my field, we use a lot a twisted views (we have a LISP routine that is basically a shortcutted version of Dview Twist that we use to set views) to make our linework fit neatly on our sheets, so this has a lot of utility for me.

 

Essentially, what I want this routine to do is:

1.Set the UCS to view

2. Invoke the MLEADER command

3. Pause while the user places the callout and

4. Set the UCS back to Previous before exiting.

 

I know next to nothing about LISP as a programming language, so I've been using MicroSoft CoPilot (and some older posts on this forum I've pulled up on Google) to try to put this code together. Here's what I have:

(defun c:MLR ()
  (command "UCS" "VIEW")  ; Set UCS to view
  (command "MLEADER")     ; Invoke Multileader command
  (while (= 1 (getvar "CMDACTIVE")) 
  (command pause))  ; Pause until the user completes the Multileader command
  (command "UCS" "P")     ; Set UCS to previous
  (princ)
)

 

This works really well, except that I can't enter contents of the multi-leader. It just always fills out a / for me and I'd have to go back and double-click and edit it. Can anyone tell me how to get it to let me fill out the text? Is it the Pause command that's causing the problem? Any help would be greatly appreciated.

 

Link to comment
Share on other sites

Just a comment we used UCS S name so would give each ucs a name, like road1, road2 etc We would make these using UCS OB selecting a object to align the UCS, then save it. UCS R is reset to a saved UCS. UCS W is to world.

 

I just did a UCS and Mleader no probs. You can set how many lines in the leader so would have a style for say 2 or 3. Then it will ask for text once correct number of points are selected.

 

image.png.b7807fc7524bdd37f3a3eaf7fd7b6a2b.png

Link to comment
Share on other sites

13 hours ago, BIGAL said:

Just a comment we used UCS S name so would give each ucs a name, like road1, road2 etc We would make these using UCS OB selecting a object to align the UCS, then save it. UCS R is reset to a saved UCS. UCS W is to world.

 

I just did a UCS and Mleader no probs. You can set how many lines in the leader so would have a style for say 2 or 3. Then it will ask for text once correct number of points are selected.

 

image.png.b7807fc7524bdd37f3a3eaf7fd7b6a2b.png

If I understand you correctly, I need to add a Command Pause for each different click. Our leaders are set to have a max number of 2 points, so there should be 3 total pauses, one for each click and then one for text entry. I tried that, and this is what happened in the command line:image.thumb.png.f33587efc2878e510efe9282504ab387.png

 

For some reason, under text it's just putting a "\" and I never even get the option to enter the text editor. Everything else works, I just have to hit enter after placing the leader to reset the UCS. But I can't for the life of me figure out where the "\" in the multileader text is coming from. Here's the code after I added pauses:

 

(defun c:MLR ()
  (command "UCS" "VIEW")  ; Set UCS to view
  (command "MLEADER")     ; Invoke Multileader command
  (while (= 1 (getvar "CMDACTIVE")) 
  (command pause)
  (command pause)
  (command pause))  ; Pause until the user completes the Multileader command
  (command "UCS" "P")     ; Set UCS to previous
  (princ)
)

 

Link to comment
Share on other sites

Maybe something like this.

 

; single line leader using standard
(defun c:mlr2 ( / )
  (setvar 'CMLEADERSTYLE  "Standard") 
  (command "VIEW" "R" "View")
  (command "mleader" pause pause pause)
  (command "Ucs" "W" "PLAN" "")
)

 

Link to comment
Share on other sites

On 10/29/2024 at 5:16 PM, BIGAL said:

Maybe something like this.

 

; single line leader using standard
(defun c:mlr2 ( / )
  (setvar 'CMLEADERSTYLE  "Standard") 
  (command "VIEW" "R" "View")
  (command "mleader" pause pause pause)
  (command "Ucs" "W" "PLAN" "")
)

 

That works perfectly, except that it still doesn't enter the text editor it just places a /. I've tried to change the invoke leader line to "MLEADER" "T" to force it to place the text first but it just freezes my CAD when I do that. I wonder if my company has a system variable set that is screwing with how the multi-leaders work.

Link to comment
Share on other sites

On 10/31/2024 at 11:22 AM, adrath said:

That works perfectly, except that it still doesn't enter the text editor it just places a /. I've tried to change the invoke leader line to "MLEADER" "T" to force it to place the text first but it just freezes my CAD when I do that. I wonder if my company has a system variable set that is screwing with how the multi-leaders work.

 

@adrath

Unfortunately, the MLEADER text editor doesn't work within the (command) function. The only way I know to do it is to emulate the MLEADER prompts and then run the command after. Try this code:

;; Written by PKenewell - 11/1/2024
(defun c:mlr (/ *error* an ar oec p p1 p2 p3 p4 pt pts s sl)
   
   (defun *error* (msg)
      (if (not (wcmatch (strcase msg T) "*break*,*cancel*,*quit*,*exit*"))
   	  (princ (strcat "\nError: " msg "\n"))
        (princ "\nProgram Aborted.\n")
      )
      (command-s)
      (command-s "._ucs" "_p")
      (command-s "._undo" "_End")
      (if oec (setvar "cmdecho" oec))
   )
   
   (setq oec (getvar "cmdecho"))
   (setvar "cmdecho" 0)
   (command "._undo" "_be") 
   (command "._ucs" "_view")
   (if 
      (and
         (setq p1 (getpoint "\nSelect start point of MLEADER: "))
         (setq p2 (getpoint p1 "\nSelect next point of MLEADER: "))
      )
      (progn
         (setq ar (* (getvar "dimscale") (getvar "dimasz"))
               an (angle p1 p2)
               p  (polar p1 an ar)
               p3 (polar p (+ (/ pi 2)   an) (/ ar 6))
               p4 (polar p (+ (* pi 1.5) an) (/ ar 6))
         )
         (grdraw p1 p2 -1)
         (grdraw p1 p3 -1)
         (grdraw p1 p4 -1)
         (grdraw p3 p4 -1)
         (setq pts (list p1 p2))
         (while (setq pt (getpoint (last pts) "\nSelect next point of MLEADER: "))
            (grdraw (last pts) pt -1)
            (setq pts (append pts (list pt)))
         )
         (while (/= "" (setq s (getstring t "\nEnter Text: ")))
            (setq sl (append sl (list s)))
         )
         (command "._mleader")
         (foreach p pts (command p))
         (command "")
         (if sl
            (progn
               (setq sl (apply 'strcat (cons (car sl)(mapcar '(lambda (x) (strcat "\\P" x)) (cdr sl)))))
               (command sl)
            )
            (command)
         )
         (redraw)    
      )
   )
   (command "._ucs" "_p")
   (command "._undo" "_End")
   (setvar "cmdecho" oec)
   (princ)
)

 

EDIT: Added an error handler and added a couple variables for grdraw points to make it easier to follow.

Edited by pkenewell
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...