Jump to content

MLeader LSP not working


ryankevin15

Recommended Posts

Hello,

 

My manager made this LSP file for me and it doesn't work and we are both not sure why. Seems correct to me.

 

How it works: Creates the E-Anno-Note layer, otherwise makes it current, then creates an MLeader (to avoid creating leaders on incorrect layers).

 

(DEFUN C:NN ()
 (setvar "cmdecho" 0)
 (if (not (tblsearch "layer" "E-Anno-Note"))
   (command "-layer" "n" "E-Anno-Note" "c" "2" "E-Anno-Note" ""))
 (command "-layer" "m" "E-Anno-Note")
 (COMMAND "mleader")
 (princ)
 )

 

Thanks!

Link to comment
Share on other sites

Hi,

Need to add double quotes.

(command "-layer" "m" "E-Anno-Note" [color="magenta"][b]""[/b][/color])

 


(DEFUN C:mm ()
 (setvar "cmdecho" 0)
 (if (not (tblsearch "layer" "E-Anno-Note"))
   (command "-layer" "n" "E-Anno-Note" "c" "2" "E-Anno-Note" ""))
 command "-layer" "m" "E-Anno-Note" "")
 (COMMAND "mleader" "")
 (princ)
 )

 

Still doesn't work when I run this...

Link to comment
Share on other sites

The -layer N is new, M is make new and make current, so does two steps.

 

So a slight variation

(if (not (tblsearch "layer" "E-Anno-Note"))
   (command "-layer" "m" "E-Anno-Note" "c" "2" "E-Anno-Note" "")
   (command "-layer" "s" "E-Anno-Note" "")
)

 

also

(if (not (tblsearch "layer" "E-Anno-Note"))
   (command "-layer" "m" "E-Anno-Note" "c" "2" "E-Anno-Note" ""))
   (setvar 'clayer "E-Anno-Note")
)

Link to comment
Share on other sites

Thanks for the help. This works now.

 

Could I make it also adjust the settings of the MLeader before it is drawn so that it will make the right alignment in the middle of the bottom row of text (this is a standard CAD thing that doesn't seem to be the default).

 

Thanks in advance.

Link to comment
Share on other sites

Thanks for the help. This works now.

 

Could I make it also adjust the settings of the MLeader before it is drawn so that it will make the right alignment in the middle of the bottom row of text (this is a standard CAD thing that doesn't seem to be the default).

 

Thanks in advance.

You could add something like this to the code:

(if (setq e (dictsearch (namedobjdict) "ACAD_MLEADERSTYLE"))
 (progn (setq o (vlax-ename->vla-object
	   (cdr (assoc -1 (dictsearch (cdr (assoc -1 e)) (getvar 'cmleaderstyle))))
	 )
 )
 (vla-put-textleftattachmenttype o 5)
 (vla-put-textrightattachmenttype o 5)
 )
)

Link to comment
Share on other sites

Anyone know of any way I can import an MLeader style right before it starts drawing the MLeader?

 

Make a template and insert it if the mleaderstyle does not exist.

Link to comment
Share on other sites

You could add something like this to the code:

(if (setq e (dictsearch (namedobjdict) "ACAD_MLEADERSTYLE"))
 (progn (setq o (vlax-ename->vla-object
	   (cdr (assoc -1 (dictsearch (cdr (assoc -1 e)) (getvar 'cmleaderstyle))))
	 )
 )
 (vla-put-textleftattachmenttype o 5)
 (vla-put-textrightattachmenttype o 5)
 )
)

 

I will try this with my manager and see if it works. Thanks!

Link to comment
Share on other sites

I was able to adjust the leader in the style, but will this code locate the style on my computer or how does that work?

 

It just changes the current mleader style ( which might actually be bad practice ) ... I would check if the style exists and set it current, else import ( or create with code ) and set current.

Link to comment
Share on other sites

Here is my updated code. Can anyone add some code so that it will import the MLeaderStyle before making the MLeader? Our style is called "Ascent"

 


(DEFUN C:mm ()
 (setvar "cmdecho" 0)
 (if (not (tblsearch "layer" "E-Anno-Note"))
   (command "-layer" "n" "E-Anno-Note" "c" "2" "E-Anno-Note" ""))
 (command "-layer" "m" "E-Anno-Note" "")
 (command "-layer" "c" "2" "E-Anno-Note" "")
 (command "-layer" "ps" "style_1" "E-Anno-Note" "")
 (COMMAND "mleader")
 (princ)
 )


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...