<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Lisp to set solid hatches to bylayer in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-set-solid-hatches-to-bylayer/m-p/5966258#M135596</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@KerryBrown wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
....
&lt;PRE&gt;  ;; select ALL the applicable hatches
....  
  ;; convert the selection set to a list of ActiveX objects
....
  ;; make the layer (assume it doesn't exixts )
....
  ;; assign the HATCH layer to each object
....&lt;BR /&gt;  ;; set the color of each hatch object to 252
....&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is a situation in which a (command) function has&amp;nbsp;advantages over the VLA-Property approach. &amp;nbsp;The CHPROP command can change the Layer or the color &lt;EM&gt;or both&lt;/EM&gt; of a whole selection all at once, rather than one at a time, and without the need to convert them to VLA objects, and with far fewer variables. &amp;nbsp;Assuming the Layer does not yet exist [you can eliminate that line&amp;nbsp;if it always will]:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun c:doit (/ ss)
  (if (setq ss (ssget "X" '((0 . "HATCH") (2 . "SOLID"))))&lt;BR /&gt;    (command ; then&lt;BR /&gt;      "_layer" "_make" "HATCH" "_color" 252 "" ""&lt;BR /&gt;      "_chprop" ss "" "_layer" "HATCH" "_color" "_bylayer" ""&lt;BR /&gt;    ); command&lt;BR /&gt;  ); if
  (princ)
)&lt;/PRE&gt;
&lt;P&gt;Or, if you want to assign the color 252 by color override on the objects, rather than by putting them on a Layer with that color, just this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun c:doit (/ ss)
  (if (setq ss (ssget "_X" '((0 . "HATCH") (2 . "SOLID"))))&lt;BR /&gt;    (command "_chprop" ss "" "_color" 252 ""); then&lt;BR /&gt;  ); if
  (princ)
)&lt;/PRE&gt;
&lt;P&gt;If you know there &lt;EM&gt;will always be&lt;/EM&gt; such Hatch patterns when you run it, you don't even need any&amp;nbsp;variables at all. &amp;nbsp;Back to the by-the-Layer's-color approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun c:doit ()
  (command&lt;BR /&gt;    "_layer" "_make" "HATCH" "_color" 252 "" ""&lt;BR /&gt;    "_chprop" (ssget "_X" '((0 . "HATCH") (2 . "SOLID"))) "" "_layer" "HATCH" "_color" "_bylayer" ""&lt;BR /&gt;  ); command&lt;BR /&gt;  (princ)&lt;BR /&gt;)&lt;/PRE&gt;
&lt;P&gt;However, the VLA-Property approach will work on things in &lt;EM&gt;multiple spaces&lt;/EM&gt;, whereas the CHPROP approach&amp;nbsp;will work only on&amp;nbsp;Hatch patterns in the &lt;EM&gt;current&lt;/EM&gt; space. &amp;nbsp;So if you might have such patterns in &lt;EM&gt;both&lt;/EM&gt; Model and Paper space, or in &lt;EM&gt;different&lt;/EM&gt; Paper space Layouts, don't do it with CHPROP.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Dec 2015 14:47:46 GMT</pubDate>
    <dc:creator>Kent1Cooper</dc:creator>
    <dc:date>2015-12-28T14:47:46Z</dc:date>
    <item>
      <title>Lisp to set solid hatches to bylayer</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-set-solid-hatches-to-bylayer/m-p/5965716#M135594</link>
      <description>Please help me by providing a lisp that can set all solid hatches to bylayer, preferably color 252</description>
      <pubDate>Sun, 27 Dec 2015 18:30:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-set-solid-hatches-to-bylayer/m-p/5965716#M135594</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-12-27T18:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Lisp to set solid hatches to bylayer</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-set-solid-hatches-to-bylayer/m-p/5965907#M135595</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DXF group Code &amp;nbsp;62 indicates&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;Color number (present if not BYLAYER);&lt;/P&gt;
&lt;P&gt;zero indicates the BYBLOCK (floating) color;&lt;/P&gt;
&lt;P&gt;256 indicates BYLAYER;&lt;/P&gt;
&lt;P&gt;a negative value indicates that the layer is turned off (optional)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the option you want is either/or &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;256 for BYLAYER&amp;nbsp;&lt;/P&gt;
&lt;P&gt;252 for the color you mentioned&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can't have both.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a play with something like this :&lt;/P&gt;
&lt;PRE&gt;(defun c:doit (/ ss collection n hatch layerObj)
  
  ;; select ALL the applicable hatches
  (setq ss         (ssget "X" '((0 . "HATCH") (2 . "SOLID")))
        collection nil
  )
  
  ;; convert the selection set to a list of ActiveX objects
  (if ss
    (repeat (setq n (sslength ss))
      (setq collection (cons (vlax-ename-&amp;gt;vla-object
                               (ssname ss (setq n (1- n)))
                             )
                             collection
                       )
      )
    )
  )

  ;; make the layer (assume it doesn't exixts )
  
  (setq layerObj
         (vla-Add (vla-get-Layers
                    (vla-get-ActiveDocument (vlax-get-acad-object))
                  )
                  "HATCH"
         )
  )

  ;; assign the HATCH layer to each object
  (foreach hatch collection (vla-put-layer hatch "HATCH"))
  
  ;; set the color of each hatch object to 252
  (foreach hatch collection (vla-put-Color hatch 252))
  (princ)
)
(princ)&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Dec 2015 02:19:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-set-solid-hatches-to-bylayer/m-p/5965907#M135595</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2015-12-28T02:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: Lisp to set solid hatches to bylayer</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-set-solid-hatches-to-bylayer/m-p/5966258#M135596</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@KerryBrown wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
....
&lt;PRE&gt;  ;; select ALL the applicable hatches
....  
  ;; convert the selection set to a list of ActiveX objects
....
  ;; make the layer (assume it doesn't exixts )
....
  ;; assign the HATCH layer to each object
....&lt;BR /&gt;  ;; set the color of each hatch object to 252
....&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is a situation in which a (command) function has&amp;nbsp;advantages over the VLA-Property approach. &amp;nbsp;The CHPROP command can change the Layer or the color &lt;EM&gt;or both&lt;/EM&gt; of a whole selection all at once, rather than one at a time, and without the need to convert them to VLA objects, and with far fewer variables. &amp;nbsp;Assuming the Layer does not yet exist [you can eliminate that line&amp;nbsp;if it always will]:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun c:doit (/ ss)
  (if (setq ss (ssget "X" '((0 . "HATCH") (2 . "SOLID"))))&lt;BR /&gt;    (command ; then&lt;BR /&gt;      "_layer" "_make" "HATCH" "_color" 252 "" ""&lt;BR /&gt;      "_chprop" ss "" "_layer" "HATCH" "_color" "_bylayer" ""&lt;BR /&gt;    ); command&lt;BR /&gt;  ); if
  (princ)
)&lt;/PRE&gt;
&lt;P&gt;Or, if you want to assign the color 252 by color override on the objects, rather than by putting them on a Layer with that color, just this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun c:doit (/ ss)
  (if (setq ss (ssget "_X" '((0 . "HATCH") (2 . "SOLID"))))&lt;BR /&gt;    (command "_chprop" ss "" "_color" 252 ""); then&lt;BR /&gt;  ); if
  (princ)
)&lt;/PRE&gt;
&lt;P&gt;If you know there &lt;EM&gt;will always be&lt;/EM&gt; such Hatch patterns when you run it, you don't even need any&amp;nbsp;variables at all. &amp;nbsp;Back to the by-the-Layer's-color approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(defun c:doit ()
  (command&lt;BR /&gt;    "_layer" "_make" "HATCH" "_color" 252 "" ""&lt;BR /&gt;    "_chprop" (ssget "_X" '((0 . "HATCH") (2 . "SOLID"))) "" "_layer" "HATCH" "_color" "_bylayer" ""&lt;BR /&gt;  ); command&lt;BR /&gt;  (princ)&lt;BR /&gt;)&lt;/PRE&gt;
&lt;P&gt;However, the VLA-Property approach will work on things in &lt;EM&gt;multiple spaces&lt;/EM&gt;, whereas the CHPROP approach&amp;nbsp;will work only on&amp;nbsp;Hatch patterns in the &lt;EM&gt;current&lt;/EM&gt; space. &amp;nbsp;So if you might have such patterns in &lt;EM&gt;both&lt;/EM&gt; Model and Paper space, or in &lt;EM&gt;different&lt;/EM&gt; Paper space Layouts, don't do it with CHPROP.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Dec 2015 14:47:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-set-solid-hatches-to-bylayer/m-p/5966258#M135596</guid>
      <dc:creator>Kent1Cooper</dc:creator>
      <dc:date>2015-12-28T14:47:46Z</dc:date>
    </item>
  </channel>
</rss>

