Jump to content

Setting Layer draworder within a dynamic block


rcb007

Recommended Posts

I was looking around and found the Hatch to Back (by Mr. Lee Mac) which does a great job. I did not know if anyone may have seen one which worked with predefined layer names or not.

 

(defun c:test ( / acblk acdoc acsel name obj processed )
 ;; Lee Mac 17.06.11

 (setq acdoc (vla-get-activedocument (vlax-get-acad-object))
       acblk (vla-get-blocks acdoc)
 )
 (if (ssget '((0 . "INSERT")))
   (progn
     (vlax-for block (setq acsel (vla-get-activeselectionset acdoc))
       (if (not (member (setq name (vla-get-name block)) processed))
         (
           (lambda ( / lst )
             (vlax-for obj (vla-item acblk name)
               (if (eq "AcDbHatch" (vla-get-objectname obj))
                 (setq lst (cons obj lst))
               )
             )
             (if lst
               (vla-movetobottom (LM:SortentsTable (vla-item acblk name))
                 (vlax-make-variant
                   (vlax-safearray-fill
                     (vlax-make-safearray vlax-vbobject (cons 0 (1- (length lst)))) lst
                   )
                 )
               )
             )
             (setq processed (cons name processed))
           )
         )
       )
     )
     (vla-delete acsel)
     (vla-regen  acdoc acallviewports)
   )
 )
 (princ)
)

(defun LM:SortentsTable ( space / dict result ) 
 (cond
   (
     (not
       (vl-catch-all-error-p
         (setq result
           (vl-catch-all-apply 'vla-item
             (list (setq dict (vla-GetExtensionDictionary space)) "ACAD_SORTENTS")
           )
         )
       )
     )
     result
   )
   ( (vla-AddObject dict "ACAD_SORTENTS" "AcDbSortentsTable") )
 )
)
(vl-load-com) (princ)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...