So I have been trying to figure this out with several approaches now and I need some help.
I would like to send all Wipeouts, or really any specified entity type, within a block to the back of the draw order.
Is there a way to do this using Lee Mac's Apply To Block Objects routine? I tried this in conjunction with his draw order routines but the MovetoBottom command kept failing. I'm pretty rough with VisualLisp which is part of the issue when trying to troubleshoot his great routines.
Or what about this approach? (I dont really understand it, again Viusal Lisp)
Below is what I tried.
I do understand Vanilla Lisp. Visual Lisp I barely know the basics, but eager to learn.
Please help me improve my capabilities. Thank you.
(defun c:test ( / s )
(princ "\nSelect Block: ")
(if (setq s (ssget "_+.:E:S" '((0 . "INSERT"))))
(LM:ApplytoBlockObjects
(vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
(vla-get-effectivename (vlax-ename->vla-object (ssname s 0)))
'(lambda ( obj ) (BG:WipeoutToBottom))
)
)
(princ)
)
(vl-load-com) (princ)
(defun BG:WipeoutToBottom( / )
(LM:movetobottom (ssget "X" '((0 . "WIPEOUT"))))
;(princ)
);end of defun
;===============Below here are Lee's draw order functions==============
Are you having issues with blocks that were existing already and block edited to add the wipeout? Or possibly new block definitions where you created all the linework needed then added the wipeout at the very end? I learned you can’t do wipeouts last.
I was recently asked to add wipeouts to certain blocks we use. All of our block content is made accessible to users via the tool palette, which calls the block definition from a cad standards drawing located on our server. I noticed when I added the wipeout to the block after all other linework was created, even though I would send it behind all objects in the block, the wipeout would wind up returning to front when inserting into a new drawing. Thru trial and error, I found that wipeouts needed to be created before all other linework in the block. To fix the issue in existing blocks I used this method:
This ensures that the wipeout stays behind everything else. You would think draworder would work here but it does not. It may have something to do with how AutoCAD inserts/recreates the block. AutoCAD seems to respect some sort of “linework history” when inserting into new files.
As to how to fix this with lisp I have not yet come up with a solution.
@bgumPXZJF wrote:
So I have been trying to figure this out with several approaches now and I need some help.
I would like to send all Wipeouts, or really any specified entity type, within a block to the back of the draw order.
What you're saying is you havea code for sending the wipeout to bottom but you need one that works inside blocks?
While you're at it, change the wipeout object to solid hatch as @pendean suggested prorgramatically.
Will that work for you?
So someone responded to this with the correct code to use based off the code that I provided. It appears they have since deleted their post. However this is the lisp based solution. Notice that it targets both normal blocks and anonymous blocks.
Note: If you are having draw order save issue make sure that you have the 2019 update for Autocad MEP 2019. The update helps correct the loss of draw-order related to wipeouts.
;11/Sep/2020 10:09 AM[Friday] AUTHOR: Brandon Gum
;--
;Command = WTB = Send wipeout to back of block
;--
;DESCRIPTION:
;Select block with wipeout.
;Will send wipeout objects the back of the draw orer
;NOTE:
;Using get-effectivename This will not alter dynamic blocks or some blocks with attributes as these will be anonymous
;and the routine gets the effectivename property which will point to the parent block.
;If you want it to work on anonymous blocks change (vla-get-effectivename ...) to (vla-get-name...)
;------------
;Helpful Links:
;http://www.lee-mac.com/draworderfunctions.html
;https://www.cadtutor.net/forum/topic/71182-send-wipeout-to-back-of-draworder-within-block-definition/?tab=comments#comment-571185
;===========================================================
(defun c:WTB ( / s )
(princ "\nSelect Block: ")
(if (setq s (ssget "_+.:E:S" '((0 . "INSERT"))))
(progn
(LM:ApplytoBlockObjects ;this one targets the parent block
(vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
(vla-get-effectivename (vlax-ename->vla-object (ssname s 0)))
'(lambda ( obj ) (if (= "AcDbWipeout" (vlax-get obj 'objectname)) (LM:movetobottom (list obj))))
);end of 1st LM:Apply
(LM:ApplytoBlockObjects ;this one targets the annoyonmous block
(vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
(vla-get-name (vlax-ename->vla-object (ssname s 0)))
'(lambda ( obj ) (if (= "AcDbWipeout" (vlax-get obj 'objectname)) (LM:movetobottom (list obj))))
);end of 2nd LM:Apply
);end of progn
);end of if
(command "regenall")
(princ)
);end of defun
(vl-load-com)
;=====================================================
;==============Helper Functions Below=================
;; Apply to Block Objects - Lee Mac
;; Evaluates a supplied function on all objects in a block definition.
;; Arguments:
;; blks - VLA Block Collection in which block resides
;; name - Block name
;; func - function to apply to all objects in block
;; Returns a list of results of evaluating the function, else nil.
(defun LM:ApplytoBlockObjects ( blks name func / def result )
(setq func (eval func))
(if (not (vl-catch-all-error-p (setq def (vl-catch-all-apply 'vla-item (list blks name)))))
(vlax-for obj def (setq result (cons (func obj) result)))
)
(reverse result)
)
(defun BG:WipeoutToBottom( / )
(LM:movetobottom (ssget "X" '((0 . "WIPEOUT"))))
;(princ)
);end of defun
; Move to Bottom - Lee Mac
;; Moves a set of objects to the bottom of the draw order.
;; obs - [lst/sel] Selection set or list of objects with same owner
;; Returns: T if successful, else nil
(defun LM:movetobottom ( obs / tab )
(if (and (or (= 'list (type obs)) (setq obs (LM:ss->vla obs)))
(setq tab (LM:sortentstable (LM:getowner (car obs))))
)
(not (vla-movetobottom tab (LM:safearrayvariant vlax-vbobject obs)))
)
)
;; Get Owner - Lee Mac
;; A wrapper for the objectidtoobject method & ownerid property to enable
;; compatibility with 32-bit & 64-bit systems
(defun LM:getowner ( obj )
(eval
(list 'defun 'LM:getowner '( obj )
(if (vlax-method-applicable-p obj 'ownerid32)
(list 'vla-objectidtoobject32 (LM:acdoc) '(vla-get-ownerid32 obj))
(list 'vla-objectidtoobject (LM:acdoc) '(vla-get-ownerid obj))
)
)
)
(LM:getowner obj)
)
;; Catch Apply - Lee Mac
;; Applies a function to a list of parameters and catches any exceptions.
(defun LM:catchapply ( fnc prm / rtn )
(if (not (vl-catch-all-error-p (setq rtn (vl-catch-all-apply fnc prm))))
rtn
)
)
;; Sortents Table - Lee Mac
;; Retrieves the Sortents Table object.
;; obj - [vla] Block Container Object
(defun LM:sortentstable ( obj / dic )
(cond
( (LM:catchapply 'vla-item (list (setq dic (vla-getextensiondictionary obj)) "acad_sortents")))
( (LM:catchapply 'vla-addobject (list dic "acad_sortents" "AcDbSortentsTable")))
)
)
;; Selection Set to VLA Objects - Lee Mac
;; Converts a Selection Set to a list of VLA Objects
;; sel - [sel] Selection set (pickset)
(defun LM:ss->vla ( sel / idx lst )
(if (= 'pickset (type sel))
(repeat (setq idx (sslength sel))
(setq lst (cons (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))) lst))
)
)
)
;; Safearray Variant - Lee Mac
;; Returns a populated safearray variant of a specified data type
;; typ - [int] Variant type enum (e.g. vlax-vbdouble)
;; lst - [lst] List of static type data
(defun LM:safearrayvariant ( typ lst )
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray typ (cons 0 (1- (length lst))))
lst
)
)
)
;; Active Document - Lee Mac
;; Returns the VLA Active Document Object
(defun LM:acdoc nil
(eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
(LM:acdoc)
)
(vl-load-com) (princ)
;;----------------------------------------------------------------------;;
;; User prompt when user lisp is loaded ;;
;;----------------------------------------------------------------------;;
(princ (strcat "\n:: WipeoutBlockToBack.lsp | Version 1 | Brandon Gum "
"\n:: Available Command:"
"\n:: \"WTB\" - Send block's wipeout to back"
);end of strcat
);end of princ
(princ);surpress additional output
;;----------------------------------------------------------------------;;
;; End of File ;;
;;----------------------------------------------------------------------;;
Can't find what you're looking for? Ask the community or share your knowledge.