Jump to content

Lisp for Automatic Draw Order Command to a specific Layer.


stevsmith

Recommended Posts

here's for blocks:

 

 

(defun c:blklayerorder (/ od_blk od_ent)
   (vl-load-com)
   (foreach od_lay
                   (reverse '("LAYER1" ; topmost
                              "LAYER2"
                              "LAYER3" ; bottom
                             )
                   ) ;_ {reverse
       (if
           (tblsearch "LAYER" od_lay)
              (while
                  (setq od_blk (tblnext "block" (null od_blk)))
                     (setq od_ent (tblobjname "block" (cdr (assoc 2 od_blk))))
                     (while (Setq od_ent (entnext od_ent))
                         (if (eq (cdr (assoc 8 (entget od_ent))) (strcase od_lay))
                             (vl-catch-all-apply
                                 (function
                                     (lambda ()
                                         (vla-MoveTotop
                                             (vla-AddObject
                                                 (vla-GetExtensionDictionary
                                                     (vla-item
                                                         (vla-get-blocks
                                                             (vla-get-ActiveDocument
                                                                 (vlax-get-acad-object
                                                                 )
                                                             ) ;_ {vla-get-ActiveDocument
                                                         ) ;_ {vla-get-ModelSpace
                                                         (cdr (assoc 2 od_blk))
                                                     ) ;_ {vla-GetExtensionDictionary
                                                 ) ;_ {vla-GetExtensionDictionary
                                                 "ACAD_SORTENTS"
                                                 "AcDbSortentsTable"
                                             ) ;_ {vla-AddObject
                                             (vlax-make-variant
                                                 (vlax-safearray-fill
                                                     (vlax-make-safearray
                                                         vlax-vbobject
                                                         '(0 . 0)
                                                     ) ;_ {vlax-make-safearray
                                                     (list (vlax-ename->vla-object
                                                               od_ent
                                                           ) ;_ {vlax-ename->vla-object
                                                     ) ;_ {list
                                                 ) ;_ end of vlax-safearray-fill
                                             ) ;_ {vlax-make-variant
                                         ) ;_ {vla-MoveToTop
                                     ) ;_ {lambda
                                 ) ;_ {function
                             ) ;_ {vl-catch-all-apply
                         ) ;_ {if
                     ) ;_ {while
              ) ;_ {while
       ) ;_ {if
   ) ;_ {foreach
   (vla-regen (vla-get-activedocument (vlax-get-acad-object)) 1)
   (princ)
) ;_ {defun..........................................wiz23mar09....8-)

Link to comment
Share on other sites

  • Replies 31
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    12

  • ichlove

    9

  • wizman

    3

  • matinau

    2

A reactor is a type of LISP that runs without the user having to enter a syntax to the command line.

 

There are many types of reactors, you can assign them to objects, command calls, etc etc.

 

Now that Wizman has provided another option, it looks like a reactor is a possibility.

Link to comment
Share on other sites

Hi , wizman,thanks for the reply.But I tried , doesn't work.the command just show regenerating model:(.FYI,following are the effect I want . (would be better can make the order automatically,if needs any manual change ,stay the manual change)

 

Thanks

here's for blocks:

 

 

(defun c:blklayerorder (/ od_blk od_ent)
   (vl-load-com)
   (foreach od_lay
                   (reverse '("LAYER1" ; topmost
                              "LAYER2"
                              "LAYER3" ; bottom
                             )
                   ) ;_ {reverse
       (if
           (tblsearch "LAYER" od_lay)
              (while
                  (setq od_blk (tblnext "block" (null od_blk)))
                     (setq od_ent (tblobjname "block" (cdr (assoc 2 od_blk))))
                     (while (Setq od_ent (entnext od_ent))
                         (if (eq (cdr (assoc 8 (entget od_ent))) (strcase od_lay))
                             (vl-catch-all-apply
                                 (function
                                     (lambda ()
                                         (vla-MoveTotop
                                             (vla-AddObject
                                                 (vla-GetExtensionDictionary
                                                     (vla-item
                                                         (vla-get-blocks
                                                             (vla-get-ActiveDocument
                                                                 (vlax-get-acad-object
                                                                 )
                                                             ) ;_ {vla-get-ActiveDocument
                                                         ) ;_ {vla-get-ModelSpace
                                                         (cdr (assoc 2 od_blk))
                                                     ) ;_ {vla-GetExtensionDictionary
                                                 ) ;_ {vla-GetExtensionDictionary
                                                 "ACAD_SORTENTS"
                                                 "AcDbSortentsTable"
                                             ) ;_ {vla-AddObject
                                             (vlax-make-variant
                                                 (vlax-safearray-fill
                                                     (vlax-make-safearray
                                                         vlax-vbobject
                                                         '(0 . 0)
                                                     ) ;_ {vlax-make-safearray
                                                     (list (vlax-ename->vla-object
                                                               od_ent
                                                           ) ;_ {vlax-ename->vla-object
                                                     ) ;_ {list
                                                 ) ;_ end of vlax-safearray-fill
                                             ) ;_ {vlax-make-variant
                                         ) ;_ {vla-MoveToTop
                                     ) ;_ {lambda
                                 ) ;_ {function
                             ) ;_ {vl-catch-all-apply
                         ) ;_ {if
                     ) ;_ {while
              ) ;_ {while
       ) ;_ {if
   ) ;_ {foreach
   (vla-regen (vla-get-activedocument (vlax-get-acad-object)) 1)
   (princ)
) ;_ {defun..........................................wiz23mar09....8-)

sample.dwg

Link to comment
Share on other sites

that routine is for draworder of entities by layer inside blocks From your posted drawing, i think you're looking for draworder between blocks through their nested entities. if they are in different blocks, then they are in different spaces, ill see later if i can figure it out.

Link to comment
Share on other sites

Wizman, why is the function vla-MovetoTop not recognised in VLIDE?

 

lee, it is recognized when vl-load-com is iniatiated.

Link to comment
Share on other sites

  • 1 year later...

this is sweet! how can you add wildcards to the list i.e. *layer* etc? been trying to figure it out all day?

 

I suppose this?

 

(defun c:orderlay  (/ laylist ss)

 (setq laylist '("LAYER1"  ;  <---<< List Layers Here.
                 "LAYER2"
                 "LAYER3"
         ))
 
 (foreach lay laylist
   (if    (and (tblsearch "LAYER" lay)
        (setq ss (ssget "X" (list (cons 8 lay)))))
     (command "_draworder" ss "" "_F")))
 (princ))

Link to comment
Share on other sites

A quick modification would be this:

 

(defun c:OrderLay ( / laylist ss )

 (setq laylist '("LAYER1"  ;  <---<< List Layers Here.
                 "LAYER2"
                 "LAYER3"
 ))

 (foreach lay laylist
   (if (setq ss (ssget "_X" (list (cons 8 lay))))
     (command "_.draworder" ss "" "_F")
   )
 )

 (princ)
)

Link to comment
Share on other sites

An alternative approach:

 

LayerstoTop will order layers as specified in the list

 

Top will move a SelectionSet of objects to the Top.

 

Bot will move a SelectionSet of objects to the Bottom.

 

(defun LM:MovetoTop ( ss / ObjLst Sortents )
 (vl-load-com)
 ;; © Lee Mac 2010

 (setq ObjLst (LM:ss->vla ss))

 (if
   (setq Sortents
     (LM:SortentsTable
       (vla-ObjectIDtoObject
         (vla-get-ActiveDocument
           (vlax-get-acad-object)
         )
         (vla-get-OwnerID (car ObjLst))
       )
     )      
   )
   (vla-MovetoTop Sortents (LM:ObjectVariant ObjLst))
 )
)

(defun LM:MovetoBottom ( ss / ObjLst Sortents )
 (vl-load-com)
 ;; © Lee Mac 2010

 (setq ObjLst (LM:ss->vla ss))

 (if
   (setq Sortents
     (LM:SortentsTable
       (vla-ObjectIDtoObject
         (vla-get-ActiveDocument
           (vlax-get-acad-object)
         )
         (vla-get-OwnerID (car ObjLst))
       )
     )      
   )
   (vla-MovetoBottom Sortents (LM:ObjectVariant ObjLst))
 )
)

(defun LM:SortentsTable ( space / dict )
 (cond
   (
     (LM:CatchApply vla-item
       (list
         (setq dict
           (vla-GetExtensionDictionary space)
         )
        "ACAD_SORTENTS"
       )
     )
   )
   (
     (LM:CatchApply vla-AddObject
       (list dict "ACAD_SORTENTS" "AcDbSortentsTable")
     )
   )
 )
)

(defun LM:ss->vla ( ss )
 ;; © Lee Mac 2010
 (if ss
   (
     (lambda ( i / e l )
       (while (setq e (ssname ss (setq i (1+ i))))
         (setq l (cons (vlax-ename->vla-object e) l))
       )
       l
     )
     -1
   )
 )
)

(defun LM:CatchApply ( foo args / result )
 ;; © Lee Mac 2010
 (if
   (not
     (vl-catch-all-error-p
       (setq result
         (vl-catch-all-apply (function foo) args)
       )
     )
   )
   result
 )
)

(defun LM:SafearrayVariant ( datatype data )
 ;; © Lee Mac 2010
 (vlax-make-variant
   (vlax-safearray-fill
     (vlax-make-safearray datatype
       (cons 0 (1- (length data)))
     )
     data
   )    
 )
)

(defun LM:ObjectVariant ( lst )
 ;; © Lee Mac 2010
 (LM:SafearrayVariant vlax-vbobject lst)
)



;; -- Test Functions --

(defun c:top ( / ss )
 (vl-load-com)
 ;; © Lee Mac 2010

 (if (setq ss (ssget "_:L" (list (cons 410 (getvar 'CTAB)))))
   (LM:MovetoTop ss)
 )
 (princ)
)

(defun c:bot ( / ss )
 (vl-load-com)
 ;; © Lee Mac 2010

 (if (setq ss (ssget "_:L" (list (cons 410 (getvar 'CTAB)))))
   (LM:MovetoBottom ss)
 )
 (princ)
)

(defun c:LayerstoTop ( / order ss )
 (vl-load-com)
 ;; © Lee Mac 2010

 (setq order
   '(
      "Layer1" "Layer2" "Layer3"
    )
 )

 (foreach l (reverse order)
   (if (setq ss (ssget "_X" (list (cons 8 l) (cons 410 (getvar 'CTAB)))))
     (LM:MovetoTop ss)
   )
 )
 (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...