Author Topic: Insert block with mleader lisp help RE: What is wrong?  (Read 6414 times)

0 Members and 1 Guest are viewing this topic.

CECE_CAD

  • Guest
Insert block with mleader lisp help RE: What is wrong?
« on: May 05, 2008, 03:25:14 PM »
I’m trying to insert a block at the end of a leader instead of using text.  I found this code and have been trying to use it, but I’m not sure if I follow it because of the (error handler).  Could someone please take a look at this and help me fix it?

Code: [Select]

(DEFUN C:fred () ; Leader w Epuip Tag
(error-handler) ; <--------------------------- inserted here          (Do I need to insert this? Can this be taken out and still work?)
(vl-cmdf "_insert" "K:/settings/AnnoDims.dwg" "0,0" "" "" "")
(vl-cmdf "._cmleaderstyle" "Anno Leader")
(vl-cmdf "._mleader")
(while (= (getvar "CMDACTIVE") 1) (command PAUSE))
(setq obj (vlax-ename->vla-object (entlast)))
(vla-put-blockconnectiontype obj acConnectBase)
)

(defun error-handler () ; handle recoverable error here                   (Again, I'm not sure what to put)
(command "._insert" "K:/settings/CECEAnnoDims")(command)
(command "._insert" "K:/menu/notes/Equip-tag.dwg")(command) 
)

(while
(vl-catch-all-error-p
(vl-catch-all-apply 'main-content nil)
)
(error-handler)
)
)

« Last Edit: May 08, 2008, 04:53:33 PM by CECE_CAD »

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Insert block with leader lisp help
« Reply #1 on: May 05, 2008, 04:47:33 PM »
Code: [Select]
(DEFUN C:fred () ; Leader w Epuip Tag
(setq BNAME "K:/settings/AnnoDims.dwg") ;<--- Change this line to whatever block you wold like to use.
(vl-cmdf "._-insert" BNAME "0,0" "" "" "")
(vl-cmdf "._erase" (entlast) "")
(vl-cmdf "._cmleaderstyle" "Anno Leader")
(vl-cmdf "._mleader" "Options" "C" "Block" BNAME)
)

This is as simplistic as it can get, I actually use a bit more complicated routine that sets the style based on pick points and the block based on user input, but this should work without any problems.



CECE_CAD

  • Guest
Re: Insert block with leader lisp help
« Reply #2 on: May 05, 2008, 05:24:09 PM »
Well, what I’m trying to do is set the anno leader style I want by first inserting the styles (annodims.dwg) then setting (anno leader).  Then have the block (Equip-Tag) attached to the leader.  Maybe using your lisp would work good.. The code comes up as unknown.  I took your code an added in:

Code: [Select]
(DEFUN C:fred () ; Leader w Epuip Tag
(vl-cmdf "_insert" "K:/settings/AnnoDims.dwg" "0,0" "" "" "")         <-----  Anno leader and dim styles
(setq BNAME "Equip-tag") ;<--- I changed this to my block.
(vl-cmdf "._-insert" "K:/menu/notes/Equip-tag.dwg)  <----- I took out ("0,0" "" "" "")
(vl-cmdf "._erase" (entlast) "")
(vl-cmdf "._cmleaderstyle" "Anno Leader")   <--------- Style Name
(vl-cmdf "._mleader" "Options" "C" "Block" "Equip-tag")

CECE_CAD

  • Guest
Re: Insert block with leader lisp help
« Reply #3 on: May 06, 2008, 07:16:49 AM »
Ok, so the block that i'm trying to insert has an attribute so I added in (attreq) and turned it off.  Just the last step keeps going in circles..  What I mean is the command keeps cycling between "Block" and "Content type".    The block gets inserted into the drawing so its there, its just not picking it up during the last command..  Any suggestions?


Code: [Select]
(DEFUN C:mech () ; Mleader with Loop
 (command "._insert" "K:/settings/AnnoDims.dwg" "0,0" "" "" "")
 (setq BNAME "Equip-tag")
 (command "attreq" "0" "")
 (command "._insert" "K:/menu/notes/Equip-tag.dwg" "0,0" "" "" "" "")
 (command "._erase" (entlast) "")
 (command "attreq" "1" "")
 (command "._cmleaderstyle" "Anno Leader" )
 (command "._mleader" "O" "C" "Block" "Equip-tag" "")
)

CECE_CAD

  • Guest
Re: Insert block with leader lisp: Works now..
« Reply #4 on: May 06, 2008, 09:12:05 AM »
Got it to work!!  Thanks for your help with the Code cmwade77 ..  So this will use an anno leader with an anno attributed block and works great..  

(DEFUN C:mech () ; Mleader with Loop
 (command "._insert" "K:/settings/AnnoDims.dwg" "0,0" "" "" "")
 (setq BNAME "Equip-tag")
 (command "attreq" "0" "")
 (command "._insert" "K:/menu/notes/Equip-tag.dwg" "0,0" "" "" "" "")
 (command "._erase" (entlast) "")
 (command "attreq" "1" "")
 (command "._cmleaderstyle" "Anno Leader" )
 (command "._mleader" "O" "C" "Block" "Equip-tag" "X" "L" "h")
)

CECE_CAD

  • Guest
Assistance with code Please
« Reply #5 on: May 08, 2008, 04:41:02 PM »
Ok this is frustrating me, I’m not good at putting these together as you can see…  It was working until I added a command to create a layer.  After the block is inserted then deleted the block is called again from with in the drawing, autocad prompts back with block name  invalid.  I have attached a picture of the bedit deffinitions to show the block is in the drawing.  Is there something I’m doing wrong?  I don’t know anything about error traps but I don’t think I need one?  Is there a better way to write this? 

 

Code: [Select]
(DEFUN C:mech () ; Mleader with Loop
 (command "._insert" "K:/settings/AnnoDims.dwg" "0,0" "" "" "")
 (setq BNAME "EquiptagA")
 (command "attreq" "0" "")
 (command "._layer" "M" "Equip-tagA" "C" "2" "Equip-tagA" "")
 (command "._insert" "K:/menu/annoblocks/EquiptagA.dwg" "0,0" "" "" "" "")
 (command "._erase" (entlast) "")
 (command "attreq" "1" "")
 (command "._layer" "M" "Leader Equip-TagA" "C" "White" "Leader Equip-TagA" "")
 (command "._cmleaderstyle" "Anno Leader" )
 (vl-cmdf "._mleader" "O" "C" "Block" "EquiptagA" "X" "L" "h")
)
« Last Edit: May 08, 2008, 05:41:25 PM by CECE_CAD »

CECE_CAD

  • Guest
Re: Insert block with mleader lisp help RE: What is wrong?
« Reply #6 on: May 08, 2008, 05:42:48 PM »
Also forgot to mention that i turned on annotativedwg in the equiptaga block.. I don't think it matters but I thought I would put that out there.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Insert block with mleader lisp help RE: What is wrong?
« Reply #7 on: May 08, 2008, 06:08:44 PM »
ok, first off, in the block turn the annotative tag off, make the leader style annotative instead, you can not use annotative blocks inside of mleaders, the annotative option on the leader style will take care of that.

Code: [Select]
(DEFUN C:mech () ; Mleader with Loop
 (setq OldAttreq (getvar "attreq")); This will allow you to restore attreq when you are done.
 (command "._insert" "K:/settings/AnnoDims.dwg" "0,0" "" "" "")
 (setq BNAME "EquiptagA"); Setting the block name here will allow you to greater flexibility with this routine, for example I created a similar object as a funcion that I can pass all sorts of variables to.
 (setvar "attreq" 0); Makes sure that if there is any attributes that you do not need to fill them in.
 (vl-cmdf "._layer" "M" BNAME "C" "2" BNAME ""); Modified this to create a layer based off of the Block Name
 (vl-cmdf "._insert" (strcat "K:\\menu\\annoblocks\\" BNAME) "0,0" "" "" "" ""); I generally have better luck with the \\ than the / for some reason, I have also modified this to use the BNAME variable as set earlier.
 (vl-cmdf "._erase" (entlast) ""); Erases the last entity inserted, as it is no longer needed.
 (vl-cmdf "._layer" "M" (strcat "Leader " BNAME) "C" "White" (strcat "Leader " BNAME) ""); Again by using the bname variable that was set earlier you will be able to customize this routine very quickly in the future.
 (vl-cmdf "._cmleaderstyle" "Anno Leader" ); Sets the leader style
 (setvar "attreq" 1); Ensures that Mleader will prompt you for all of the needed attributes
 (vl-cmdf "._mleader" "O" "C" "Block" BNAME "X" "L" "h"); Calls the mleader command
 (setvar "attreq" OldAttReq); Restores attreq back to what it was when you started the command.
)

I have recently been made aware that the vl-cmdf is preffered over command.
Pasting this into the visual lisp editor should make the comments stand out nicely for you, hopefully you can learn a bit more about LISP at the same time, so that the next time you need to write LISP it will be a bit easier for you, I am always learning something new.
« Last Edit: May 08, 2008, 06:16:32 PM by cmwade77 »

CECE_CAD

  • Guest
Re: Insert block with mleader lisp help RE: What is wrong?
« Reply #8 on: May 08, 2008, 06:11:05 PM »
Ok, so at first I didn't have the block set to annotive.. But I already have the leader style set to anno.. Having both the block and leader annotive doesn't work..?  I will try out the code.. Thanks for looking at it..

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Insert block with mleader lisp help RE: What is wrong?
« Reply #9 on: May 09, 2008, 12:14:32 PM »
Having both set as annotative causes some conflicts, I never had it crash out the routine though, what happened to me was the Annotative leader scaled the annotative block, which mean that when it came to the block the annotative scales were multiplied and I ended up with a HUGE block, changed the block to not be annotative and that fixed the problem.

No problem, it took me quite some time to get my leader routines to work exactly how I wanted them to with MLEADERS, but they now all work great.

Let me know how it turns out for you.

Crank

  • Water Moccasin
  • Posts: 1503
Re: Insert block with mleader lisp help RE: What is wrong?
« Reply #10 on: May 09, 2008, 01:48:36 PM »
  • Make the ML-style annotative, not the block.
  • You don't have to insert the block and erase it. Just cancel the insert command:

(command ".insert" (strcat "K:\\menu\\annoblocks\\" BNAME) (command))
[/list]
Vault Professional 2023     +     AEC Collection

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Insert block with mleader lisp help RE: What is wrong?
« Reply #11 on: May 09, 2008, 01:52:06 PM »
Cool, I didn't know that would work.

CECE_CAD

  • Guest
Re: Insert block with mleader lisp help RE: What is wrong?
« Reply #12 on: May 12, 2008, 11:56:09 AM »
Cool, I didn't know that would work.

Thanks guy's.. I was wondering why it stopped working.. I set the block back so it wasn't annotive.  The only thing thats not setting is the layer for the block, the layer gets created fine.  When the block is added to the leader it doesn't take the layer.. 

Crank,
Thanks for the tip, it works good. 

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Insert block with mleader lisp help RE: What is wrong?
« Reply #13 on: May 12, 2008, 04:11:41 PM »
I the definition of the block is everything drawn on layer 0 and set to bylayer? If not, that's why.

CECE_CAD

  • Guest
Re: Insert block with mleader lisp help RE: What is wrong?
« Reply #14 on: May 12, 2008, 05:35:42 PM »
Yes, the block is drawn on Zero..  Should it be set to byblock?

CECE_CAD

  • Guest
Re: Insert block with mleader lisp help RE: What is wrong?
« Reply #15 on: May 13, 2008, 07:54:05 AM »
I just looked at my mleaderstyle and noticed that my leader was set to byblock, so I changed that to white and only using one of the layers "Leader" setting that to yellow.. That changes the tag to yellow keeping the leader white.  Thanks again! I do appreciate the help..

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Insert block with mleader lisp help RE: What is wrong?
« Reply #16 on: May 13, 2008, 01:23:26 PM »
No problem.