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

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Batch Processing title block info to Excel
« Reply #15 on: February 29, 2024, 06:49:25 PM »
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.

What are you talking about?

57gmc

  • Bull Frog
  • Posts: 362
Re: Batch Processing title block info to Excel
« Reply #16 on: February 29, 2024, 07:34:36 PM »
Good question.I can't find a good definition of what the editor is on Autodesk's website. Maybe a better way to explain it is that ObjectDbx, AxDbDocument or a 'side database' as some call it, is just a representation of the dwg database. But the editor includes the gui and a document collection and methods for displaying and working with a document. That's just my experience of from learning what you can and can't do without the editor. How would you describe it? You have a lot of experience with it.

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: Batch Processing title block info to Excel
« Reply #17 on: February 29, 2024, 09:46:07 PM »
I am very confused.
If you want pure data extraction for one or many drawings use the EATTEXT command. You can even make a table from the results if I remember right.

If you just want simple attribute value extraction why don't you try ATTOUT/ATTIN or ATTEXT.

If you want to batch extraction/calculation/replacing/etc. from the same block in several files with my little batch script thing, then you'd just use simple ssget/entget and iterate the attributes, do your calculations/formatting/whatever, and export [append] to a CSV or write them back to the attribute. I don't know what ActiveX has to do with attributes or CSV.

ObjectDBX is another way too I suppose but I've used that so few times I can probably count on one hand. What would happen in the case where someone had the drawing open for edit?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Batch Processing title block info to Excel
« Reply #18 on: March 01, 2024, 11:25:48 AM »
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.
see also https://www.theswamp.org/index.php?topic=52209.msg571916#msg571916
and https://www.theswamp.org/index.php?topic=55890.msg599064#msg599064

MrSmith

  • Newt
  • Posts: 23
Re: Batch Processing title block info to Excel
« Reply #19 on: March 01, 2024, 12:26:44 PM »
I agree with the first, I don't know what voodoo magic Lee used to get it to work with his batch find/replace. All my attempts/tricks to get it to adjust properly have always failed. But as pointed out, it works perfectly find in BCAD.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Batch Processing title block info to Excel
« Reply #20 on: March 01, 2024, 01:04:01 PM »
<clip<
ObjectDBX is another way too I suppose but I've used that so few times I can probably count on one hand. What would happen in the case where someone had the drawing open for edit?
Before opening it you can try to see if it is already open...

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Batch Processing title block info to Excel
« Reply #21 on: March 01, 2024, 01:07:09 PM »
I agree with the first, I don't know what voodoo magic Lee used to get it to work with his batch find/replace. All my attempts/tricks to get it to adjust properly have always failed. But as pointed out, it works perfectly find in BCAD.
see https://www.lee-mac.com/bfind.html
Position of Non-Left Justified AttributesWhen using an ObjectDBX interface to modify the content of attribute references which do not have justification set to 'Left', there is a known bug which results in the attribute position not being updated following a change to the text field length (e.g. extending the text content of middle-center justified attributes will cause the attributes to become positioned off-center to the right).A function has been included in the application which attempts to adjust the attribute position to account for this issue, however, this function is not 100% effective and a slight change in attribute position may be apparent. Note that the attribute position will be correctly updated when the attribute is next edited manually.To modify attribute values without encountering this issue, please use my script-based Batch Attribute Editor program.
[/size][/font][/size][/font]

57gmc

  • Bull Frog
  • Posts: 362
Re: Batch Processing title block info to Excel
« Reply #22 on: March 01, 2024, 03:32:12 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.
see also https://www.theswamp.org/index.php?topic=52209.msg571916#msg571916
and https://www.theswamp.org/index.php?topic=55890.msg599064#msg599064
Thanks for the links. I didn't know it was a bug. I just knew that it didn't work and I came up with my own solution. That was many years ago.

57gmc

  • Bull Frog
  • Posts: 362
