wizman Posted March 23, 2009 Share Posted March 23, 2009 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-) Quote Link to comment Share on other sites More sharing options...
ichlove Posted March 23, 2009 Share Posted March 23, 2009 Sorry,what is reactor? a lisp? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 23, 2009 Share Posted March 23, 2009 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. Quote Link to comment Share on other sites More sharing options...
ichlove Posted March 23, 2009 Share Posted March 23, 2009 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 Quote Link to comment Share on other sites More sharing options...
wizman Posted March 23, 2009 Share Posted March 23, 2009 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 23, 2009 Share Posted March 23, 2009 Wizman, why is the function vla-MovetoTop not recognised in VLIDE? Quote Link to comment Share on other sites More sharing options...
wizman Posted March 23, 2009 Share Posted March 23, 2009 Wizman, why is the function vla-MovetoTop not recognised in VLIDE? lee, it is recognized when vl-load-com is iniatiated. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 23, 2009 Share Posted March 23, 2009 It is still black on my screen, even with vl-load-com initiated Quote Link to comment Share on other sites More sharing options...
matinau Posted July 8, 2010 Share Posted July 8, 2010 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)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 8, 2010 Share Posted July 8, 2010 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) ) Quote Link to comment Share on other sites More sharing options...
matinau Posted July 8, 2010 Share Posted July 8, 2010 Ah...so simple - works like a charm cheers Lee Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 9, 2010 Share Posted July 9, 2010 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) ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.