Author Topic: Purging with ODBX?  (Read 5602 times)

0 Members and 2 Guests are viewing this topic.

ArgV

  • Guest
Purging with ODBX?
« 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!

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Purging with ODBX?
« Reply #1 on: March 31, 2010, 03:45:08 PM »
Yes it is possible but it's an activity that requires more than a quick answer to detail.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ArgV

  • Guest
Re: Purging with ODBX?
« Reply #2 on: March 31, 2010, 03:47:03 PM »
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Purging with ODBX?
« Reply #3 on: March 31, 2010, 03:50:10 PM »
Can you just use the ' delete ' method?  I thought it wouldn't let you delete items that are referenced.  Not sure though.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Purging with ODBX?
« Reply #4 on: March 31, 2010, 03:53:15 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!
Here is some code to purge a block(S).  Modify it to suite your neeeds
Code: [Select]
;; 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.
Code: [Select]
;;; ------------ 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:


ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Purging with ODBX?
« Reply #5 on: March 31, 2010, 04:56:47 PM »
try this...

change the "C:\test\33.dwg" by your drawing name..

Code: [Select]
(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))
)
Keep smile...

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Purging with ODBX?
« Reply #6 on: March 31, 2010, 05:03:42 PM »
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.

Quote
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)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Purging with ODBX?
« Reply #7 on: March 31, 2010, 05:04:34 PM »
Alright I will play dumb which takes very little effort from me.

What is the significance of checking for the ACAD version?
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Purging with ODBX?
« Reply #8 on: March 31, 2010, 05:14:51 PM »
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 fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Purging with ODBX?
« Reply #9 on: March 31, 2010, 05:17:46 PM »
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?
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Purging with ODBX?
« Reply #10 on: March 31, 2010, 05:28:43 PM »
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.

Quote
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)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Purging with ODBX?
« Reply #11 on: March 31, 2010, 05:40:28 PM »
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.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

ArgV

  • Guest
Re: Purging with ODBX?
« Reply #12 on: March 31, 2010, 05:49:47 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!
Here is some code to purge a block(S).  Modify it to suite your neeeds
Code: [Select]
;; 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.
Code: [Select]
;;; ------------ 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! :)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Purging with ODBX?
« Reply #13 on: March 31, 2010, 05:54:06 PM »
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...

Code: [Select]
;;; 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
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ArgV

  • Guest
Re: Purging with ODBX?
« Reply #14 on: March 31, 2010, 05:58:45 PM »
try this...

change the "C:\test\33.dwg" by your drawing name..

Code: [Select]
(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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Purging with ODBX?
« Reply #15 on: March 31, 2010, 09:16:15 PM »
Quasi pseudo code food for thought ...

Code: [Select]
([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])
   
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Purging with ODBX?
« Reply #16 on: April 01, 2010, 01:09:09 AM »
Not you too Michael.  Those color code post are horrible to read on Black22 theme.   :cry:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Purging with ODBX?
« Reply #17 on: April 01, 2010, 01:14:13 AM »
For the benefit of the theme challenged:

Code: [Select]
(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)
   
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Purging with ODBX?
« Reply #18 on: April 01, 2010, 02:56:16 AM »
Quasi pseudo code food for thought ...

Code: [Select]
([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:
Code: [Select]
(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
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Purging with ODBX?
« Reply #19 on: April 01, 2010, 07:18:03 AM »
Perhaps this may help?

Maybe feed it this function  :-)

Code: [Select]
(Mac-ODBX '(lambda (x) (repeat 3 (vla-purgeall x)) (vla-save x)) nil)

{ Untested }