K Baden Posted August 18, 2017 Share Posted August 18, 2017 Good morning all I am looking to get this code working how i need it to. Right now, it is just selecting solid hatches outside of blocks and looking for more selection. What i want it to do is automatically select all solid hatch in Model space, whether its in a block or not, and change the color to the TrueColor 255,255,255 I'm pretty new to coding, but i think im on the right track, although i do not know how to call for truecolor, and the code isnt currently working. I've done some pretty extensive searching, and this is what i have so far. The code below was originally to change the pattern type, and im afraid my modifications have not done what i'd like. it also doesnt include anything to set its search for Model space only. Thanks in advance for any help, i really appreciate it. (defun c:sol2white ( / doc ) (vlax-for blk (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object)))) (if (= :vlax-false (vla-get-isxref blk)) (vlax-for obj blk (if (and (= "AcDbHatch" (vla-get-objectname obj)) (= "SOLID" (strcase (vla-get-patternname obj))) (vlax-write-enabled-p obj) ) (progn ((vla-put-color obj 255,255,255)) ;(vla-put-patternscale obj 1000.0) ) ) ) ) ) (vla-regen doc acallviewports) (princ) ) (vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted August 18, 2017 Share Posted August 18, 2017 ((vla-put-color obj 255,255,255)) according to documentations, object color property aci index 0-256 integer (vla-put-color obj [color="blue"]AcWhite[/color]) [color="green"];1=red 2=yellow 3=green 4=cyan 5=blue 6=magenta 7=white[/color] useful link color conversion Quote Link to comment Share on other sites More sharing options...
K Baden Posted August 18, 2017 Author Share Posted August 18, 2017 Is there perhaps a way to hybrid this sort of code with this sort of code? (setq sset (ssget "x" '((0 . "HATCH") (2 . "SOLID")))) (command ".chprop" sset "" "c" "T" "255,255,255" "") Im just not sure how to get that ^ sort to look inside block and outside of block for solid hatching. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted August 18, 2017 Share Posted August 18, 2017 Try this: (defun c:sol2white (/ doc) (or *colorobject* (setq *colorobject* (vla-getinterfaceobject (vlax-get-acad-object) (strcat "AutoCAD.AcCmColor." (substr (getvar "acadver") 1 2)) ) ) ) (if (null (vl-catch-all-error-p (vl-catch-all-apply 'vla-setrgb (list *colorobject* 255 255 255)))) (progn (vlax-for blk (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object)))) (if (= :vlax-false (vla-get-isxref blk)) (vlax-for obj blk (if (and (= "AcDbHatch" (vla-get-objectname obj)) (= "SOLID" (strcase (vla-get-patternname obj))) (vlax-write-enabled-p obj) ) (vl-catch-all-apply 'vla-put-truecolor (list obj *colorobject*)) ) ) ) ) (vla-regen doc acallviewports) ) ) (princ) ) (vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
K Baden Posted August 18, 2017 Author Share Posted August 18, 2017 This is amazing. Thank you so much!! I had no clue how to get it to work with 255,255,255 as the color. Unfortunately, it's a rather important variable for the team to have it that rather than white. I really appreciate you helping out with this!!! Quote Link to comment Share on other sites More sharing options...
K Baden Posted August 18, 2017 Author Share Posted August 18, 2017 Could I perhaps pick your brain on how to make this only work within a selection window? rather than the entire drawing? (I am pretty unfamiliar with this type of code) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 19, 2017 Share Posted August 19, 2017 Objects that are not blocks just remove the "X" from your code. The "X" implys all. The ssget will wait for you to pick objects in the way that is normally supported. Quote Link to comment Share on other sites More sharing options...
K Baden Posted August 22, 2017 Author Share Posted August 22, 2017 okay i have returned to this today. I've found that this works how i want it to but i need it to only run within model space. It currently will change the solid hatching on all paper space tabs as well, which causes issues with the title block. any solutions to having it run only in model? I'll post my latest and greatest code below. (defun c:hw (/ doc) (or *colorobject* (setq *colorobject* (vla-getinterfaceobject (vlax-get-acad-object) (strcat "AutoCAD.AcCmColor." (substr (getvar "acadver") 1 2)) ) ) ) (if (null (vl-catch-all-error-p (vl-catch-all-apply 'vla-setrgb (list *colorobject* 255 255 255)))) (progn (vlax-for blk (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object)))) (if (= :vlax-false (vla-get-isxref blk)) (vlax-for obj blk (if (and (= "AcDbHatch" (vla-get-objectname obj)) (= "SOLID" (strcase (vla-get-patternname obj))) (vlax-write-enabled-p obj) ) (vl-catch-all-apply 'vla-put-truecolor (list obj *colorobject*)) ) ) ) ) (vla-regen doc acallviewports) ) ) (princ) ) (vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
K Baden Posted August 22, 2017 Author Share Posted August 22, 2017 I've added the highlighted line and I'm getting this error: Command: HW ; error: ActiveX Server returned the error: unknown name: Blocks (defun c:hw (/ doc) (or *colorobject* (setq *colorobject* (vla-getinterfaceobject (vlax-get-acad-object) (strcat "AutoCAD.AcCmColor." (substr (getvar "acadver") 1 2)) ) ) ) (if (null (vl-catch-all-error-p (vl-catch-all-apply 'vla-setrgb (list *colorobject* 255 255 255)))) (progn (vlax-for blk (vla-get-blocks (setq doc [color="red"](vla-get-ModelSpace[/color] (vla-get-ActiveDocument (vlax-get-acad-object))))) (if (= :vlax-false (vla-get-isxref blk)) (vlax-for obj blk (if (and (= "AcDbHatch" (vla-get-objectname obj)) (= "SOLID" (strcase (vla-get-patternname obj))) (vlax-write-enabled-p obj) ) (vl-catch-all-apply 'vla-put-truecolor (list obj *colorobject*)) ) ) ) ) (vla-regen doc acallviewports) ) ) (princ) ) (vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
devitg Posted August 22, 2017 Share Posted August 22, 2017 Block are not "LIVING" at the MODEL space . It live at the DOC . Blocks ref LIVE at the model or what ever it is. And MODEL an d all LAYOUT are blocks it self. May if you have common letter at block names , as to set a wildcard to select it , but I repeat , what you see at the SPACE are Block-references. Not BLOCK itself. So you can loop to the block-reference , and get the block name . then check for the name at the BLOCK-collection, and change inside the block. Quote Link to comment Share on other sites More sharing options...
K Baden Posted August 23, 2017 Author Share Posted August 23, 2017 All of the blocks would have the word "Elevation" at the end. perhaps i could use that to search for the blocks? I would still also want this to change all solid hatching in modelspace that is not within a block. Is that even possible? I am learning, but I am still an amateur at best with coding. I appreciate any help. Thank you Quote Link to comment Share on other sites More sharing options...
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.