+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Full Member
    Using
    AutoCAD 2017
    Join Date
    Oct 2013
    Posts
    59

    Default Solid hatch color change in and outside of blocks

    Registered forum members do not see this ad.

    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.

    Code:
    (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)

  2. #2
    Super Member hanhphuc's Avatar
    Using
    AutoCAD 2007
    Join Date
    Apr 2013
    Location
    Happy Garden
    Posts
    555

    Default

    Quote Originally Posted by K Baden View Post
    ((vla-put-color obj 255,255,255))
    according to documentations,
    object color property aci index 0-256 integer
    Code:
     (vla-put-color obj AcWhite)
    ;1=red 2=yellow 3=green 4=cyan 5=blue 6=magenta 7=white
    useful link color conversion
    lambda not optimized.. ( apply '= "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" ) ; error: too many arguments

  3. #3
    Full Member
    Using
    AutoCAD 2017
    Join Date
    Oct 2013
    Posts
    59

    Default

    Is there perhaps a way to hybrid this sort of code with this sort of code?
    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.

  4. #4
    Senior Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    457

    Default

    Try this:
    Code:
    (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)

  5. #5
    Full Member
    Using
    AutoCAD 2017
    Join Date
    Oct 2013
    Posts
    59

    Default

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

  6. #6
    Full Member
    Using
    AutoCAD 2017
    Join Date
    Oct 2013
    Posts
    59

    Default

    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)

  7. #7
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,745

    Default

    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.
    A man who never made mistakes never made anything

  8. #8
    Full Member
    Using
    AutoCAD 2017
    Join Date
    Oct 2013
    Posts
    59

    Default

    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.

    Code:
    (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)

  9. #9
    Full Member
    Using
    AutoCAD 2017
    Join Date
    Oct 2013
    Posts
    59

    Default

    I've added the highlighted line and I'm getting this error:
    Command: HW ; error: ActiveX Server returned the error: unknown name: Blocks

    Code:
    (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-ModelSpace (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)

  10. #10
    Senior Member devitg's Avatar
    Computer Details
    devitg's Computer Details
    Operating System:
    XP
    Monitor:
    VG2021WM VIEW SONIC
    Using
    AutoCAD 2008
    Join Date
    Apr 2005
    Location
    CORDOBA ARGENTINA
    Posts
    143

    Default

    Registered forum members do not see this ad.

    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.

Similar Threads

  1. change solid hatch
    By CAD in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 17th Aug 2017, 01:03 pm
  2. Change HATCH color Based on the number you input
    By ktbjx in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 7th Jul 2016, 05:50 pm
  3. Two-color solid hatch or two-color thick stripes hatch?
    By macklara in forum The CUI, Hatches, Linetypes, Scripts & Macros
    Replies: 6
    Last Post: 16th Jan 2013, 10:49 pm
  4. plot objects w/ solid color hatch and not show object lines: how?
    By Sudan in forum AutoCAD Beginners' Area
    Replies: 5
    Last Post: 31st Jan 2009, 02:15 am
  5. Change a solid fill to a shade of the solid color
    By hgruber in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 2
    Last Post: 24th Apr 2008, 01:49 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts