Michael83 Posted October 2, 2010 Posted October 2, 2010 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 Quote
David Bethel Posted October 2, 2010 Posted October 2, 2010 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 Quote
Lee Mac Posted October 2, 2010 Posted October 2, 2010 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") Quote
Michael83 Posted October 2, 2010 Author Posted October 2, 2010 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.. Quote
Lee Mac Posted October 2, 2010 Posted October 2, 2010 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 Quote
David Bethel Posted October 2, 2010 Posted October 2, 2010 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 Quote
jake77777 Posted October 2, 2010 Posted October 2, 2010 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! Quote
irneb Posted October 2, 2010 Posted October 2, 2010 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). Quote
boratensa Posted May 21, 2013 Posted May 21, 2013 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? Quote
David Bethel Posted May 21, 2013 Posted May 21, 2013 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 Quote
johmmeke Posted April 9, 2017 Posted April 9, 2017 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 Quote
johmmeke Posted April 10, 2017 Posted April 10, 2017 found what i did wrong. now working perfect ;-) Quote
Recommended Posts
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.