Jump to content

Solid hatch color change in and outside of blocks


K Baden

Recommended Posts

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)

Link to comment
Share on other sites

((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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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!!!

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...