See the top rated post in this thread. Click here

Results 1 to 4 of 4

Thread: Move Hatches to specific layer

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

    Default Move Hatches to specific layer

    Hi I hope someone can help me here.
    I have a drawing with 300 or so blocks most of which have some sort of hatching.

    Does someone know of or could someone write a lisp routine that would select all hatches (including within the blocks) and move the to a specified layer?

    It sounds fairly simple task but I am not very experienced in Autocad. I have been trying to learn how to a write lisp routine but admittedly I am completely hopeless. I have been searching forums and the closest lisp I have found is this one but seems to only move hatches with colour set to bylayer.

    I would really appreciate any help someone could give me here.
    Thanks

  2. #2
    100 Club
    Join Date
    2000-11
    Location
    Ontario, Canada
    Posts
    116
    Login to Give a bone
    1

    Default Re: Move Hatches to specific layer

    Here's a basic function that should do what you are asking:

    Code:
    (defun htchlay (lynm )
      (or activedocument
          (setq activedocument (vlax-get-property (vlax-get-acad-object) 'activedocument))
          ); or
      (or blocks
          (setq blocks (vlax-get-property activedocument 'blocks))
          ); or
      (or layers
          (setq layers (vlax-get-property activedocument 'layers))
          ); or
      (if (not
    	(vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list layers lynm)))
    	); not
        (progn
          (vlax-for x blocks
    	(vlax-for n x
    	  (if (equal "AcDbHatch" (vlax-get-property n 'objectname))
    	    (vl-catch-all-apply 'vlax-put-property (list n 'layer lynm))
    	    ); if
    	  ); vlax-for
    	); vlax-for
          ); progn
        ); if
      (vl-cmdf "regen")
      (princ)
      ); defun
    Pass it the name of an existing layer, thus:

    Code:
    (htchlay  "0")

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

    Default Re: Move Hatches to specific layer

    This accounts for locked layers, error handling, and supports UNDO functionality as well:

    Code:
    (vl-load-com)
    
    (defun _FOO (layerName / *error* acDoc oLayers layer oLayer lock)
    
      (defun *error* (msg)
        (foreach oLayer lock
          (vla-put-lock oLayer :vlax-true)
        )
        (if acDoc
          (progn
            (vla-endundomark acDoc)
            (vla-regen acDoc acallviewports)
          )
        )
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
        )
        (princ)
      )
    
      (vla-startundomark
        (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
      )
      (setq oLayers (vla-get-layers acDoc))
      (vlax-for block (vla-get-blocks acDoc)
        (vlax-for x block
          (if
            (and
              (= "AcDbHatch" (vla-get-objectname x))
              (/= layerName (setq layer (vla-get-layer x)))
            )
             (progn
               (if
                 (= :vlax-true
                    (vla-get-lock (setq oLayer (vla-item oLayers layer)))
                 )
                  (progn
                    (setq lock (cons oLayer lock))
                    (vla-put-lock oLayer :vlax-false)
                  )
               )
               (vla-put-layer x layerName)
             )
          )
        )
      )
      (*error* nil)
    )

    Note - You may still receive associative hatch messages for boundary objects on locked layers.


    Cheers
    Last edited by BlackBox; 2014-07-02 at 06:41 PM.
    "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

  4. #4
    Member
    Join Date
    2012-12
    Posts
    10
    Login to Give a bone
    0

    Default Re: Move Hatches to specific layer

    Hello!
    could your lisp work upon selected blocks, instead of all in drawing?
    Best regards,
    Last edited by mikitari; 2019-05-27 at 09:21 AM.

Similar Threads

  1. Move and lock the text in specific blocks
    By Wish List System in forum AutoCAD Wish List
    Replies: 3
    Last Post: 2014-05-26, 06:24 PM
  2. 2012: Autocad LT not able to move an entity along a line a specific distance
    By josh829675 in forum AutoCAD LT - General
    Replies: 5
    Last Post: 2013-01-16, 04:53 PM
  3. Xref only Specific Layer
    By rmjcorp596401 in forum AutoCAD General
    Replies: 4
    Last Post: 2012-02-23, 01:18 PM
  4. Dim Text on Specific Layer instead of having Specific Color
    By Masroor Javid in forum ACA Wish List
    Replies: 0
    Last Post: 2009-02-23, 09:34 AM

Posting Permissions

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