cedwards Posted July 28, 2009 Posted July 28, 2009 I was wondering if someone could help me modify this lisp that I found or if someone has one that could help. I need the lisp to update/redefine all the blocks in the current dwg. The attached one works very good but it would be perfect if I could just define a support path instead of picking it. Thanks in advance for your help. (defun BrowseForFolder ( text Rootfolder / ret y ) (setq y (vlax-get-or-create-object "shell.application")) (if (setq ret (vlax-invoke y "BrowseForFolder" 0 text 1 Rootfolder)) (setq ret (vlax-get (vlax-get ret "Self") "Path"))) (vlax-release-object y) ret ) (defun get_table (table / tb tb_ls) (setq tb (tblnext table t) tb_ls nil ) (while tb (cond ((= (strcase table) "STYLE") (if (= (boole 1 (cdr (assoc 70 tb)) 1) 0);bit 1 bedeutet Symboleintrag, keine Schrift! (setq tb_ls (append tb_ls (list (cdr (assoc 2 tb))))) ) ) ((= (strcase table) "BLOCK") (if (/= (substr (cdr (assoc 2 tb)) 1 1) "*") (setq tb_ls (append tb_ls (list (cdr (assoc 2 tb))))) ) ) (t (setq tb_ls (append tb_ls (list (cdr (assoc 2 tb))))) ) ) (setq tb (tblnext table)) ) (setq tb_ls (vl-sort tb_ls '<)) ) (defun c:all-block-upd ( / bl_liste ant n bl_ex) (setvar "cmdecho" 0) (command "_undo" "_be") (setq bl_liste (get_table "block")) (if bl_pfad (progn (initget "Ja Nein") (setq ant (getkword (strcat "Pfad "bl_pfad" verwenden? <Ja>/Nein:"))) (if (= ant "Nein") (setq bl-pfad (BrowseForFolder "Blockpfad wählen:" ""))) ) (setq bl_pfad (BrowseForFolder "Blockpfad wählen:" "")) ) (foreach n bl_liste (progn (setq bl_ex (strcat bl_pfad "\\" n ".dwg")) (if (findfile bl_ex) (command "_insert" (strcat n "=" bl_ex) nil)) ) ) (command "_undo" "_end") (setvar "cmdecho" 1) (prin1) ) (defun c:block-upd ( / bl_liste ant n bl_ex) (setvar "cmdecho" 0) (command "_undo" "_be") (setq bl_liste (get_table "block")) (if bl_pfad (progn (initget "Ja Nein") (setq ant (getkword (strcat "Pfad " bl_pfad " verwenden? <Ja>/Nein:"))) (if (= ant "Nein") (setq bl-pfad (BrowseForFolder "Blockpfad wählen:" ""))) ) (setq bl_pfad (BrowseForFolder "Blockpfad wählen:" "")) ) (foreach n bl_liste (progn (setq bl_ex (strcat bl_pfad "\\" n ".dwg")) (if (findfile bl_ex) (progn (initget "Ja Nein") (setq ant (getkword (strcat "Block " n " aktualisieren? <Ja>/Nein:"))) (if (/= ant "Nein") (command "_insert" (strcat n "=" bl_ex) nil)) ) ) ) ) (command "_undo" "_end") (setvar "cmdecho" 1) (prin1) ) (prompt "Funktionen ALL-BLOCK-UPD und BLOCK-UPD geladen. (c) H. Jesse 2006") Quote
wkplan Posted July 28, 2009 Posted July 28, 2009 The support-path is defined in the var "bl_pfad", twice. What I did: just comment out part of code which will call the shell and pick the path, then hardcoded the path. (Look for: (setq bl_pfad "D:\\TEST") ;;;; ++++ place directory-path here" You have to adjust the path to youre needs. It ist surely not the best way to deal with this problem, but it works:wink: regards Wolfgang (defun BrowseForFolder ( text Rootfolder / ret y ) (setq y (vlax-get-or-create-object "shell.application")) (if (setq ret (vlax-invoke y "BrowseForFolder" 0 text 1 Rootfolder)) (setq ret (vlax-get (vlax-get ret "Self") "Path"))) (vlax-release-object y) ret ) (defun get_table (table / tb tb_ls) (setq tb (tblnext table t) tb_ls nil ) (while tb (cond ((= (strcase table) "STYLE") (if (= (boole 1 (cdr (assoc 70 tb)) 1) 0);bit 1 bedeutet Symboleintrag, keine Schrift! (setq tb_ls (append tb_ls (list (cdr (assoc 2 tb))))) ) ) ((= (strcase table) "BLOCK") (if (/= (substr (cdr (assoc 2 tb)) 1 1) "*") (setq tb_ls (append tb_ls (list (cdr (assoc 2 tb))))) ) ) (t (setq tb_ls (append tb_ls (list (cdr (assoc 2 tb))))) ) ) (setq tb (tblnext table)) ) (setq tb_ls (vl-sort tb_ls '<)) ) (defun c:all-block-upd ( / bl_liste ant n bl_ex) (setvar "cmdecho" 0) (command "_undo" "_be") (setq bl_liste (get_table "block")) ;(if bl_pfad ;(progn ;(initget "Ja Nein") ;(setq ant (getkword (strcat "Pfad "bl_pfad" verwenden? <Ja>/Nein:"))) ;(if (= ant "Nein") (setq bl-pfad (BrowseForFolder "Blockpfad wählen:" ""))) ;(setq bl_pfad (BrowseForFolder "Blockpfad wählen:" "")) (setq bl_pfad "D:\\TEST");;;; ++++ place directory-path here (foreach n bl_liste (progn (setq bl_ex (strcat bl_pfad "\\" n ".dwg")) (if (findfile bl_ex) (command "_insert" (strcat n "=" bl_ex) nil)) ) ) (command "_undo" "_end") (setvar "cmdecho" 1) (prin1) ) (defun c:block-upd ( / bl_liste ant n bl_ex) (setvar "cmdecho" 0) (command "_undo" "_be") (setq bl_liste (get_table "block")) ;(if bl_pfad ;(progn ;(initget "Ja Nein") ;(setq ant (getkword (strcat "Pfad " bl_pfad " verwenden? <Ja>/Nein:"))) ;(if (= ant "Nein") (setq bl-pfad (BrowseForFolder "Blockpfad wählen:" ""))) ;(setq bl_pfad (BrowseForFolder "Blockpfad wählen:" "")) (setq bl_pfad "D:\\TEST") ;;;; ++++ place directory-path here (foreach n bl_liste (progn (setq bl_ex (strcat bl_pfad "\\" n ".dwg")) (if (findfile bl_ex) (progn (initget "Ja Nein") (setq ant (getkword (strcat "Block " n " aktualisieren? <Ja>/Nein:"))) (if (/= ant "Nein") (command "_insert" (strcat n "=" bl_ex) nil)) ) ) ) ) (command "_undo" "_end") (setvar "cmdecho" 1) (prin1) ) (prompt "Funktionen ALL-BLOCK-UPD und BLOCK-UPD geladen. (c) H. Jesse 2006") Quote
gilsoto13 Posted September 25, 2009 Posted September 25, 2009 The support-path is defined in the var "bl_pfad", twice.What I did: just comment out part of code which will call the shell and pick the path, then hardcoded the path. (Look for: (setq bl_pfad "D:\\TEST") ;;;; ++++ place directory-path here" You have to adjust the path to youre needs. It ist surely not the best way to deal with this problem, but it works:wink: regards Wolfgang (defun BrowseForFolder ( text Rootfolder / ret y ) (setq y (vlax-get-or-create-object "shell.application")) (if (setq ret (vlax-invoke y "BrowseForFolder" 0 text 1 Rootfolder)) (setq ret (vlax-get (vlax-get ret "Self") "Path"))) (vlax-release-object y) ret ) (defun get_table (table / tb tb_ls) (setq tb (tblnext table t) tb_ls nil ) (while tb (cond ((= (strcase table) "STYLE") (if (= (boole 1 (cdr (assoc 70 tb)) 1) 0);bit 1 bedeutet Symboleintrag, keine Schrift! (setq tb_ls (append tb_ls (list (cdr (assoc 2 tb))))) ) ) ((= (strcase table) "BLOCK") (if (/= (substr (cdr (assoc 2 tb)) 1 1) "*") (setq tb_ls (append tb_ls (list (cdr (assoc 2 tb))))) ) ) (t (setq tb_ls (append tb_ls (list (cdr (assoc 2 tb))))) ) ) (setq tb (tblnext table)) ) (setq tb_ls (vl-sort tb_ls '<)) ) (defun c:all-block-upd ( / bl_liste ant n bl_ex) (setvar "cmdecho" 0) (command "_undo" "_be") (setq bl_liste (get_table "block")) ;(if bl_pfad ;(progn ;(initget "Ja Nein") ;(setq ant (getkword (strcat "Pfad "bl_pfad" verwenden? <Ja>/Nein:"))) ;(if (= ant "Nein") (setq bl-pfad (BrowseForFolder "Blockpfad wählen:" ""))) ;(setq bl_pfad (BrowseForFolder "Blockpfad wählen:" "")) (setq bl_pfad "D:\\TEST");;;; ++++ place directory-path here (foreach n bl_liste (progn (setq bl_ex (strcat bl_pfad "\\" n ".dwg")) (if (findfile bl_ex) (command "_insert" (strcat n "=" bl_ex) nil)) ) ) (command "_undo" "_end") (setvar "cmdecho" 1) (prin1) ) (defun c:block-upd ( / bl_liste ant n bl_ex) (setvar "cmdecho" 0) (command "_undo" "_be") (setq bl_liste (get_table "block")) ;(if bl_pfad ;(progn ;(initget "Ja Nein") ;(setq ant (getkword (strcat "Pfad " bl_pfad " verwenden? <Ja>/Nein:"))) ;(if (= ant "Nein") (setq bl-pfad (BrowseForFolder "Blockpfad wählen:" ""))) ;(setq bl_pfad (BrowseForFolder "Blockpfad wählen:" "")) (setq bl_pfad "D:\\TEST") ;;;; ++++ place directory-path here (foreach n bl_liste (progn (setq bl_ex (strcat bl_pfad "\\" n ".dwg")) (if (findfile bl_ex) (progn (initget "Ja Nein") (setq ant (getkword (strcat "Block " n " aktualisieren? <Ja>/Nein:"))) (if (/= ant "Nein") (command "_insert" (strcat n "=" bl_ex) nil)) ) ) ) ) (command "_undo" "_end") (setvar "cmdecho" 1) (prin1) ) (prompt "Funktionen ALL-BLOCK-UPD und BLOCK-UPD geladen. (c) H. Jesse 2006") I'll check it out right now.. maybe will be needed... Quote
gilsoto13 Posted September 28, 2009 Posted September 28, 2009 I'll check it out right now.. maybe will be needed... And yes, it works... But I think It is also possible by inserting all the blocks from that directory in a new drawing with the attached lisp (Blockimport.lsp) and then just copy paste all the blocks in the drawing to the new drawing, that way autocad will ignore previous versions copied from the old drawing and keep new versions already inserted using Block import in the new drawing... Maybe they are 2 ways to do the same... This one seems to take a little more time... but for some reason I prefer it.. BI.lsp Quote
wkplan Posted September 29, 2009 Posted September 29, 2009 And yes, it works... Maybe they are 2 ways to do the same... This one seems to take a little more time... but for some reason I prefer it.. Hi gilsoto13, CAB's code is allways a good advice for learning lisp. It is (as usual) a well commented code, you can step through the lines and see what happens. "BrowseForFolder" is also well commented, but in german language. There are many lisps around here that deal with same problems. For me it is important to understand how the lisp works, see what it does. This gives me the chance to learn more about lisp, modify or combine them and build other lisps that help me in daily cad. So if you prefer a special lisp, if it does exactly what you need, feel happy that you have found it. regards Wolfgang 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.