TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ArgV on March 31, 2010, 03:39:08 PM
-
Just wondering if anyone knows if, or how, to purge a drawing with ODBX? Or if it's even possible?
I realize there are no graphical entities with ODBX, so it would be hard for the application to determine whether an item can be purged or not, but I dunno.
thanks!
-
Yes it is possible but it's an activity that requires more than a quick answer to detail.
-
Yes it is possible but it's an activity that requires more than a quick answer to detail.
I could imagine. Well, I'd love to know how to do it, but if it's super involved then maybe I'll just write a script to do it.
-
Can you just use the ' delete ' method? I thought it wouldn't let you delete items that are referenced. Not sure though.
-
Just wondering if anyone knows if, or how, to purge a drawing with ODBX? Or if it's even possible?
I realize there are no graphical entities with ODBX, so it would be hard for the application to determine whether an item can be purged or not, but I dunno.
thanks!
Here is some code to purge a block(S). Modify it to suite your neeeds
;; Check to see if the block is a DW block
(foreach X BlockList
(if (= "DW-" (strcase (substr X 1 3)))
(progn
;; Check to see if the block is used and purge it
;; Method Thanks to Jimmy Bergmark
(if
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-delete
(list (vl-catch-all-apply
'vla-item
(list (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) X)
)
)
)
)
nil ; name cannot be purged or doesn't exist
)
)
)
)
Here is the code to open and close the drawing. credit to Credit to jbuzbee.
;;; ------------ OPEN A DBXDOCUMENT
(defun BLOCK_OpenDbx (dbxDrawingName / Application Document dbxDocument dbxOpen)
(setq Application (vlax-get-acad-object))
(setq Document (vla-get-activedocument Application))
(if (/= dbxDrawingName (vla-get-fullname Document))
(progn
(cond
((= (substr (getvar "ACADVER") 1 5) "15.06")
(setq dbxDocument (vla-GetInterfaceObject Application "ObjectDBX.AxDbDocument"))
(setq dbxOpen (vl-catch-all-apply 'vla-open (list dbxDocument dbxDrawingName)))
)
(T
(setq dbxDocument (vla-GetInterfaceObject Application (strcat "ObjectDBX.AxDbDocument." (substr (getvar "acadver") 1 2))))
(setq dbxOpen (vl-catch-all-apply 'vla-open (list dbxDocument dbxDrawingName)))
)
)
(if (vl-catch-all-error-p dbxOpen)
(setq dbxDocument nil)
)
)
)
(vlax-release-object Application)
(vlax-release-object Document)
dbxDocument
)
;;; ------------ CLOSE DBXDOCUMENT
(defun BLOCK_CloseDbx (dbxDocument / dbxDocument)
(if (= (type dbxDocument) 'VLA-OBJECT)
(progn
(vlax-release-object dbxDocument)
(setq dbxDocument nil)
)
)
)
Just start hacking things together. When you have things some what usable post it. :mrgreen:
-
try this...
change the "C:\test\33.dwg" by your drawing name..
(setq AutoCADapp
(vlax-create-object
(strcat "AutoCAD.Application."
(substr (getvar "acadver") 1 2)
)
)
)
(setq documents (vla-get-documents AutoCADapp))
(setq ii (vla-open documents "C:\\test\\33.dwg" nil))
(vla-sendcommand
ii
(strcat "_-purge"
(chr 13)
"_A"
(chr 13)
"_*"
(chr 13)
"_N"
(chr 13)
)
)
(vlax-invoke-method documents "close")
(vlax-invoke-method AutoCADapp "quit")
(mapcar 'vlax-release-object
(mapcar 'eval '(AutoCADapp documents ii))
)
-
If you are going to open the drawing, then there is no need to use ' sendcommand ', as there is a ' purgeall ' method of a document that is open in editor, even if it's not the current document.
Command: (dump (vla-item (vla-get-documents (vlax-get-acad-object)) "Drawing3.dwg"))
; IAcadDocument: An AutoCAD drawing
; Property values:
<snip>
; Methods supported:
; Activate ()
; AuditInfo (1)
; Close (2)
; CopyObjects (3)
; EndUndoMark ()
; Export (3)
; GetVariable (1)
; HandleToObject (1)
; Import (3)
; LoadShapeFile (1)
; New (1)
; ObjectIdToObject (1)
; Open (2)
; PurgeAll ()
; Regen (1)
; Save ()
; SaveAs (3)
; SendCommand (1)
; SetVariable (2)
; StartUndoMark ()
; Wblock (2)
-
Alright I will play dumb which takes very little effort from me.
What is the significance of checking for the ACAD version?
-
One thing I have noticed, that using the Delete method through ODBX will only catch the top-level objects i.e. a block that is part of a block will only delete the parent, not the child. Not sure if connecting to the file multiple times will solve that.
-
If you are going to open the drawing, then there is no need to use ' sendcommand ', as there is a ' purgeall ' method of a document that is open in editor, even if it's not the current document.
I have been meaning to ask this question.
I read somewhere that -purge is more through that purgeall.
Is this true?
-
Know that this will not purge Multileader styles.
If you are going to open the drawing, then there is no need to use ' sendcommand ', as there is a ' purgeall ' method of a document that is open in editor, even if it's not the current document.
Command: (dump (vla-item (vla-get-documents (vlax-get-acad-object)) "Drawing3.dwg"))
; IAcadDocument: An AutoCAD drawing
; Property values:
<snip>
; Methods supported:
; Activate ()
; AuditInfo (1)
; Close (2)
; CopyObjects (3)
; EndUndoMark ()
; Export (3)
; GetVariable (1)
; HandleToObject (1)
; Import (3)
; LoadShapeFile (1)
; New (1)
; ObjectIdToObject (1)
; Open (2)
; PurgeAll ()
; Regen (1)
; Save ()
; SaveAs (3)
; SendCommand (1)
; SetVariable (2)
; StartUndoMark ()
; Wblock (2)
-
If you are going to open the drawing, then there is no need to use ' sendcommand ', as there is a ' purgeall ' method of a document that is open in editor, even if it's not the current document.
I have been meaning to ask this question.
I read somewhere that -purge is more through that purgeall.
Is this true?
Wouldn't know. I never ran any tests. I just know it's there. :wink:
Know that this will not purge Multileader styles.
<snip>
Good to know. Don't use mleaders yet, so one for the memory bank.
-
Just wondering if anyone knows if, or how, to purge a drawing with ODBX? Or if it's even possible?
I realize there are no graphical entities with ODBX, so it would be hard for the application to determine whether an item can be purged or not, but I dunno.
thanks!
Here is some code to purge a block(S). Modify it to suite your neeeds
;; Check to see if the block is a DW block
(foreach X BlockList
(if (= "DW-" (strcase (substr X 1 3)))
(progn
;; Check to see if the block is used and purge it
;; Method Thanks to Jimmy Bergmark
(if
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-delete
(list (vl-catch-all-apply
'vla-item
(list (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) X)
)
)
)
)
nil ; name cannot be purged or doesn't exist
)
)
)
)
Here is the code to open and close the drawing. credit to Credit to jbuzbee.
;;; ------------ OPEN A DBXDOCUMENT
(defun BLOCK_OpenDbx (dbxDrawingName / Application Document dbxDocument dbxOpen)
(setq Application (vlax-get-acad-object))
(setq Document (vla-get-activedocument Application))
(if (/= dbxDrawingName (vla-get-fullname Document))
(progn
(cond
((= (substr (getvar "ACADVER") 1 5) "15.06")
(setq dbxDocument (vla-GetInterfaceObject Application "ObjectDBX.AxDbDocument"))
(setq dbxOpen (vl-catch-all-apply 'vla-open (list dbxDocument dbxDrawingName)))
)
(T
(setq dbxDocument (vla-GetInterfaceObject Application (strcat "ObjectDBX.AxDbDocument." (substr (getvar "acadver") 1 2))))
(setq dbxOpen (vl-catch-all-apply 'vla-open (list dbxDocument dbxDrawingName)))
)
)
(if (vl-catch-all-error-p dbxOpen)
(setq dbxDocument nil)
)
)
)
(vlax-release-object Application)
(vlax-release-object Document)
dbxDocument
)
;;; ------------ CLOSE DBXDOCUMENT
(defun BLOCK_CloseDbx (dbxDocument / dbxDocument)
(if (= (type dbxDocument) 'VLA-OBJECT)
(progn
(vlax-release-object dbxDocument)
(setq dbxDocument nil)
)
)
)
Just start hacking things together. When you have things some what usable post it. :mrgreen:
I'll tinker with that, but as far as I know (which isn't very far, mind you), the objectDBX interface doesn't have a purge method. Though I may be wrong, I didn't see one.
However, if the 'delete' method works like a purge, then I'm golden.
thank you! :)
-
If you are going to open the drawing, then there is no need to use ' sendcommand ', as there is a ' purgeall ' method of a document that is open in editor, even if it's not the current document.
I have been meaning to ask this question.
I read somewhere that -purge is more through that purgeall.
Is this true?
Wouldn't know. I never ran any tests. I just know it's there. :wink:
Know that this will not purge Multileader styles.
<snip>
Good to know. Don't use mleaders yet, so one for the memory bank.
This was my solution...
;;; Purge Multileader Styles (since vla-purgeall ignores them)
;;; Alan J. Thompson, 08.24.09
(defun AT:MleaderStylePurge (/)
(vl-remove-if
'null
(mapcar
'(lambda (x)
(and
(eq 350 (car x))
(not (eq 330 (car (nth 5 (entget (cdr x))))))
(not (eq (getvar "cmleaderstyle")
(vla-get-name (vlax-ename->vla-object (cdr x)))
) ;_ eq
) ;_ not
(entdel (cdr x))
) ;_ and
) ;_ lambda
(dictsearch (namedobjdict) "ACAD_MLEADERSTYLE")
) ;_ mapcar
) ;_ vl-remove-if
) ;_ defun
-
try this...
change the "C:\test\33.dwg" by your drawing name..
(setq AutoCADapp
(vlax-create-object
(strcat "AutoCAD.Application."
(substr (getvar "acadver") 1 2)
)
)
)
(setq documents (vla-get-documents AutoCADapp))
(setq ii (vla-open documents "C:\\test\\33.dwg" nil))
(vla-sendcommand
ii
(strcat "_-purge"
(chr 13)
"_A"
(chr 13)
"_*"
(chr 13)
"_N"
(chr 13)
)
)
(vlax-invoke-method documents "close")
(vlax-invoke-method AutoCADapp "quit")
(mapcar 'vlax-release-object
(mapcar 'eval '(AutoCADapp documents ii))
)
Will this work with ObjectDBX? I noticed this is a standard autocad application, which supports the 'vla-purgeall' command.
-
Quasi pseudo code food for thought ...
([color=blue]defun [/color][color=red]_PurgeAxdbDocument[/color] ( axdbDocument / purgeableCollections initialCount thisCount lastCount flag )
([color=blue]setq [/color]
purgeableCollections (_[color=red]GetPurgeAbleCollections [/color]axdbDocument)
initialCount ([color=blue]apply '+[/color] ([color=blue]mapcar [/color]'[color=red]_GetDeepCount [/color]purgeableCollections))
thisCount initialCount
flag T
)
([color=blue]while [/color]flag [color=green];; do at least once[/color]
([color=blue]foreach [/color]collection purgeableCollections
([color=red]_RecursivelyKillItWithFire[/color] collection)
)
([color=blue]setq [/color]
lastCount thisCount
thisCount ([color=blue]apply '+[/color] (mapcar '[color=red]_GetDeepCount[/color] purgeableCollections))
flag ([color=blue]/=[/color] lastCount thisCount)
)
)
([color=blue]princ [/color]([color=blue]strcat [/color][color=purple]"Purged "[/color] ([color=blue]itoa [/color]([color=blue]-[/color] initialCount thisCount)) [color=purple]" object(s).\n"[/color]))
([color=blue]princ[/color])
)
-
Not you too Michael. Those color code post are horrible to read on Black22 theme. :cry:
-
For the benefit of the theme challenged:
(defun _PurgeAxdbDocument ( axdbDocument / purgeableCollections initialCount thisCount lastCount flag )
(setq
purgeableCollections (_GetPurgeAbleCollections axdbDocument)
initialCount (apply '+ (mapcar '_GetDeepCount purgeableCollections))
thisCount initialCount
flag T
)
(while flag ;; do at least once
(foreach collection purgeableCollections
(_RecursivelyKillItWithFire collection)
)
(setq
lastCount thisCount
thisCount (apply '+ (mapcar '_GetDeepCount purgeableCollections))
flag (/= lastCount thisCount)
)
)
(princ (strcat "Purged " (itoa (- initialCount thisCount)) " object(s).\n"))
(princ)
)
-
Quasi pseudo code food for thought ...
([color=blue]defun [/color][color=red]_PurgeAxdbDocument[/color] ( axdbDocument / purgeableCollections initialCount thisCount lastCount flag )
([color=blue]setq [/color]
purgeableCollections (_[color=red]GetPurgeAbleCollections [/color]axdbDocument)
initialCount ([color=blue]apply '+[/color] ([color=blue]mapcar [/color]'[color=red]_GetDeepCount [/color]purgeableCollections))
thisCount initialCount
flag T
)
< .... >
)
For the benefit of the theme challenged:
(defun _PurgeAxdbDocument ( axdbDocument / purgeableCollections initialCount thisCount lastCount flag )
(setq
purgeableCollections (_GetPurgeAbleCollections axdbDocument)
initialCount (apply '+ (mapcar '_GetDeepCount purgeableCollections))
thisCount initialCount
flag T
)
< .. >
Both read fine for me in the Mercury theme .... :angel:
I can even read the code without re-formatting :-D
-
Perhaps this (http://www.theswamp.org/index.php?topic=31827.0)may help?
Maybe feed it this function :-)
(Mac-ODBX '(lambda (x) (repeat 3 (vla-purgeall x)) (vla-save x)) nil)
{ Untested }