alexcolodner Posted June 8, 2011 Posted June 8, 2011 So I get a lot of drawings from architects which need to be prepared in a specific way that can be quite tedious and sometimes a time consuming process. I have been trying to speed things up by writing some simple LISPs (I am new to autoLISP) and incorporating them along with other commands into Macros. This method sort of works, but when switching computers I have to load up each lisp and the macro. It also takes quite long and certain commands have to select stuff or hit enter, etc. Sometimes I can have en entire drawing set updated in the middle of my working, and sometimes I need to run through this with 20+ large drawings. I do not know LISP well enough to easily write all of this into one routine. I have been trying but having countless problems. Here is what I am trying to accomplish: -Bind all x-refs -Burst bound x-refs -Unlock all layers -Delete frozen layers -Delete invisible layers -Delete all dimensions -Set all layers to a single color -Set all objects color to ByLayer Here is how I am binding all xrefs: (defun c:xrb () (command "xref" "b" "*") (princ) ) For bursting all xrefs I am selecting them and bursting them from within the macro... cant figure out how to burst from a routine. I unlock all layers from command macro as well. Deleting all objects on frozen/invisible layers is done from this: (defun c:deleteFROZENOFF (/ blocks doc ent idx layers lays2delete ss) (vl-load-com) (setq doc (vla-get-activedocument (vlax-get-acad-object)) layers (vla-get-layers doc) blocks (vla-get-blocks doc) idx -1 ) (vlax-for lay layers (if (or (eq (vla-get-layeron lay) :vlax-false) (eq (vla-get-freeze lay) :vlax-true) ) (progn (vla-put-lock lay :vlax-false) (if lays2delete (setq lays2delete (strcat lays2delete "," (vla-get-name lay))) (setq lays2delete (vla-get-name lay)) ) ) ) ) (if (and lays2delete (setq ss (ssget "x" (list (cons 8 lays2delete)))) ) (progn (while (setq ent (ssname ss (setq idx (1+ idx)))) (vla-delete (vlax-ename->vla-object ent)) ) ) ) (princ (strcat "\nDone....deleted " (itoa (1+ idx)) " entities from the drawing.")) (princ) ) ^Had some help with this one Set all layers to a single color uses this: (defun c:layers55 () (command "_.layer" "_co" "55" "*" "") (princ) ) SetByLayer command works like a charm to set all objects color to ByLayer, but when it is called in the macro, I need to configure the settings to just color. I would like to eliminate that step. So that is where I am right now. Any help, tips, or ideas would be greatly appreciated. Ideally I want to just type a command and have the routine do all for me at once without having to attend to it. Thanks! Quote
Lee Mac Posted June 8, 2011 Posted June 8, 2011 Maybe something like this? (defun c:test ( / *error* a b c d e f ) ;; © Lee Mac 2011 (defun *error* ( msg ) (if c (setvar 'CMDECHO c)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (setq c (getvar 'CMDECHO)) (setvar 'CMDECHO 0) (while (setq b (tblnext "BLOCK" (null b))) (if (= 4 (logand 4 (cdr (assoc 70 b)))) (setq a (cons "," (cons (cdr (assoc 2 b)) a))) ) ) (command "_.undo" "_BE" "_.-xref" "_B" "*" "_.-layer" "_U" "*" "") (sssetfirst nil (ssget "_X" (list '(0 . "INSERT") (cons 2 (apply 'strcat (cdr a)))))) (c:burst) (while (setq d (tblnext "LAYER" (null d))) (if (or (minusp (cdr (assoc 62 d))) (= 1 (logand 1 (cdr (assoc 70 d)))) ) (setq e (cons (cdr (assoc 2 d)) e)) ) ) (command "_.-laydel") (foreach x e (command "_N" x)) (command "" "_Y" "_.-layer" "_C" "55" "*" "") (if (setq f (ssget "_X" '((0 . "*DIMENSION")))) (command "_.erase" f "") ) (if (setq f (ssget "_X")) (command "_.chprop" f "" "_C" "ByLayer" "") ) (command "_.undo" "_E") (setvar 'CMDECHO c) (princ) ) Be careful though, the above code is dangerous in that it uses the LayDel command which will delete all entities on a particular layer before deleting that layer. Quote
alexcolodner Posted June 8, 2011 Author Posted June 8, 2011 Thank you Lee! I have tried out that script and it is on the lines of what I am looking for. I have a question though.. Why do you call Undo and BE in this line? (command "_.undo" "_BE" "_.-xref" "_B" "*" "_.-layer" "_U" "*" "") Also, not sure if you will know this, but when I ran this routine on one computer, it did everything on its own without prompting me for yes/no questions or selections. On another computer, it asked me to select things and those questions came up in the command line which I had to manually answer. I assume it is a setting but is there a way to override this? Another question: Where would I call a command that would delete a specific hatch pattern. I would like to delete all solid hatches, but leave the rest. I normally could do this with the QSelect, but because that command brings up a dialogue box where I would choose the particular hatch properties, I am not sure how to do this. Any ideas? Thank you for your help, it is much appreciated! Quote
VVA Posted June 8, 2011 Posted June 8, 2011 Some commands found here (google translate) Burst bound x-refs - BGBLEXP Delete frozen layers - BGLAYDEL Delete invisible layers - BGLAYDEL Set all objects color to ByLayer - BGCOLOR ;;;==============================================;; ;;; Command(s) to call ;;;==============================================;; ;;; ;; ;;; BGLAYDEL - delete frozen and off layers with objects ;; ;;; BG1BLEXP - Explode blocks consisting of one primitive thing (it is possible other block) ;; ;;; BGBLEXP - Explode the block and all blocks entering into it, transforming visible attributes in the text ;; ;;; BGBLEXP1 - Explode blocks of 1st level, transforming visible attributes in the text ;; ;;; BGBLDYNEXP1 - Explode dynamic blocks of 1st level, transforming visible attributes in the text ;; ;;; BGBLEXP1NOATT -Explode blocks of 1st level which do not have visible attributes ;; ;;; BGBLXCLIP - show xclip blocks ;; ;;; BGBLDYN2A - Conver Dynamic Blocks to Anonymous block ;;; BGBLDYN2S - Conver Dynamic Blocks to Static block ;;; =========================================== ;; ;;; BGRGB2ACI - Changes color from RGB to the corresponding Index Color (ACI) ;; ;;; BGCOLOR - Set a selected color to all objects (WITHOUT XREF) ;; ;;; BGCOLORXREF - Changes color selected XREF ( ONLY ON A CURRENT SESSION ) ;; ;;; BGBLCC - Changes color of the chosen blocks ;; ;;; BGENCC - Changes color of the chosen element of the block ;; ;;; BGCATT - Changes color of attributes of the chosen blocks ;; ;;; BGCBL2 - Changes color in blocks 2 and more levels (the nested blocks) ;; ;;; BGBLFIX - fix (normalize) blocks ;; ;;; BGCFT - Convert field to text ;; ;;; ;; ;;;================================================;; Quote
Lee Mac Posted June 8, 2011 Posted June 8, 2011 it is on the lines of what I am looking for. Did I miss a bullet point? Why do you call Undo and BE in this line? (command "_.undo" "_BE" "_.-xref" "_B" "*" "_.-layer" "_U" "*" "") To start an Undo Group so that all the actions between that statement and the Undo End call may be Undone with a single use of the Undo command. Also, not sure if you will know this, but when I ran this routine on one computer, it did everything on its own without prompting me for yes/no questions or selections. This is how the program should function, (and how it does with my initial testing). On another computer, it asked me to select things and those questions came up in the command line which I had to manually answer. I assume it is a setting but is there a way to override this? What are you prompted for? Could you copy the command-line history? Are both computers running the same version of AutoCAD? Another question: Where would I call a command that would delete a specific hatch pattern. I would like to delete all solid hatches, but leave the rest. I normally could do this with the QSelect, but because that command brings up a dialogue box where I would choose the particular hatch properties, I am not sure how to do this. Any ideas? You could need to use a SelectionSet with a filter list to filter for Solid Hatches: (if (setq ss (ssget "_X" '((0 . "HATCH") (2 . "SOLID")))) (command "_.erase" ss "") ) 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.