Jump to content
ryankevin15

MLeader LSP not working

Recommended Posts

ryankevin15

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!

Share this post


Link to post
Share on other sites
Tharwat

Hi,

Need to add double quotes.

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

Share this post


Link to post
Share on other sites
ryankevin15
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...

Share this post


Link to post
Share on other sites
Tharwat

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

 

You have omitted one bracket before the command call.

Share this post


Link to post
Share on other sites
BIGAL

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")
)

Share this post


Link to post
Share on other sites
ryankevin15

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.

Share this post


Link to post
Share on other sites
ronjonp
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)
 )
)

Share this post


Link to post
Share on other sites
ryankevin15

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

Share this post


Link to post
Share on other sites
ronjonp
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.

Share this post


Link to post
Share on other sites
ryankevin15
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!

Share this post


Link to post
Share on other sites
ryankevin15

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?

Share this post


Link to post
Share on other sites
ronjonp
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.

Share this post


Link to post
Share on other sites
ryankevin15

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


Share this post


Link to post
Share on other sites
ryankevin15

Actually, it looks like we need to create this MLeader style every time and set it to current if it doesn't exist...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×