+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Senior Member 3dwannab's Avatar
    Computer Details
    3dwannab's Computer Details
    Operating System:
    Windows 7 Ultimate x64
    Computer:
    Self-Built
    Motherboard:
    Rampage II Extreme
    CPU:
    Intel(R) Core(TM) i7 CPU 965 @ 3.20GHz
    RAM:
    Corsair 12GB DDR3 XMS3 PC3-12800C9 1600MHz
    Graphics:
    ATI Radeon HD 4870 X2
    Primary Storage:
    512GB SSD
    Secondary Storage:
    2 x WD VelociRaptor 1000 GB Hard Drives @ 7,200RPM
    Monitor:
    32" HP LP3065 Wide LCD Moniter + 24" Dell
    Discipline
    Architectural
    3dwannab's Discipline Details
    Occupation
    arch technician and arch viz
    Discipline
    Architectural
    Details
    Office Tea Maker
    Using
    AutoCAD 2017
    Join Date
    Jun 2012
    Location
    Ireland
    Posts
    118

    Default Select Hatch by background color

    Registered forum members do not see this ad.

    I've wrote a function to select hatches based on their layer layColor patName patScale

    What I'm missing is getting the DXF data on ssget for the vla-get-backgroundcolor

    As I'm not sure if this is exposed to the DXF.

    Any help would be appreciated. Thanks.


    Code:
    ;
    ; Select hatches on same layer & pattern by 3dwannab
    ;
    ; v0.1 - 16.03.2017
    ; Usage: Select hatch to select other hatches on similar bkgCol color layer patName patScale
    
    (defun c:TEST nil (c:QS_HATCH_SAME_Layer_PatternName_PatternScale_Color_&_BkgColor))
    (defun c:QS_HATCH_SAME_Layer_PatternName_PatternScale_Color_&_BkgColor ( / ss ssdata layer layColor patName patScale bkgCol)
    
    	(while
    		(not
    			(and
    				(setq
    					ss (car (entsel "\nSelect Hatch to get same Hatch entities as:\nlayer layColor patName patScale bkgCol: "))
    					ssdata (if ss (entget ss))
    					)
    
    				(= (cdr (assoc 0 ssdata)) "HATCH")
    
    				(sssetfirst nil)
    
    				(setq ss (vlax-ename->vla-object ss))
    
    				(progn
    
    					(setq
    						bkgCol (vla-get-backgroundcolor ss)
    						layColor (vla-get-color ss)
    						layer (vla-get-Layer ss)
    						patName (vla-get-PatternName ss)
    						patScale (vla-get-PatternScale ss)
    						)
    
    					(setq ss (ssget "X" (list (cons 8 layer) '(0 . "HATCH") (cons 2 patName) (cons 62 layColor) (cons 41 patScale) (cons 410 (getvar 'ctab)))))
    					(princ (strcat "\n   >>>   " (itoa (setq len (sslength ss))) (if (> len 1) " items" " item") " selected   <<<   "))
    
    					(sssetfirst nil ss)(princ)
    
    					)
    
    				)
    			)
    		(prompt "\n   >>>   Nothing selected, or please select a hatch !   <<<   ")
    
    		)
    
    	(princ)
    	)
    (vl-load-com)
    (princ "\n:: QS_HATCH_SAME_Layer_PatternName_PatternScale_Color_&_BkgColor.lsp | Version 1.0 | by 3dwannab ::")
    (princ "\n:: Type \"QS_HATCH_SAME_Layer_PatternName_PatternScale_Color_&_BkgColor\" OR \"TEST\" to Invoke ::") (princ)

  2. #2
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,080

    Default

    Alternative solution would be to iterate over the SS, construct a new SS and populate it with the hatches that match the criteria:
    Code:
    (defun C:test ( / e bkgColidx SS nSS i )
      (and 
        (setq e (car (entsel "\nSelect source hatch: ")))
        (= "HATCH" (cdr (assoc 0 (entget e))))
        (setq bkgColidx (vla-get-ColorIndex (vla-get-BackgroundColor (vlax-ename->vla-object e))))
        (setq SS (ssget "_X" (list '(0 . "HATCH")(cons 410 (getvar 'ctab)))))
        (progn
          (setq nSS (ssadd))
          (repeat (setq i (sslength SS))
            (and
              (setq e (ssname SS (setq i (1- i))))
              (= bkgColidx (vla-get-ColorIndex (vla-get-BackgroundColor (vlax-ename->vla-object e))))
              (ssadd e nSS)
            ); and
          ); repeat
          (sssetfirst nil nSS)
        ); progn
      ); and
      (princ)
    ) (vl-load-com) (princ)
    The above should select the hatches with the same background index color, else you could use a RGB list for comparsion:
    Code:
    (setq RGB (mapcar '(lambda (x) (vlax-get (vla-get-BackgroundColor o) x)) '(Green Blue Red)))
    As for the DXF, perhaps wait for the professor.

  3. #3
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,053

    Default

    Hi,
    Have a look at the Xdata of the Hatch object before and after adding background colour.

  4. #4
    Senior Member 3dwannab's Avatar
    Computer Details
    3dwannab's Computer Details
    Operating System:
    Windows 7 Ultimate x64
    Computer:
    Self-Built
    Motherboard:
    Rampage II Extreme
    CPU:
    Intel(R) Core(TM) i7 CPU 965 @ 3.20GHz
    RAM:
    Corsair 12GB DDR3 XMS3 PC3-12800C9 1600MHz
    Graphics:
    ATI Radeon HD 4870 X2
    Primary Storage:
    512GB SSD
    Secondary Storage:
    2 x WD VelociRaptor 1000 GB Hard Drives @ 7,200RPM
    Monitor:
    32" HP LP3065 Wide LCD Moniter + 24" Dell
    Discipline
    Architectural
    3dwannab's Discipline Details
    Occupation
    arch technician and arch viz
    Discipline
    Architectural
    Details
    Office Tea Maker
    Using
    AutoCAD 2017
    Join Date
    Jun 2012
    Location
    Ireland
    Posts
    118

    Default

    Quote Originally Posted by Grrr View Post
    Alternative solution would be to iterate over the SS, construct a new SS and populate it with the hatches that match the criteria:
    Code:
    (defun C:test ( / e bkgColidx SS nSS i )
      (and 
        (setq e (car (entsel "\nSelect source hatch: ")))
        (= "HATCH" (cdr (assoc 0 (entget e))))
        (setq bkgColidx (vla-get-ColorIndex (vla-get-BackgroundColor (vlax-ename->vla-object e))))
        (setq SS (ssget "_X" (list '(0 . "HATCH")(cons 410 (getvar 'ctab)))))
        (progn
          (setq nSS (ssadd))
          (repeat (setq i (sslength SS))
            (and
              (setq e (ssname SS (setq i (1- i))))
              (= bkgColidx (vla-get-ColorIndex (vla-get-BackgroundColor (vlax-ename->vla-object e))))
              (ssadd e nSS)
            ); and
          ); repeat
          (sssetfirst nil nSS)
        ); progn
      ); and
      (princ)
    ) (vl-load-com) (princ)
    The above should select the hatches with the same background index color, else you could use a RGB list for comparsion:
    Code:
    (setq RGB (mapcar '(lambda (x) (vlax-get (vla-get-BackgroundColor o) x)) '(Green Blue Red)))
    As for the DXF, perhaps wait for the professor.
    Thanks for going to the trouble of writing that for me. Is there any way to test how quick a fn is to compare them?

    But it's always good to start my collection of code snippets. Thank you.

    Quote Originally Posted by Tharwat View Post
    Hi,
    Have a look at the Xdata of the Hatch object before and after adding background colour.
    Interesting. I have a fn (don't know where, as I've had it a long time) and never used it.
    Code:
    ;;  get entity list of user picked entity
    ;;  plus related objects
    (defun c:myentget+ (/ ent elst)
    	(if (and (setq ent (car (entsel "\nSelect entity to list.")))
    		(setq elst (entget ent '("*"))))
    	(progn
    		(textscr)
    		(princ "\n>>>------>  ")
    		(princ (vlax-ename->vla-object ent))
    		(mapcar 'print elst)
    		(mapcar
    			'(lambda(x / slst)
    				(if (and (assoc x elst)
    					(setq slst (entget (cdr (assoc x elst)))))
    				(progn
    					(prompt (strcat "\n\n*******  Dump DXF "(itoa x)" listing  *********"))
    					(foreach n slst (print n))
    					)
    				)
    				)
    		'(330 340)) ; '(320 330 340 350 360))
    		)
    	)
    	(princ)
    	)
    and checked that. I missed this earlier. So, I've got this portion of data back :
    Code:
    (-3 ("HATCHBACKGROUNDCOLOR" (1071 . -1023410170) (1000 . "") (1000 . "")) ("GradientColor1ACI" (1070 . 5)) ("GradientColor2ACI" (1070 . 2)) ("ACAD" (1010 0.0 0.0 0.0)))
    For the life of me I don't know what to do with it or how to use that in the filter for ssget.

    My ssget _X now looks like (this is probably way off)
    Code:
    (setq ss (ssget "X" (list (cons 8 layer) '(0 . "HATCH") (cons 2 patName) (cons 1071 bkgCol) (cons 62 layColor) (cons 41 patScale) (cons 410 (getvar 'ctab)))))

  5. #5
    Senior Member 3dwannab's Avatar
    Computer Details
    3dwannab's Computer Details
    Operating System:
    Windows 7 Ultimate x64
    Computer:
    Self-Built
    Motherboard:
    Rampage II Extreme
    CPU:
    Intel(R) Core(TM) i7 CPU 965 @ 3.20GHz
    RAM:
    Corsair 12GB DDR3 XMS3 PC3-12800C9 1600MHz
    Graphics:
    ATI Radeon HD 4870 X2
    Primary Storage:
    512GB SSD
    Secondary Storage:
    2 x WD VelociRaptor 1000 GB Hard Drives @ 7,200RPM
    Monitor:
    32" HP LP3065 Wide LCD Moniter + 24" Dell
    Discipline
    Architectural
    3dwannab's Discipline Details
    Occupation
    arch technician and arch viz
    Discipline
    Architectural
    Details
    Office Tea Maker
    Using
    AutoCAD 2017
    Join Date
    Jun 2012
    Location
    Ireland
    Posts
    118

    Default

    Registered forum members do not see this ad.

    Never did find a way to get the HATCHBACKGROUND DXF code filtered in the ssget.

    Just went with this instead with the help of GRRRs code.

    Code:
    ;; Select HATCH by: Layer, Pattern Name, Pattern Scale, Colour & Background Colour
    ;; by 3dwannb on 11.04.17
    ;;
    ;; Help by GRRR: http://www.cadtutor.net/forum/showthread.php?100136-Select-Hatch-by-background-color&p=681038&viewfull=1#post681038
    ;;
    ;; Known Bugs: None
    ;;
    (defun c:QS_HLPSCB nil (c:QS_HATCH_SAME_Layer_PatternName_PatternScale_Color_&_BkgColor))
    (defun c:QS_HATCH_SAME_Layer_PatternName_PatternScale_Color_&_BkgColor ( /
    	bkgCol
    	layColor
    	layer
    	patName
    	patScale
    	ss
    	nSS
    	ssdata
    	)
    (while
    	(not
    		(and
    			(setq
    				ss (car (entsel "\nSelect Hatch to get same Hatch entities as:\nLayer, Pattern Name, Pattern Scale, Colour & Background Colour :"))
    				ssdata (if ss (entget ss))
    				)
    			(= (cdr (assoc 0 ssdata)) "HATCH")
    			(sssetfirst nil)
    			(setq ss (vlax-ename->vla-object ss))
    			(progn
    				(setq
    					bkgCol (vla-get-backgroundcolor ss)
    					bkgCol (vla-get-ColorIndex (vla-get-BackgroundColor ss))
    					layColor (vla-get-color ss)
    					layer (vla-get-Layer ss)
    					patName (vla-get-PatternName ss)
    					patScale (vla-get-PatternScale ss)
    					ss (ssget "X" (list (cons 8 layer) '(0 . "HATCH") (cons 2 patName) (cons 62 layColor) (cons 41 patScale) (cons 410 (getvar 'ctab))))
    					nSS (ssadd)
    					)
    				(repeat (setq i (sslength ss))
    					(and
    						(setq e (ssname ss (setq i (1- i))))
    						(= bkgCol (vla-get-ColorIndex (vla-get-BackgroundColor (vlax-ename->vla-object e))))
    						(ssadd e nSS)
    						)
    					)
    				(princ (strcat "\n   >>>   " (itoa (setq len (sslength nSS))) (if (> len 1) " items" " item") " selected   <<<   "))
    				(sssetfirst nil nSS)
    				)
    			)
    		)
    	(prompt "\n   >>>   Nothing selected or not a Hatch !   <<<   ")
    	)
    (princ)
    )
    (vl-load-com)
    (princ "\n:: QS_HATCH_SAME_Layer_PatternName_PatternScale_Color_&_BkgColor.lsp | Version 1.0 | by 3dwannab ::")
    (princ "\n:: Type \"QS_HATCH_SAME_Layer_PatternName_PatternScale_Color_&_BkgColor\" OR \"QS_HLPSCB\" to Invoke ::") (princ)

Similar Threads

  1. set layer color as the layout background color
    By samifox in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 18th May 2016, 04:21 pm
  2. 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
  3. hatch text background color
    By betina490 in forum The CUI, Hatches, Linetypes, Scripts & Macros
    Replies: 2
    Last Post: 4th Nov 2012, 10:28 am
  4. Background Color while in Sun & Sky
    By Nick@TE-Direct in forum AutoCAD 3D Modelling & Rendering
    Replies: 17
    Last Post: 29th Dec 2011, 05:56 pm
  5. AutoCAD Layout Background Color to Solid Black or Other Color
    By Between the Lines in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 14th Jul 2010, 09:20 pm

Tags for this Thread

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