Jump to content
Michael83

Auto lisp to redefine/insert multiple blocks w/o prompts??

Recommended Posts

Michael83

I know there's a bunch of posts on this but I could never find a lisp that could incorporate all, or multiple. lisps that can..auto run w/ ea. .dwg opened, redefine & replace multiple referenced blocks (about 10) keeping original location, & retaining attributes..w/o any prompts..I could be asking too much but any insight is greatly appreciated..I'm on hr 7 on this one..if it's easier..only one block has attributes and can make a separate lisp for that..or again if easier make a separate lisp for ea block..anything put together really that auto runs w/o prompts.. If u think I missed a post like this please let me know..again I really appreciate it

Share this post


Link to post
Share on other sites
David Bethel

It could be as simple as this:

[b][color=BLACK]([/color][/b]defun c:upbs [b][color=FUCHSIA]([/color][/b]/ bl[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq bl '[b][color=NAVY]([/color][/b][color=#2f4f4f]"BLOCK1"[/color] [color=#2f4f4f]"BLOCK2"[/color] [color=#2f4f4f]"BLOCK2"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]foreach b bl
    [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]and [b][color=GREEN]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]cons 0 [color=#2f4f4f]"INSERT"[/color][b][color=RED])[/color][/b][b][color=RED]([/color][/b]cons 2 b[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
             [b][color=GREEN]([/color][/b]findfile [b][color=BLUE]([/color][/b]strcat b [color=#2f4f4f]".DWG"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
        [b][color=MAROON]([/color][/b]progn
         [b][color=GREEN]([/color][/b]command [color=#2f4f4f]"_.INSERT"[/color] [b][color=BLUE]([/color][/b]strcat b [color=#2f4f4f]"="[/color] b[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
         [b][color=GREEN]([/color][/b]command[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

It could also be a lot more complicated. -David

Share this post


Link to post
Share on other sites
Lee Mac

I wrote this a while back, you can call it from within a script if you like:

 

(defun ReDef ( block / *error* oc spc doc block )
 (vl-load-com)
 ;; © Lee Mac 2010

 (defun *error* ( msg )
   (and oc (setvar 'CMDECHO oc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (setq spc
   (if
     (or
       (eq AcModelSpace
         (vla-get-ActiveSpace
           (setq doc
             (vla-get-ActiveDocument
               (vlax-get-acad-object)
             )
           )
         )
       )
       (eq :vlax-true (vla-get-MSpace doc))
     )
     (vla-get-ModelSpace doc)
     (vla-get-PaperSpace doc)
   )
 )

 (setq oc (getvar 'CMDECHO)) (setvar 'CMDECHO 0)  

 (if (setq block (findfile block))
   (progn
     (vla-delete
       (vla-insertblock spc
         (vlax-3D-point '(0. 0. 0.)) block 1. 1. 1. 0.
       )
     )
     (vl-cmdf "_.attsync" "_N" (vl-filename-base block))
   )
 )
 
 (setvar 'CMDECHO oc)
 (princ)
)

 

Call like this:

 

(Redef "C:\\MyFolder\\MyBlock.dwg")

Share this post


Link to post
Share on other sites
Michael83

Thanks for the response. It's amazing how active this forum is..Having some difficulty..The blocks that need to be redefined have the same name for the code you provide David and got an error. I know I'm missing something with your code Lee..It's saying its unknown..When you say call from..(Redef "C:\\Tool Palettes 8-31-08\\ Common Notes\\ CN200.dwg") Does that mean it would import & redefine one block only at a time..Newbie Question...is this saved as a lisp..or do I create a vlx file with it with same name in same folder as lisps..

Share this post


Link to post
Share on other sites
Lee Mac

Hi Michael,

 

I'll make mine easier to use and more akin to David's:

 

(defun c:ReDef ( / *error* oc spc doc block b )
 (vl-load-com)
 ;; © Lee Mac 2010

 ;; Full filename needed if block is not in the support path
 (setq BlocksToRedefine
  '(
     "C:\\MyFolder\\BLOCK1.dwg"
     "C:\\MyFolder\\BLOCK2.dwg"
     "BLOCK3"
   )
 )

 (defun *error* ( msg )
   (and oc (setvar 'CMDECHO oc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (setq spc
   (vlax-get (vla-get-ActiveDocument (vlax-get-acad-object))
     (if (= 1 (getvar 'CVPORT)) 'PaperSpace 'ModelSpace)
   )
 )
 
 (setq oc (getvar 'CMDECHO)) (setvar 'CMDECHO 0)

 (foreach block BlocksToRedefine
   (if (setq b (findfile (strcat block (if (not (vl-filename-extension block)) ".dwg" ""))))
     (progn
       (vla-delete
         (vla-insertblock spc
           (vlax-3D-point '(0. 0. 0.)) b 1. 1. 1. 0.
         )
       )
       (vl-cmdf "_.attsync" "_N" (vl-filename-base b))
     )
     (princ (strcat "\n** Cannot Find Block: " block " **"))
   )
 )
 
 (setvar 'CMDECHO oc)
 (princ)
)

 

Save the above as a .lsp file and edit the list at the top to suit the blocks you are redefining.

 

Load as you would any other LISP file. Instructions here.

 

Lee

Share this post


Link to post
Share on other sites
David Bethel

Hmmm....

 

This turns the CMDECHO on

 

The command line screen should give you a clue as to the problem

 

[b][color=BLACK]([/color][/b]defun c:upbs [b][color=FUCHSIA]([/color][/b]/ bl[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setvar [color=#2f4f4f]"CMDECHO"[/color] 1[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq bl '[b][color=NAVY]([/color][/b][color=#2f4f4f]"LEG6"[/color] [color=#2f4f4f]"FDI-OCT2"[/color] [color=#2f4f4f]"KCLHEX4"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]foreach b bl
    [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]and [b][color=GREEN]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]cons 0 [color=#2f4f4f]"INSERT"[/color][b][color=RED])[/color][/b][b][color=RED]([/color][/b]cons 2 b[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
             [b][color=GREEN]([/color][/b]findfile [b][color=BLUE]([/color][/b]strcat b [color=#2f4f4f]".DWG"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
        [b][color=MAROON]([/color][/b]progn
           [b][color=GREEN]([/color][/b]command [color=#2f4f4f]"_.INSERT"[/color] [b][color=BLUE]([/color][/b]strcat b [color=#2f4f4f]"="[/color] b[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
           [b][color=GREEN]([/color][/b]command[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

The block names are dwg files located in the search path

The names in the list do not contain the '.dwg' extension

The block names are the same

 

 

 

-David

Share this post


Link to post
Share on other sites
jake77777

I'll certainly remember to relay the cmdecho response in the future..it came back with the block names are the same code response..But I think the other code should do the trick perfect..loves how it comes in at the same scale! Very grateful for this one. Thank you David/Lee. Just Awesome!

Share this post


Link to post
Share on other sites
irneb

I had something similar previously, but it's not perfect. And I've not updated it well since I use it very little.

http://forums.augi.com/showthread.php?t=74579

 

It's not exactly what I wanted, since my libraries are all contained within DWG's and I then use DesignCenter to import the blocks. I was thinking of using ObjectDBX to redefine the blocks from another DWG into the current ... but simply don't have the time (as it's not such a big hassle to me as yet).

Share this post


Link to post
Share on other sites
boratensa

hi,

 

i need a little lisp which creates blocks with unique random names (no matter what) out of selected objects. can you help me out?

Share this post


Link to post
Share on other sites
David Bethel

You should, probably have started a new thread. However, all you will need to look into are anonymous blocks. You will need to ( entmake ) the BLOCK and the ( entmake ) the INSERT. -David

Share this post


Link to post
Share on other sites
johmmeke

i know this is a old thread..

 

i try to use lee's second code but get this error---

 

Block SAL-TITELBLOK_GNB_LANG references itself

** Error: Automation Error. Self reference **

 

what is it i do wrong?

the block i try to redefine has the same name as the drawing and block in the drawing i put in the list -> BlocksToRedefine

 

greetz john

Share this post


Link to post
Share on other sites
johmmeke

found what i did wrong.

 

now working perfect ;-)

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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