Jump to content

Help! Need to generate LOTS of PNG files...


tmelancon

Recommended Posts

We use PNG image files on our technicians ipads who work in the field and we have about 6-8k isometric piping drawings in each of our projects directories (multiple directories). We upload to our cloud account and they are able to access them and perform their job and mark up as needed, etc...

 

My problem is that every year we have to generate all new PNG files to ensure the latest image of our drawings are available for them and I dread having to batch PNG using either scripting or even the Publish command because it takes so long... This may be the only way but I am seeking advice and opinions on the most efficient way to convert thousands of autocad drawings into PNG files.

 

My current script is something line this:

_.open "G:\client\division\location\area\Drawings\Example.dwg" _pngh

 

The C:PNGH is the command we use to convert DWG to PNG and looks like this:

(defun c:PNGH (/)
 (foreach lay (layoutlist) ;lay = each item in the layoutlist
   (setvar 'CTab lay)
   (COMMAND  "-plot" "n" "" "Horizontal-PNG-Acad (Color)" "PublishToWeb PNG.pc3" "" "n" "Y")
   ); end of foreach function
  (command "CTAB" "MODEL" "ZOOM" "ALL" "_QSAVE" "_CLOSE")
(PRIN1))

On average it takes about 3-4 seconds per drawing to be converted while running the batch. Is there a better more efficient way (meaning the accore method so I dont have to use multiple workstations) I am currently looking at about 22,000 drawings in front of me. I am about 4,000 in. Open to discussion... THANKS SO MUCH IN ADVANCE!

Edited by tmelancon
wanted to clarify it wasnt that 3-4 seconds was too slow... but...
Link to comment
Share on other sites

Maybe try Accoreconsole.exe this allows you to script multiple dwgs and do something with them including running a lisp it does not open the dwg so it will work in background.

 

Do a search here for examples I have used it as a test some people use it all the time. Not sure how much faster it will work but a big time component is open dwg and close again.

 

This is for one dwg there are some do a directory via a bat file so would make it easier again, will try to find the bat example.

cd\ 
cd c:\Program files\Autodesk\Autocad 2020
accoreconsole.exe /i d:\alan\test.dwg /s d:\alan\lisp\test.scr 

 

Edited by BIGAL
Link to comment
Share on other sites

BigAL Thank you so much for taking time to respond to my request. I have checked out the link and ended up using this one...

 

echo off

:: Path to AutoCAD core console
set accoreexe="C:\Program Files\Autodesk\AutoCAD 2019\accoreconsole.exe"

:: Path the directory to process
set "source=C:\Drawings\test\testscr"

:: Path to the script to run
set script="C:\Drawings\test\pasteblock.scr"

FOR /f "delims=" %%f IN ('dir /b "%source%\*.dwg"') DO %accoreexe% /i "%source%\%%f" /s %script%

:: comment the following to automatically close the console when batch ends
pause

 

Now the problem is when I use C:PNGH which is that little custom written command you can refer to in first post, it says:

 

Unknown Command "PNGH". Press F1 for Help!

Command: _quit

 

I re-wrote the script just to test and see and it looks like this:

 

CTAB

QSAVE

CLOSE

 

...and it executed perfectly on all 5 test drawings. Any reason why I am getting that error when I run PNGH from the script? I am so close... Any ideas? Thanks in advance!

Link to comment
Share on other sites

Ok so I have update and tested multiple times, here is my latest and although is not giving me errors anymore, it just simply runs through then nothing happens afterwards. No PNGs, nothing. Just runs then finishes with no visible results.

 

.BAT

FOR  /R  %%f  IN  (*.dwg)  DO  "C:\Program Files\Autodesk\AutoCAD 2014\AcCoreConsole.exe"  /i "%%f" /s "C:\Users\tmelancon\Desktop\TEMP-ATL-BATCH-IPAD\TESTER\TESTER2.scr" /l en-US

 

.SCR

(load "C:\Users\tmelancon\Desktop\TEMP-ATL-BATCH-IPAD\TESTER\TESTER.lsp")
(C:PNGH2)
 

 

.LSP

(defun c:PNGH2 (/)
 (foreach lay (layoutlist) ;lay = each item in the layoutlist
   (setvar 'CTab lay)
   (COMMAND  "-plot" "n" "" "Horizontal-PNG-Acad (Color)" "PublishToWeb PNG.pc3" "" "n" "Y")
   ); end of foreach function
  (command "CTAB" "MODEL" "ZOOM" "ALL")
(PRIN1))

 

 

Still trying. I have about 7k drawings processed so far via dragging ascript like this into my CAD window:

_.open "C:\Users\[USERNAME]\Desktop\Drawings\Example1.dwg" _pngh
_.open "C:\Users\[USERNAME]\Desktop\Drawings\Example2.dwg" _pngh
_.open "C:\Users\[USERNAME]\Desktop\Drawings\Example3.dwg" _pngh
_.open "C:\Users\[USERNAME]\Desktop\Drawings\Example4.dwg" _pngh
_.open "C:\Users\[USERNAME]\Desktop\Drawings\Example5.dwg" _pngh
_.open "C:\Users\[USERNAME]\Desktop\Drawings\Example6.dwg" _pngh

The problem with that is it physically opens each drawing, performs the command, closes out, then moves on to the next one. VERY VERY tidious... averages 3-4 seconds for a one page drawing... I have about over 20k to process and there could potentially be more afterwards. This is just a start. I feel like I am getting closer.

Link to comment
Share on other sites

SLW210, at this moment, an image file is what is compatible with our 3rd party software. Works wonders. These PNG files are used in more places than one and for more than one use. I gave you a single example. Its a requirement. Thank you for your input though.

Link to comment
Share on other sites

Our drawings are basically 8x11 canvas, we draw in model space, we then have a layout for each page of our drawing (i.e. 4 pages then Drawing1, Drawing2, Drawing3, Drawing4).

Link to comment
Share on other sites

The problem may be in the line (foreach lay (layoutlist)

 

As a 1st test try using this it is not tested. This will show if (layoutlist) is the problem.

 

(setq lays (layoutlist))
(repeat (setq x (length lays))
(setvar 'ctab (nth (setq x (- x 1)) lays))
(COMMAND "-plot" "n" "" "Horizontal-PNG-Acad (Color)" "PublishToWeb PNG.pc3" "" "n" "Y") ); end of foreach function 
(command "CTAB" "MODEL" "ZOOM" "ALL")
)

 

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

3 to 4 seconds per drawing seems very fast to me. I would just see about setting it up on a separate machine and let it run until done. If not then a more robust machine to get the time down maybe.

It would be instant if you had it set up for them to use the drawings. There are some apps for iPads and CAD viewing/markup.

  • Like 1
Link to comment
Share on other sites

BIG AL, The batch isnt working but I tested your code on a standalone drawing and it works very similar to mine except it does it in reverse order (i.e. my foreach prints pg1, pg2, etc.. yours prints pg4, p3, p2, p1...)

 

SLW210 you are right, this time isn't that bad, I just know the accore.exe way would definitely bring it down to 2 secs each and I would also be able to still use CAD. I may just have to seek out a second rig around here to put this task on. Thanks for that opinion. We use these PNG files for all sorts of things, we use them for review, we are constantly emailing and marking up on them, clients view them (and they do not have CAD and do not want CAD lol), they just want to open it up see our revision really quick and move along. Thanks for that input though.

 

I will continue to roll my old school way and test other methods periodically through the day. If I could figure it out man that would be nice! Thanks for all of your help! Talk to you soon!

Link to comment
Share on other sites

Im convinced it's my LISP for some reason. Something about having to step into "each" layout or something idk... I ran a batch by changing the script to something basic like:


 

<Start Script>
CTAB
Drawing1
QSAVE
CLOSE
       
<End Script>

 

...and when I opened each drawing they were all updated and I used the same code using accoreexe...

Link to comment
Share on other sites

(setq lays (reverse (layoutlist))) fixes backward plot order.

 

What happens with 1 dwg in a test script using repeat of the code above. Don't do the batch looping 

echo off

:: Path to AutoCAD core console
set accoreexe="C:\Program Files\Autodesk\AutoCAD 2019\accoreconsole.exe"

:: Path the directory to process
set "source=C:\Drawings\test\testscr\dwgname"

:: Path to the script to run
set script="C:\Drawings\test\pastetest.scr"

%accoreexe% /i "%source%" /s %script%

 

Link to comment
Share on other sites

BIGAL! Thanks again for your remarkable advice and assistance with all of this! I truly can't thank you enough. Im determined to get this.

 

So after further testing, it appears that my LISP is somehow the culprit. I even tested the LISP without the (foreach lay (layoutlist) and without the (repeat (setq x (length lays) and it still didnt work.

 

----TEST #1----

 

.BAT:

echo off
echo Starting AcCoreConsole
c:
cd C:\Users\[USERNAME]\Desktop\IPAD\TESTER
echo ================================================================================
FOR %%f in ("C:\Users\[USERNAME]\Desktop\IPAD\TESTER\*.dwg") DO "C:\Program Files\Autodesk\AutoCAD 2014\AcCoreConsole.exe" /i "%%f" /s "C:\Users\[USERNAME]\Desktop\IPAD\TESTER\TESTER2 - Copy.scr" /l en-US
echo Done!
pause

 

SCRIPT:

ctab
drawing1
-plot
n
drawing1
Horizontal-PNG-Acad (Color)
PublishToWeb PNG.pc3

n
y
ctab
model

 

It generates a PNG for all 5 drawings in the folder without a single issue, and it did it FAST, like 2-3 seconds for ALL FIVE! Keep in mind by doing it this way, it ONLY creates PNG of first layout Drawing1 and thats it. My LISP generates Drawing1 then cycles through the additional layouts if there are any. That is really what I need this to do in order to work.

 

----TEST #2----

Here is what I tried to do to bring it back to the basics for Drawing1 ONLY, not even going into multiple layouts, just 1, to keep it simple during testing:

 

.BAT:

echo off
echo Starting AcCoreConsole
c:
cd C:\Users\[USERNAME]\Desktop\IPAD\TESTER
echo ================================================================================
FOR %%f in ("C:\Users\[USERNAME]\Desktop\IPAD\TESTER\*.dwg") DO "C:\Program Files\Autodesk\AutoCAD 2014\AcCoreConsole.exe" /i "%%f" /s "C:\Users\[USERNAME]\Desktop\IPAD\TESTER\TESTER2.scr" /l en-US
echo Done!
pause

 

SCRIPT:

<Start Script>
(load "C:\Users\[USERNAME]\Desktop\IPAD\TESTER\TESTER - Copy.LSP")
(C:PNGH3)

<End Script>

LISP:

(defun C:PNGH3 (/)
(COMMAND "CTAB" "DRAWING1")
(COMMAND "-plot" "n" "" "Horizontal-PNG-Acad (Color)" "PublishToWeb PNG.pc3" "" "n" "Y")
(command "CTAB" "MODEL" "ZOOM" "ALL")
);end defun

 

Link to comment
Share on other sites

Had another look and may have an idea when you do -plot and "N" it expects  Horizontal-PNG-Acad (Color) is set in the plot if this is missing lisp will error try plotting with a full -plot "Y"

 

Something like this is a full version you can use extents and fit for the png

(COMMAND "-PLOT"  "Y"  "" "DWG To PDF"
	       "Iso full bleed A3 (420.00 x 297.00 MM)" "m" "LANDSCAPE"  "N"   "W"  "-6,-6" "807,560" "1=2"  "C"
	       "y" "Acad.ctb" "Y"	"n" "n" "n" pdfName "N" "y"
    )

Whilst your testing on a dwg that has the sheet set your lisp will work.

 

(setvar 'ctab lay)

Edited by BIGAL
Link to comment
Share on other sites

Hey BIGAL thanks again for your continued efforts. I updated the plot routine to use detailed plot configuration. Everything runs normally with no errors or visible issues however I see no PNGs as a results to running the test on the five sample drawings I performed the batch on. The batch opens, runs through the script, but I see no PNGs in my test folder where my drawings are at.

 

It also appears it is running the code through CMD Prompt and not accoreconsole.exe...

image.png.25fa6b21b7296fb6d9915ae1478fdfa0.png

 

I though it would open and execute code from here...

image.png.eecf968165e48cc88ef7c38b55f89b73.png

 

This is my first time exploring accoreconsole so maybe that is normal..Not sure how to get it to run out of accoreconsole. Still a work in progress...

 

With everything I currently am working with, regardless of whether I test as batch or test with individual drawing, it just does the following with no actual results:

 

Command: (load "C:\\........)

 

Command: PNGH2

 

Command:

Command: _quit

Edited by tmelancon
Link to comment
Share on other sites

This should work save as a bat file

echo off

:: Path to AutoCAD core console
set accoreexe="C:\Program Files\Autodesk\AutoCAD 2019\accoreconsole.exe"

:: Path to the script to run
set script="C:\Drawings\test\pastetest.scr"

%accoreexe% /i C:\Drawings\test\testscr\dwg1 /s %script%

%accoreexe% /i C:\Drawings\test\testscr\dwg2 /s %script%

%accoreexe% /i C:\Drawings\test\testscr\dwg3 /s %script%

%accoreexe% /i C:\Drawings\test\testscr\dwg4 /s %script%

look into a couple of things to write a bat

CMD 

cd C:\Drawings\test\testscr\

Dir *.dwg /s /b >dwgnames.txt 

 

This should make a text file of all the dwg's in the directory plus any below sub directorys.

 

Then use word you can replace ^p which is end of line with ^p"C:\Program Files\Autodesk\AutoCAD 2019\accoreconsole.exe" and do same for ends "C:\Drawings\test\pastetest.scr"^p

or excel use concatenate to join the columns =concatenate(a1," ",b1," "c1)

to make the bat file.

 

 

Edited by BIGAL
Link to comment
Share on other sites

Hey BIGAL, I have developed a spreadsheet with macros and some VBA that allows me to list out a drawing directory, extract the drawing name with and without the .dwg extension depending on which one I need so I can use it for specific tasks. However, you provided me with another useful method to use as an alternative and I appreciate that. It is always good to learn new things.

Quote

Dir *.dwg /s /b >dwgnames.txt 

 

As far as the BAT file, I have created one identically to what you specified and edited to my directory and samples file names and again it is running through each one like it is performing successfully, but again no PNGs..

 

[CMD Results]

C:\Users\[USERNAME]\Desktop\IPAD\TESTER>echo off
AutoCAD Core Engine Console - Copyright Autodesk, Inc 2009-2013.


Regenerating model.


Command:
Command:
Command:

Command:
Command: (load "C:\Users\[USERNAME]\Desktop\IPAD\TESTER\\TESTER.LSP")


Command: PNGH3


Command:
Command: _quit

AutoCAD Core Engine Console - Copyright Autodesk, Inc 2009-2013.


Regenerating model.


Command:
Command:
Command:

Command:
Command: (load "C:\Users\[USERNAME]\Desktop\IPAD\TESTER\\TESTER.LSP")


Command: PNGH3


Command:
Command: _quit

AutoCAD Core Engine Console - Copyright Autodesk, Inc 2009-2013.


Regenerating model.


Command:
Command:
Command:

Command:
Command: (load "C:\Users\[USERNAME]\Desktop\IPAD\TESTER\\TESTER.LSP")


Command: PNGH3


Command:
Command: _quit

AutoCAD Core Engine Console - Copyright Autodesk, Inc 2009-2013.


Loading Modeler DLLs.
Regenerating model.


Command:
Command:
Command:

Command:
Command: (load "C:\Users\[USERNAME]\Desktop\IPAD\TESTER\\TESTER.LSP")


Command: PNGH3


Command:
Command: _quit

AutoCAD Core Engine Console - Copyright Autodesk, Inc 2009-2013.


Loading Modeler DLLs.

Grid too dense to display
Regenerating model.

Grid too dense to display


Command:
Command:
Command:

Command:
Command: (load "C:\Users\[USERNAME]\Desktop\IPAD\TESTER\\TESTER.LSP")


Command: PNGH3


Command:
Command: _quit

Press any key to continue . . .

 

[BAT]

echo off

:: Path to AutoCAD core console
set accoreexe="C:\Program Files\Autodesk\AutoCAD 2014\accoreconsole.exe"

:: Path to the script to run
set script="C:\Users\[USERNAME]\Desktop\IPAD\TESTER\tester2.scr"

%accoreexe% /i C:\Users\[USERNAME]\Desktop\IPAD\TESTER\TEST1.dwg /s %script%

%accoreexe% /i C:\Users\[USERNAME]\Desktop\IPAD\TESTER\TEST2.dwg /s %script%

%accoreexe% /i C:\Users\[USERNAME]\Desktop\IPAD\TESTER\TEST3.dwg /s %script%

%accoreexe% /i C:\Users\[USERNAME]\Desktop\IPAD\TESTER\TEST4.dwg /s %script%

%accoreexe% /i C:\Users\[USERNAME]\Desktop\IPAD\TESTER\TEST5.dwg /s %script%
pause

 

[SCRIPT]

<Start Script>
(load "C:\Users\[USERNAME]\Desktop\IPAD\TESTER\\TESTER.LSP")
PNGH3

<End Script>

 

[LISP]

(defun c:pngh3 (/ lays x)
(setq lays (reverse (layoutlist)))
(repeat (setq x (length lays))
(setvar 'ctab (nth (setq x (- x 1)) lays))
    (COMMAND  "-plot" "Y" "" "PublishToWeb PNG.pc3" "Sun hi-Res (1600.00 x 1280.00 Pixels)" "L" "N" "EXTENTS" "F" "C" "Y" "ACAD.CTB" "Y" "N" "Y" "N" "" "N" "Y")
   ); end of repeat function
  (command "CTAB" "MODEL" "ZOOM" "ALL" "QSAVE" "CLOSE")
(PRIN1))

 

I am so confused as to why it wouldn't work and I don't know enough about accoreconsole to know if the lisp is the culprit. When I test the lisp in CAD it works. When I open an individual drawing and drag my TESTER2.scr in the drawing, it processes the script as usual, loads the lisp, runs C:PNGH3, saves, closes, and my PNG appears. However, its when I introduce the LISP is when it just runs with no errors and doesn't produce the resulted PNG.

 

Sorry for the lengthy posts I just want to provide whoever reads the post, yourself included, enough information for advice to be provided. Is there a way you can sort of use what I have and create your own directory on your desktop with 5 test drawings, each drawing with +1 Layout so we can process multi-page drawings with the test?

Link to comment
Share on other sites

https://houseofbim.com/2016/10/05/son-of-a-batch-autocad-core-console-through-lisp/ 

 

May have found it you have no png  filename "ACAD.CTB" "Y" "N" "Y" "N" "" "N" by going accept it gets nothing so your lisp needs to add a filename like dwgname-ctab

 

my plot pdf Acad.ctb" "Y" "n" "n" "n" pdfName "N" "y"

Edited by BIGAL
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...