Results 1 to 5 of 5

Thread: Hatch closed polygon on a choosen layer

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2014-12
    Posts
    1
    Login to Give a bone
    0

    Red face Hatch closed polygon on a choosen layer

    Does anyone have or can write a LISP routine that will do the following:

    1. With select the layer from the layer name I input.
    2. Allow me the set the color for the solid pattern.
    3. Hatch all the closed polygon on the layer I called to be hatched.

    Any help would be greatly appreciated..... THANKS!!

  2. #2
    I could stop if I wanted to
    Join Date
    2015-12
    Posts
    385
    Login to Give a bone
    0

    Default Re: Hatch closed polygon on a choosen layer

    Crude but but here's an old one of mine slightly modified

    Code:
    (defun c:yay (/ ss1)  
      (setq ss1 (ssget '((0 . "LWPOLYLINE")(8 . "HATCH-BOUND"))))
      (if (/= ss1 nil)
        (progn
          
          (command "-hatch"
    	       "la" "HATCH-PATT"
    	       "P" "SOLID"
    	       "S" ss1
    	       "")
          ))  
      (princ))

  3. #3
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Hatch closed polygon on a choosen layer

    Try this draft and change the layer names as you require with the color number as well .

    Code:
    (defun c:Test (/ layers color ss)
      ;; Tharwat 04.12.2014    ;;
      (setq layers "Layer1,Layer2,Layer3" ;; <= Layer names
            color  1      ;; <= Color number between 1 to 256 
      )
      (if (setq ss (ssget "_X"
                          (list '(0 . "LWPOLYLINE")
                                (cons 8 layers)
                                '(-4 . "&=")
                                '(70 . 1)
                          )
                   )
          )
        ((lambda (i / sn h)
           (while (setq sn (ssname ss (setq i (1+ i))))
             (setq
               h (vla-addhatch
                   (vlax-get
                     (vla-get-activelayout
                       (vla-get-ActiveDocument (vlax-get-acad-object))
                     )
                     'block
                   )
                   acHatchPatternTypePredefined
                   "SOLID"
                   :vlax-true
                 )
             )
             (vlax-invoke
               h
               'AppendOuterLoop
               (list (vlax-ename->vla-object sn))
             )
             (vlax-invoke h 'Evaluate)
             (vla-put-color h color)
           )
         )
          -1
        )
      )
      (princ)
    )(vl-load-com)

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Hatch closed polygon on a choosen layer

    Quote Originally Posted by Tharwat View Post
    Try this draft and change the layer names as you require with the color number as well .

    Code:
    (defun c:Test (/ layers color ss)
      ;; Tharwat 04.12.2014    ;;
      (setq layers "Layer1,Layer2,Layer3" ;; <= Layer names
            color  1      ;; <= Color number between 1 to 256 
      )
      (if (setq ss (ssget "_X"
                          (list '(0 . "LWPOLYLINE")
                                (cons 8 layers)
                                '(-4 . "&=")
                                '(70 . 1)
                          )
                   )
          )
        ((lambda (i / sn h)
           (while (setq sn (ssname ss (setq i (1+ i))))
             (setq
               h (vla-addhatch
                   (vlax-get
                     (vla-get-activelayout
                       (vla-get-ActiveDocument (vlax-get-acad-object))
                     )
                     'block
                   )
                   acHatchPatternTypePredefined
                   "SOLID"
                   :vlax-true
                 )
             )
             (vlax-invoke
               h
               'AppendOuterLoop
               (list (vlax-ename->vla-object sn))
             )
             (vlax-invoke h 'Evaluate)
             (vla-put-color h color)
           )
         )
          -1
        )
      )
      (princ)
    )(vl-load-com)
    FWIW -

    If using Visual LISP Methods, you'd simplify (and speed up) your code to use vlax-For on the ActiveDocument's ActiveSelectionSet Property, in lieu of WHILE + SSNAME + vlax-Ename->vla-Object.

    Also, you can store the ActiveLayout's Block once prior to iterating the Selection Set.

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #5
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Hatch closed polygon on a choosen layer

    Quote Originally Posted by BlackBox View Post
    FWIW -

    If using Visual LISP Methods, you'd simplify (and speed up) your code to use vlax-For on the ActiveDocument's ActiveSelectionSet Property, in lieu of WHILE + SSNAME + vlax-Ename->vla-Object.

    Also, you can store the ActiveLayout's Block once prior to iterating the Selection Set.

    Cheers
    Absolutely right and many thanks for the notes .
    like.jpg

Similar Threads

  1. LISP to create layer, hatch and set layer back to original.
    By jpcadconsulting347236 in forum AutoLISP
    Replies: 1
    Last Post: 2013-12-11, 07:22 PM
  2. How to hatch closed Plines
    By Ukemi72 in forum Dot Net API
    Replies: 13
    Last Post: 2013-08-13, 07:24 PM
  3. "IF you want to hatch an area whose boundary is not quite closed"
    By Sureshrrai in forum AutoCAD Tips & Tricks
    Replies: 14
    Last Post: 2013-06-11, 01:58 PM
  4. Replies: 0
    Last Post: 2008-02-27, 10:08 PM
  5. Stretch a Polygon/Maintain the Original Area of Polygon
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2007-08-02, 04:39 PM

Tags for this Thread

Posting Permissions

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