Author Topic: Batch drawing processor  (Read 35252 times)

jb

  • Full Member
  • ***
  • Posts: 183
    • Black Horse Development, LLC
Batch drawing processor
« on: August 15, 2008, 09:57:12 AM »
This was originally posted over at theSwamp.org.

Using nothing more than a custom partial menu and OpenDCL!

Warning: this is a batch processing program that opens, modifies and closes drawings without giving you the opportunity to interact.  So before trying it out, set up a test folder with a few drawings in it.

How to use:
Unzip the files to a folder, making sure it's in AutoCAD's search path.  Menuload the partial menu, Batch.mns.  Now for some reason the menuload command doesn't load the corresponding .mnl file so you'll have to open up a fresh drawing to load the BatchProject.lsp.  Yes, this could also be done with an acadDoc.lsp in lieu of the menu.

The calling command is "Batchthis".



The BatchProject.lsp file is pretty well documented (well extremely well documented for me!) so I won't go into much detail here.  The Batch.odcl file is the OpenDCL project definition file that is edited in the studio editor.  Batch.lsp is the compiled code that I cut and paste into BatchProject.lsp.  Now you can just use the Batch.lsp in the Studio Editor and do away with the Batch.odcl, but I like to keep them separate.  Why? well, once I accidental screwed up the OpenDCL lisp file in the VLIDE editor.  :oops:

The place in the lisp that you'll add the code that modifies the drawing is here:

Code: [Select]
(defun Batch:Process (/ )
      (dcl_Control_SetCaption
Batch_00_DWGName
(strcat "Processing " (getvar "dwgname"))
)
    ;run the process here - put your edit functions here

      (command "circle" "0,0,0" "50")

    ;close the document
      (command "close" "n")
      (princ)
      (princ)
)

You'll see that I use nothing fancy, just some command calls.  You can add any type of lisp stuff.  I'm going to set up some subs and just call them here like: (kb_EditTitleBLock) - stuff like that.

You'll also notice I just use (command "close" . . . ) to close the document.  This is a beta because I want to speed things up by processing all the drawings first and then use (vla-close to save and close all the processed drawings.  I haven't figured out haw to not close the calling document yet  - but I'm working on it.

Well, have at it and let me know what you think.

jb


« Last Edit: August 15, 2008, 10:10:23 AM by jb »
James Buzbee
Managing Memeber
Black Horse Development, LLC

cmwade77

  • Member
  • *
  • Posts: 18
Re: Batch drawing processor
« Reply #1 on: August 26, 2008, 09:33:15 AM »
Hopefully this works better than my attempt at doing something like this, I will have to take a look, thank you so much.

jb

  • Full Member
  • ***
  • Posts: 183
    • Black Horse Development, LLC
Re: Batch drawing processor
« Reply #2 on: September 03, 2008, 05:56:58 AM »
Had any luck?

Make sure to let us know if you come up with anything interesting!
James Buzbee
Managing Memeber
Black Horse Development, LLC

cmwade77

  • Member
  • *
  • Posts: 18
Re: Batch drawing processor
« Reply #3 on: September 15, 2008, 01:57:43 PM »
This was a great starting point, unfortunately I do not believe mine would be of any interest, as it is so heavily customized for our office standards. But again, thank you to the OP, I still have a few bugs to iron out.

cmwade77

  • Member
  • *
  • Posts: 18
Re: Batch drawing processor
« Reply #4 on: May 07, 2009, 03:20:32 PM »
Ok, so now that 2010 no longer includes VBA, how can I open and close documents without using the VBASTMT, so that I don't have to install it for this one routine, so far everything that I have tried has failed miserably.

jb

  • Full Member
  • ***
  • Posts: 183
    • Black Horse Development, LLC
Re: Batch drawing processor
« Reply #5 on: May 25, 2009, 08:59:42 AM »
Owen . . . oh Owen . . .

Maybe the great one can roll the ARX function for opening a drawing into OpenDCL?  How hard would it be / would it conflict with a product(s) already on the market??
James Buzbee
Managing Memeber
Black Horse Development, LLC

owenwengerd

  • Administrator
  • Hero Member
  • *****
  • Posts: 3094
    • Outside The Box
Re: Batch drawing processor
« Reply #6 on: May 25, 2009, 09:43:50 AM »
What exactly is the problem? I'll bet it can be solved with a little creative lisp.

Fred Tomke

  • OpenDCL Technician
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2101
Re: Batch drawing processor
« Reply #7 on: May 25, 2009, 11:27:46 AM »
... sometimes I'll do such things via ObjectDBX

Code: (autolisp) [Select]
(defun DBX_OPEN (strFile / strRel reaRel strDBX oDbx)
  (setq strRel (substr (getvar "ACADVER") 1 2))
  (setq reaRel (float strRel))
  (if (<= reaRel 15.0)
    (setq strDBX "ObjectDBX.AxDbDocument")
    (setq strDBX (strcat "ObjectDBX.AxDbDocument." strRel))
  ); if
 
  (if (vl-catch-all-error-p (setq oDbx (vl-catch-all-apply 'vla-GetInterfaceObject (list (vlax-get-acad-object) strDBX))))
    (setq oDbx nil)
    (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list oDbx strFile)))
      (progn
(vlax-release-object oDbx)
        (setq oDbx nil)
      ); progn
    ); if
  ); if
  oDbx
); DBX_OPEN

