Author Topic: Batch Processing title block info to Excel  (Read 1441 times)

0 Members and 1 Guest are viewing this topic.

57gmc

  • Bull Frog
  • Posts: 366
Batch Processing title block info to Excel
« on: February 20, 2024, 03:55:20 PM »
This question is directed to JohnK's solution for batch processing using AcCoreConsole.
For the result, I want to iterate a titleblock and send attribute and dwg info to a xslx or csv. Using John's method, it seems that writing to the csv would be handled by the bat file similar to writing to the log. But, then how do I pass the info from the scr to the bat file so it can write a line of info for each dwg?

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Batch Processing title block info to Excel
« Reply #1 on: February 20, 2024, 05:16:47 PM »
The batch script only logs the calls to it so, in other words, you can see what script you ran on what drawings. That script does not capture the output of the accoreconsole session.

You can build a script (aka: simple lisp) to grab the information you want and write--append--to a common log file of your choosing. Accoreconsole allows you to open files for reading and writing to.

Code - Auto/Visual Lisp: [Select]
  1. ;; read
  2. ( (lambda ( fd / line )
  3.   (princ "\n\n")
  4.    (while (setq line (read-line fd))
  5.      (write-line line))
  6.      (princ) )
  7.   (open "C:\\Temp\\MyFile.txt" "R")
  8.  )
  9.  
  10. ;; write
  11. ( (lambda ( fd / )
  12.     (write-line "this is a line of text" fd)
  13.     (close fd))
  14.   (open "C:\\Temp\\MyFile.txt" "a")
  15.  )
  16.  

Typically I used that script to "clean" drawings that were to be sent off somewhere (client, for example). I kept a "job list" of files (it was another batch script that listed my project drawings) in my directory that when the time I just double clicked to clean all my drawings and it would call the accooreconsole batch script thing I made for all my drawings and the correct script (I had MANY scripts that did all sorts of things, like update titleblock info, plot, clean, make slide files, etc.).

Code - Bash: [Select]
  1. @echo off
  2.  
  3. set SCRIPT="%~dp0\job-filelist_script.scr"
  4. set logfile="%~dp0\scripting.log"
  5.  
  6. set FILELIST=
  7. set FILELIST=%FILELIST%;"C:\Temp\FILE-001.dwg"
  8. set FILELIST=%FILELIST%;"C:\Temp\FILE-002.dwg"
  9.  
  10. call C:\some\location\to\BatchDrawings_accoreconsole.bat %FILELIST%

So, you can create a lisp to grab the information you want from the titleblock. Use the `job list` method (most likely not what you want here), drag and drop, or even assemble the list of drawings from AutoCAD and run through them with my script thing to append a log for each drawing.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

57gmc

  • Bull Frog
  • Posts: 366
Re: Batch Processing title block info to Excel
« Reply #2 on: February 20, 2024, 05:22:49 PM »
I was thinking that the bat file would open the csv once and keep writing a line for each file processed. But I see that I can have the script open and close the csv each time. That was the piece I was missing. Thx

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: Batch Processing title block info to Excel
« Reply #3 on: February 20, 2024, 10:31:49 PM »
A couple of comments

If you use "A" instead of "W" when opening a file it will "Append" to a file. So multiple dwgs could add to one file. Just close before you close a dwg file.