Re: Batch Processing title block info to Excel
« Reply #23 on: March 01, 2024, 03:33:56 PM »
I am very confused.
If you want pure data extraction for one or many drawings use the EATTEXT command. You can even make a table from the results if I remember right.

If you just want simple attribute value extraction why don't you try ATTOUT/ATTIN or ATTEXT.

If you want to batch extraction/calculation/replacing/etc. from the same block in several files with my little batch script thing, then you'd just use simple ssget/entget and iterate the attributes, do your calculations/formatting/whatever, and export [append] to a CSV or write them back to the attribute. I don't know what ActiveX has to do with attributes or CSV.

ObjectDBX is another way too I suppose but I've used that so few times I can probably count on one hand. What would happen in the case where someone had the drawing open for edit?
Yeah, the discussion kind of got off track. I'm still going with your dragndrop solution. I'm almost finished with the lisp. I just keep getting pulled to other stuff.

57gmc

  • Bull Frog
  • Posts: 362
Re: Batch Processing title block info to Excel
« Reply #24 on: March 05, 2024, 07:32:12 PM »
John, In your bat file, you have the following comparison:
Code: [Select]
if NOT [%~x1]==[.dwg] goto endmark
It's failing if the extension is .DWG. I can't find a syntax to compare both versions.

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: Batch Processing title block info to Excel
« Reply #25 on: March 05, 2024, 08:43:52 PM »
John, In your bat file, you have the following comparison:
Code: [Select]
if NOT [%~x1]==[.dwg] goto endmark
It's failing if the extension is .DWG. I can't find a syntax to compare both versions.

To do that we'd need a logical OR (and I'm pretty sure batch script doesn't have that for this case). ...yuck. But, let's try a chain of IF's.