(defun LIST_LAYERS (strDWG / oDbx oLayers lstLayers)
  (setq oDbx (DBX_OPEN strDWG))
  (setq oLayers (vla-get-layers oDbx))
  (vlax-for oLayer oLayers
    (setq lstLayers (cons (vla-get-name oLayer) lstlayers))
    (vlax-release-object oLayer)
  ); vlax-for
  (vlax-release-object oLayers)
  (vl-catch-all-apply 'vla-close (list oDbx))
  (vlax-release-object oDbx)
  (setq lstLayers (vl-sort lstLayers '(lambda (a b) (< (strcase a) (strcase b)))))
  lstLayers
); LIST_LAYERS

(vl-load-com)
(LIST_LAYERS "MyDwg.dwg")

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Marco Jacinto

  • Local Language Project Manager
  • Member
  • ****
  • Posts: 41
Re: Batch drawing processor
« Reply #8 on: May 25, 2009, 01:16:44 PM »
what i do to open and close a file (or a lot of them) is to open a second instance of AutoCAD and do all the batch processing here, having it invisible makes it looks like if it is in the same session of AutoCAD.

jb

  • Full Member
  • ***
  • Posts: 183
    • Black Horse Development, LLC
Re: Batch drawing processor
« Reply #9 on: May 27, 2009, 10:41:28 AM »
Owen the problem with lisp is because of document object dependency: vla-open returns to the calling document to complete, where as the VBA equivalent does not ( don't remember the syntax ).  I used the command "vbastmnt" to issue the open document function.  So, in 2010 if the VBA module isn't loaded I'm assuming the function fails ( don't have 2010 ).

To my knowledge there is no way to open a document with AutoLISP / VLISP and not return to dependent calling document.

Fred: I use ObjectDBX for a multiple of things and am well aware of it's potential, but it has some major problems with the Verticals ( I use Architecture ) so for this routine I wanted something with more control and access to the defined AEC commands.

jb
James Buzbee
Managing Memeber
Black Horse Development, LLC

owenwengerd

  • Administrator
  • Hero Member
  • *****
  • Posts: 3094
    • Outside The Box
Re: Batch drawing processor
« Reply #10 on: May 27, 2009, 11:36:06 AM »
I've always used Marco's approach for batch processing (opening an invisible session of AutoCAD in the background). However, I think you could use (dcl_SendString) to duplicate the VBA Open functionality.

Fred Tomke

  • OpenDCL Technician
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2101
Re: Batch drawing processor
« Reply #11 on: May 27, 2009, 10:50:49 PM »
Hi James,

Quote
it has some major problems with the Verticals

Oha, just to extend my knowledge: which problems this could be? Our customers use mainly Map and Civil, some Architecture, too.

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Kerry

  • Mesozoic Relic
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 433
  • class keyThumper<T>
Re: Batch drawing processor
« Reply #12 on: May 28, 2009, 03:11:33 AM »

Perhaps something like
Code: (autolisp) [Select]
(defun c:OpenDwg ()
    ;; CodeHimbelongaKdub ©  May2009
    (vla-activate
        (vla-open (vla-get-documents
                      (vla-get-application (vlax-get-acad-object))
                  )
                  "c:\\Test_Drawing51.dwg"
        )
    )
)
Perfection is not optional.
My other home is TheSwamp

Kerry

  • Mesozoic Relic
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 433
  • class keyThumper<T>
Re: Batch drawing processor
« Reply #13 on: May 28, 2009, 03:32:00 AM »
Thank goodness for Copernic desktop Search
searched my hardrives for vla-activate
This was from Frank Whaley (fairly elderley :) ):-

Code: (autolisp) [Select]
(defun cmdOpen (name)
  ;;; posted by Frank Whaley
  (vl-load-com)
  (if (= 0 (getvar "SDI"))
    (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) name))
    (vla-sendcommand
        (vla-get-activedocument
            (vlax-get-acad-object))
                (strcat "(command \"_.OPEN\")\n" name "\n") )
  )
)
Perfection is not optional.
My other home is TheSwamp

jb

  • Full Member
  • ***
  • Posts: 183
    • Black Horse Development, LLC
Re: Batch drawing processor
« Reply #14 on: May 28, 2009, 12:30:38 PM »
Fred: specifically with Styles and attached "extra" data such as materials, propertyset data, classifications, etc..  Say you have a door style with a classification defined.  When the door is imported via ObjectDBX, and the classification exists, a new classification is created: MyClass[1].  I ran into this along time ago and I think it happens with property data as well.  My work-around was to create a block with an object representing the style in the block and then use 'ImportBlock which brings the style in cleaner: but still won't work with classifications.  So I don't use classifications.

Owen: What argument to use with dcl_sendString? ".Open "?

jb
James Buzbee
Managing Memeber
Black Horse Development, LLC