I dont think accoreconsole supports get application so may not be able to direct put an Excel cell. (setq myxl (vlax-get-object "Excel.Application")

A man who never made a mistake never made anything

57gmc

  • Bull Frog
  • Posts: 366
Re: Batch Processing title block info to Excel
« Reply #4 on: February 21, 2024, 10:22:28 AM »
Thanks for the tip Al.

ASCII csv will work. I just need to export attribute text.

57gmc

  • Bull Frog
  • Posts: 366
Re: Batch Processing title block info to Excel
« Reply #5 on: February 21, 2024, 12:38:34 PM »
I dont think accoreconsole supports get application so may not be able to direct put an Excel cell. (setq myxl (vlax-get-object "Excel.Application")
Do you know if I can use ActiveX vlax functions?

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Batch Processing title block info to Excel
« Reply #6 on: February 21, 2024, 02:04:47 PM »
I dont think accoreconsole supports get application so may not be able to direct put an Excel cell. (setq myxl (vlax-get-object "Excel.Application")
Do you know if I can use ActiveX vlax functions?

No, you plan on using only AutoLisp. (ssget, (entget, etc.

You wouldn't access excel outright, you'd be making a CSV file.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

57gmc

  • Bull Frog
  • Posts: 366
Re: Batch Processing title block info to Excel
« Reply #7 on: February 21, 2024, 06:09:25 PM »
I dont think accoreconsole supports get application so may not be able to direct put an Excel cell. (setq myxl (vlax-get-object "Excel.Application")
Do you know if I can use ActiveX vlax functions?

No, you plan on using only AutoLisp. (ssget, (entget, etc.

You wouldn't access excel outright, you'd be making a CSV file.
I was thinking more of using activex to get the block and iterate the attributes.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Batch Processing title block info to Excel
« Reply #8 on: February 21, 2024, 06:44:27 PM »
Sorry, you’ll have to go old school. Open accoreconsole and play around.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: Batch Processing title block info to Excel
« Reply #9 on: February 21, 2024, 11:11:26 PM »
This is interesting link 573 commands supported. Scroll down.

https://www.keanw.com/2012/03/commands-that-work-in-the-autocad-2013-core-console.html

I will try a get application and post back.
A man who never made a mistake never made anything

MrSmith

  • Newt
  • Posts: 23
Re: Batch Processing title block info to Excel
« Reply #10 on: February 29, 2024, 12:29:28 PM »
@57gmc "I was thinking more of using activex to get the block and iterate the attributes." That is how I solved this issue. Used ObjectDB to open drawings (with Lee Mac's primer) and collected the information of each attribute block (DWG Name, Layout, Block Name, Block Tag Name, Block Tag Attribute (text)). Saved this information into a list that was then exported into Excel at the very end. The whole process is really quick.

I then wrote the reverse to allow me to take the info from the Excel file and update the attributes in the blocks. This method can also be handled by ObjectDB but because ACAD has a bug with justifications of attributes, they will often times get misaligned. Works well in Bricscad though; I had to do the slow script method for ACAD :(

57gmc

  • Bull Frog
  • Posts: 366
Re: Batch Processing title block info to Excel
« Reply #11 on: February 29, 2024, 01:39:17 PM »
This method can also be handled by ObjectDB but because ACAD has a bug with justifications of attributes, they will often times get misaligned.
This is not really a bug, but a limitation of trying to justify without opening the drawing in the editor. The calculation can't be done. Just process the file in the editor and alignment should happen ok.

MrSmith

  • Newt
  • Posts: 23
Re: Batch Processing title block info to Excel
« Reply #12 on: February 29, 2024, 01:51:11 PM »
I've seen it referred to as a bug and the fact BCAD solves it means the calculation can be done, ACAD just doesn't handle the issue well. But yes, if you open the file directly and change it works fine. (I am assuming by "editor" you mean opened AutoCAD drawing?)

57gmc

  • Bull Frog
  • Posts: 366
Re: Batch Processing title block info to Excel
« Reply #13 on: February 29, 2024, 01:57:26 PM »
I've seen it referred to as a bug and the fact BCAD solves it means the calculation can be done, ACAD just doesn't handle the issue well. But yes, if you open the file directly and change it works fine. (I am assuming by "editor" you mean opened AutoCAD drawing?)
I don't know if Bcad has a similar feature as ObjectDbx in AutoCAD. But the editor is the graphical user interface, without it, there is no 'display' to calculate distances. Therefore its not a bug if it's missing by design. It is more accurately called a limitation. You would have to know the actual location yourself or predict it mathematically and translate that into a coordinate. I presume that you're just processing it normally in bcad.

MrSmith

  • Newt
  • Posts: 23
Re: Batch Processing title block info to Excel
« Reply #14 on: February 29, 2024, 05:04:43 PM »
BCAD's ObjectDB works exactly the same as ACADs. I run the exact same script in BCAD and it will properly justify the attributes despite it purely being edited through the ObjectDB method.