Try replacing that line with these and see what happens (I'm typing blind here so bear with me, please).
Code - Bash: [Select]
  1. set end=T
  2. if [%~x1]==[.dwg] set end=F
  3. if [%~x1]==[.DWG] set ent=F
  4. if "%end%"=="T" goto endmark

We start off by assuming we need to "END" so we add a few IF statements to prove that we can continue. This (chained IF's) should represent a OR condition.

However, I wonder if we could just nest the IFs and get the same results without the need for a variable.
Code - Bash: [Select]
  1. if NOT [%~x1]==[.dwg] if NOT [%~x1]==[.DWG] goto endmark
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

57gmc

  • Bull Frog
  • Posts: 362
Re: Batch Processing title block info to Excel
« Reply #26 on: March 06, 2024, 10:50:16 AM »
Your intuition on the second case was right. It worked. For others, here is the bat file and lisp. I had to make a couple of small changes to your bat, but it was a good start. Thanks John.
Save the following as BatchExportTBInfo.bat
Code - Bash: [Select]
  1. rem comment out next line to view processing@echo off
  2. if [%logfile%]==[] set logfile="%~dp0\scripting.log"
  3. echo ----------------------------------------x- %date% -x------ >> %logfile%
  4. echo Batch command: %0 %* >> %logfile%
  5. echo Started at %date% %time% >>%logfile%
  6.      
  7. if [%script%]==[] (
  8.         set script="%~dp0\ExportTitleBlockInfo.scr"
  9.         set argc=0
  10.         ) else (
  11.         set argc=-1
  12.         )
  13. set script=%script:\\=\%
  14.  
  15. :: UPDATE as necessary.
  16. if [%accoreconsole%]==[] set accoreconsole="C:\Program Files\Autodesk\AutoCAD 2024\accoreconsole.exe"
  17.      
  18. set count=1
  19. for %%x in (%*) do set /A argc+=1
  20.      
  21. :processArgs
  22.    if [%1]==[] goto endmark
  23.    if NOT [%~x1]==[.dwg] if NOT [%~x1]==[.DWG] goto endmark
  24.    call %accoreconsole% /i "%~f1" /s %script% /l en-US
  25.    echo     %accoreconsole% /i "%~f1" /s %script% /l en-US
  26.    echo     %accoreconsole% /i "%~f1" /s %script% /l en-US >> %logfile%
  27.    set /A count +=1
  28.    if errorlevel 1 goto errormark
  29.    SHIFT
  30.    goto processArgs
  31.      
  32. :errormark
  33.   echo.
  34.   echo.
  35.   echo ERROR processing %~f1
  36.   pause
  37.   echo.
  38.   goto endmark
  39.      
  40. :endmark
  41.   rem
  42.   rem     finished
  43.   rem
  44.   echo Ended at %date% %time% >> %logfile%
  45.   rem uncomment next line to view processing
  46.   rem pause
  47.   rem
  48.   rem
Save the following as ExportTitleBlockInfo.scr. Change the filter to suit your needs.
Code - Auto/Visual Lisp: [Select]
  1. (defun LM:getattributevalues (blk / enx lst)
  2.    (while
  3.       (and (setq blk (entnext blk))
  4.            (= "ATTRIB" (cdr (assoc 0 (setq enx (entget blk)))))
  5.       )
  6.       (setq lst (cons
  7.                    (cons
  8.                       (cdr (assoc 2 enx))
  9.                       (cdr (assoc 1 (reverse enx)))
  10.                    )
  11.                    lst
  12.                 )
  13.       )
  14.    )
  15.    (reverse lst)
  16. )
  17. (defun getBlkName (blk / enx)
  18.    (cdr (assoc 8 (setq enx (entget blk))))
  19. )
  20. ((lambda (/)
  21.     (mapcar
  22.        '(lambda (x /)
  23.            (eval x)
  24.            (repeat 2 (command))
  25.            (princ)
  26.         )
  27.        '(
  28.           (setq ss (ssget "_x" '((0 . "insert") (8 . "TITLEBLK"))))
  29.           (setq blk (ssname ss 0))
  30.           (setq bname (getBlkName blk))
  31.           (setq header "")
  32.           (setq values "")
  33.           (setq atts (LM:getattributevalues blk))
  34.           (foreach a atts
  35.             (setq tag (car a))
  36.             (setq val (cdr a))
  37.             (setq header (strcat header "," tag))
  38.             (setq values (strcat values "," val))
  39.           )
  40.           (setq fn (strcat (getvar "DWGPREFIX") "," (getvar "DWGNAME") "," bname))
  41.           (setq folder (getvar "DWGPREFIX"))
  42.           (if
  43.               (setq file (if (findfile (strcat folder "TitleBlockExport.csv"))
  44.                             (open (strcat folder "TitleBlockExport.csv") "a")
  45.                             (open (strcat folder "TitleBlockExport.csv") "w")
  46.                         )
  47.               )
  48.               (progn
  49.                 (write-line fn file)
  50.                 (write-line header file)
  51.                 (write-line values file)
  52.                 (close file)
  53.               )
  54.           )
  55.         )
  56.     )
  57.     (princ line)
  58.  )
  59. )
  60.  

PrinceLISPalot

  • Newt
  • Posts: 34
  • perfectionist trapped inside the mind of an idiot.
Re: Batch Processing title block info to Excel
« Reply #27 on: March 07, 2024, 08:50:40 PM »
If you have BricsCAD, then you may find you can just use DATAEXTRACTION https://help.bricsys.com/en-us/document/bricscad/dialog-boxes/wizard-page-dialog-box. You can use this to generate .CSV or .XLSX and you can select multiple drawings to extract from. From memory the main limitation I found was that you couldn't access some data, such as the Layout name. This wouldn't be an issue if you're drawings have a single paper space layout or a single titleblock.

I've also successfully made use of Lee Mac's ObjectDBX wrapper to extract and update titleblock data in BricsCAD https://www.lee-mac.com/odbxbase.html