Lee Mac Posted July 13, 2009 Posted July 13, 2009 Going the VL route: (defun c:test () (vl-load-com) (vlax-for blk (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for Obj blk (if (eq 3 (vla-get-color Obj)) (vla-put-color Obj 1)))) (princ)) Quote
SteveK Posted July 13, 2009 Author Posted July 13, 2009 Here's what I've done. I've made an edit form (at the bottom) so I can just put in different things in there and it will apply it to all objects: ; Start of command form: *********************************** (defun c:cca (/ ss1 i en elst RGB_number) (setvar "cmdecho" 0) (command "UNDO" "BE") ; Begin UNDO group ; Search individual Entities================================= (setq ss1 (ssget "_X")) (setq i -1) (while (setq en (ssname ss1 (setq i (1+ i)))) (edit en) ) ; End while ;===================================================== ; Search and change all blocks============================== (foreach blk (getblk) (foreach sub (GetObj (tblobjname "BLOCK" blk)) (edit sub) ) ; End Foreach sub ) ; End Foreach blk ;===================================================== (command "REGEN") (command "UNDO" "E") ; End UNDO Group (setvar "cmdecho" 1) (princ) ) ;***************************************************** ; Returns List of entity names in block------------------------------- (defun GetObj (bObj) (if (setq bObj (entnext bObj)) (cons bObj (GetObj bObj)))) ; Returns list of block names------------------------------------------ (defun getblk (/ tdef lst) (reverse (while (setq tdef (tblnext "BLOCK" (not tdef))) (setq lst (cons (cdr (assoc 2 tdef)) lst))))) ; Makes changes to specified entity name (en)------------------------ (defun edit (en) ;Put in whatever changes you want to make to entities here ;Example: (setq elst (entget en) RGB_number (cdr (assoc 420 elst))) ; Remove RGB value (Setq elst (vl-remove-if (function (lambda (x) (eq 420 (car x)))) elst)) ; Convert specific RGB values to specified ACI Colours (Cond ((= RGB_number 16737792) ; Orange (Setq elst (subst (cons 62 2) (assoc 62 elst) elst))) ; To Yellow ((= RGB_number 52479) ; Sky Blue (Setq elst (subst (cons 62 140) (assoc 62 elst) elst))) ; To Color 140 ) ; End Cond (entmod elst) (entupd en) ) Except now when I try to implement the VL code in place of: ; Search and change all blocks================================ (foreach blk (getblk) (foreach sub (GetObj (tblobjname "BLOCK" blk)) (edit sub) ) ; End Foreach sub ) ; End Foreach blk ;====================================================== IE something like: ; Search and change all blocks================================ (vl-load-com) (vlax-for blk (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for Obj blk (edit Obj) ) ) ;==================================================== Obj is not an entity name so this doesn't work. Can you correct this? (nothing too incomprehensible please ) Quote
Lee Mac Posted July 14, 2009 Posted July 14, 2009 Hey Steve, my posted code will change the colour using a VL method - as each item I am working on is now a VLA-Object. You could either go the VL route and edit the objects using VL methods, or stick to plain AutoLISP and convert the VLA-object back to an ename using: (vlax-vla-object->ename Obj) Hope I'm not overcomplicating things here I'll look at your code and see if I can explain things better for you Lee Quote
Lee Mac Posted July 14, 2009 Posted July 14, 2009 I've tried not to change your original code too much, but just add my snippet: ; Start of command form: *********************************** (defun c:cca (/ ss1 i en elst RGB_number) (setvar "cmdecho" 0) (command "UNDO" "BE") ; Begin UNDO group ; Search individual Entities================================= (setq ss1 (ssget "_X")) (setq i -1) (while (setq en (ssname ss1 (setq i (1+ i)))) (edit en) ) ; End while ;===================================================== ; Search and change all blocks================================ (vl-load-com) (vlax-for blk (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for Obj blk (edit (vlax-vla-object->ename Obj)) ) ) ;==================================================== (command "REGEN") (command "UNDO" "E") ; End UNDO Group (setvar "cmdecho" 1) (princ) ) ;***************************************************** ; Makes changes to specified entity name (en)------------------------ (defun edit (en) ;Put in whatever changes you want to make to entities here ;Example: (setq elst (entget en) RGB_number (cdr (assoc 420 elst))) ; Remove RGB value (Setq elst (vl-remove-if (function (lambda (x) (eq 420 (car x)))) elst)) ; Convert specific RGB values to specified ACI Colours (Cond ((= RGB_number 16737792) ; Orange (Setq elst (subst (cons 62 2) (assoc 62 elst) elst))) ; To Yellow ((= RGB_number 52479) ; Sky Blue (Setq elst (subst (cons 62 140) (assoc 62 elst) elst))) ; To Color 140 ) ; End Cond (entmod elst) (entupd en) ) Quote
SteveK Posted July 14, 2009 Author Posted July 14, 2009 Yeah great, vlisp does the trick. For the big drawing it took about 2minutes but it worked So the lesson learnt is there is no simple autolisp method -> learn vlisp Thanks Lee Quote
Lee Mac Posted July 14, 2009 Posted July 14, 2009 Yeah great, vlisp does the trick. For the big drawing it took about 2minutes but it worked So the lesson learnt is there is no simple autolisp method -> learn vlisp Thanks Lee I find VLisp easier, now that I have gotten to grips with it. Although I would recommend that you are competent with standard AutoLisp first. Visual LISP can be a bit daunting at first, as there are a few more data types to deal with, - like safe-array's and variants, but once you get the hang of it, you should be ok 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.