Jump to content

conditional statement


lfe011969

Recommended Posts

I'm trying to put together some code that plots individual sheets as a PDFs in a temp folder on the user's PC, then calls an external program (PDFTK) to merge the PDFs back into one PDF.

 

Before anyone states the obvious, I do realize I could just use the PUBLISH command to plot the sheets into one file. When we do this however, miscellaneous text is missing from various areas on each sheet. We think it has something to do with the font (RomanS) which is mandated by the customer for this project. It's really weird because using PLOT to make the PDFs works fine, but everytime we use PUBLISH, random letters disappear on almost every sheet. We tried multiple users on multiple computers all with the same result. :?

 

So in an effort to overcome this flaw, I found the PDFTK program on the Internet to merge the PDFs back into one file. Of course the drawback to this is automating the process so I've been working on a lisp to do just this. The code works for most users but because of the way our network is setup approximately 10 users who are on a different subnet than the rest of the office and the server experience extreme network lag and the lisp executes before the PDFs are created.

 

I'm playing with a conditional statement that compares the number of layouts (nLAY) against the number of PDFs (nPDF) in the temp folder. I want the code to wait until (= nLAY nPDF). Here's what I have so far:

 

(defun slowassnetwork (/ dir nLAY PDFlist nPDF)
   ;; Because of poor network speeds the following section continuously checks the
   ;; the temp folder until the number of PDFs in the folder equal the number of layouts
   ;; in the drawing.
   (setq dir "c:/Windows/Temp/CSC/")
   (setq nLAY (length (layoutlist)))
   (setq PDFlist (vl-directory-files dir "*.pdf" 1))
   (setq nPDF (vl-list-length PDFlist))
   (if (= nPDF nlay)
     (doit)
     (slowassnetwork)
   )
 )

 

The (doit) call references the rest of the program which already works. I don't have a lot of experience with lisp so I'm not sure if this will work (and I'm taking the day off so I can't experiment with the code).

 

Will this work? Thanks.

 

Lonnie

Link to comment
Share on other sites

  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

  • irneb

    8

  • Se7en

    6

  • BlackBox

    6

  • lfe011969

    5

Top Posters In This Topic

Have you downloaded and installed all service pack updates? :unsure:

 

I had similar issues early in our 2009 deployment, which was fixed when we updated our apps. I am constantly publishing plans to multi-sheet PDF.

Link to comment
Share on other sites

You haven't said which ACad version you're using. Also as RenderMan's stated, some updates have fixed problems with ACad's DWG2PDF driver. Although I still have huge problems with even the newest version in 2011 (e.g. text looks crappy, and lineweights are ALWAYS wrong). We use PDFs mainly to import into PhotoShop, where these bugs show up excessively - even on one-off PLOT commands (never mind the Publish). :sick:

 

For that reason we've been using PDFCreator instead. The PDFs are a lot nicer, smaller, views quicker, lineweights are perfect, as are text (both TTF and SHX). Not to mention, it's got its own combine PDF plots as you plot to it (e.g. I simply use publish to plot to it {check "Plotter named in page setup"}, the 1st time it asks for the filename I click the Wait+Collect button. Then when the last publish tab is complete, I click the combine all button & finish print. Asks for a filename for the combined PDF, e'voila! :thumbsup:

 

Now you want to do all this automatically by first using the (IMO still buggy DWG2PDF) into multiple files, then combine them. I suppose you could go that route. I'm not sure what's happening in your doit function, but since you state it works fine we'll not bother :whistle:

 

Anyhow, I wouldn't do this through recursion as you've done. You'll end up using a S#IT-Load of RAM as each recursive call maps itself to a new stack entry in RAM :sweat:. Rather go with an iteration using while. Also, I'd add something to wait a bit before checking the files again, otherwise you'll be checking each 1000'th of a second - which is going to make your slowass network a truly, prehistorically, molasses-like, screwed-up, crash-prone, useless, bunch of ... you get the picture :shock:? As an example I've moved the file checking into a while loop, first issuing the delay command to wait for 1sec before reading the folder's files. Then once the while completes the doit is called.

(vl-load-com)
(defun slowassnetwork (/ dir nLAY PDFlist nPDF)
 ;; Because of poor network speeds the following section continuously checks the
 ;; the temp folder until the number of PDFs in the folder equal the number of layouts
 ;; in the drawing.
 (setq dir "c:/Windows/Temp/CSC/")
 (setq nLAY (length (layoutlist)))
 (setq nPDF 0)
 (while (< nPDF nLAY)
   (command "._DELAY" 1000)
   (setq PDFlist (vl-directory-files dir "*.pdf" 1))
   (setq nPDF (vl-list-length PDFlist))
 )
 (doit)
)

Note: The above is going to loop forever if something goes wrong. E.g. if one of the plots fail, the PDF's will never reach the number of layouts ... so the while loop will never end.

 

BTW, you're talking about the network being slow. Have you mapped a network share onto the c:/Windows/Temp/CSC/ folder? IFAIK this "should" be directly on your PC's local HDD, not a network :?

 

To get round the problem of the never-ending-loop-on-error, you could have a secondary check to see how long the routine has been running. Then have a maximum time limit to stop the while loop. E.g.

(vl-load-com)
(setq *timelimit* (/ (* 5 60) 86400.0)) ;Maximum time of 5min
(defun slowassnetwork (/ dir nLAY PDFlist nPDF startTime)
 ;; Because of poor network speeds the following section continuously checks the
 ;; the temp folder until the number of PDFs in the folder equal the number of layouts
 ;; in the drawing.
 (setq dir       "c:/Windows/Temp/CSC/"
       nLAY      (length (layoutlist))
       nPDF      0
       startTime (getvar "DATE")
 )
 (while (and (< nPDF nLAY)
             (> (+ startTime *timelimit*) (getvar "DATE"))
        )
   (command "._DELAY" 1000)
   (setq PDFlist (vl-directory-files dir "*.pdf" 1))
   (setq nPDF (vl-list-length PDFlist))
 )
 (print (strcat (itoa nPDF) " PDFs are to be combined from " (itoa nLAY) " Layouts."))
 (doit)
)

You can change the value of *timeLimit* to suit, depending on just how long you're willing to wait before you realize there's a problem. It should be the time in seconds divided by the number of seconds in a day (i.e. 86400.0) and it should be a real value (not an integer).

 

At least the function will now stop after 5 minutes if there's still not enough PDFs. If your PC is slower than that, you may need to increase the time limit.:wink:

Link to comment
Share on other sites

Oh! And just BTW ... have you turned backgound publish off? If you publish in backgound you find some weird stuff happening. It's one of the settings I change in my ACAD.LSP file:

(setvar "BACKGROUNDPLOT" 0)

 

Just to ensure it's set correctly, you do get some smart-ass every now-and-again who "thinks" he knows better. :lol:

Link to comment
Share on other sites

Hey guys, didn't forget about you - I just went out of town for the weekend and just got into the office. I try not to think about work too much on my own time :shock:

 

Have you downloaded and installed all service pack updates? :unsure:

 

I know our IT group pushes out all the latest MS patches and updates (we are running XP). I doubt very seriously they've pushed out any AutoCAD updates as AutoCAD is not a standard part of the software suite they install on everyone's machine. I will double check that.

 

You haven't said which ACad version you're using.

 

Sorry I always forget that. We're using 2009. Maybe I should take the time to make a signature and put that I'm using 2009 in it, lol.

 

For that reason we've been using PDFCreator instead.

 

If PDFCreator costs money then the answer will be let us get back to you. We are a satellite office and aren't really thought of as we requested 6 more AutoCAD licenses in May due to our increased workload yet we haven't heard anything and it's now October. We literally have ACAD users waiting for people to get off the CAD stations so they can do their work. It's ridiculous.

 

Now you want to do all this automatically by first using the (IMO still buggy DWG2PDF) into multiple files, then combine them. I suppose you could go that route. I'm not sure what's happening in your doit function, but since you state it works fine we'll not bother :whistle:

 

Anyhow, I wouldn't do this through recursion as you've done. You'll end up using a S#IT-Load of RAM as each recursive call maps itself to a new stack entry in RAM :sweat:. Rather go with an iteration using while. Also, I'd add something to wait a bit before checking the files again, otherwise you'll be checking each 1000'th of a second - which is going to make your slowass network a truly, prehistorically, molasses-like, screwed-up, crash-prone, useless, bunch of ... you get the picture :shock:? As an example I've moved the file checking into a while loop, first issuing the delay command to wait for 1sec before reading the folder's files. Then once the while completes the doit is called.

 

LMAO :lol:. How we already feel about our network is exactly how you describe it. We have two servers onsite for our usage and for 3/4 of our office the route to actually file something to these servers takes 13 hops. This picture on the following link (we are blocked from uploading pictures) is a tracert test from my computer to the server 1 floor below me. For some reason our IT has it setup so that data leaves the site, travels up the east coast of the U.S. to D.C. (our office is in Hampton, VA) and back to the office and our server.

 

http://lonnies-pics.googlegroups.com/web/tracert.PNG?hl=en&gda=xJGRnj4AAABewkoxbCqYeie6ULGiJChjJySnXLtmUytH2QXSnWsbEcVzYw7vf3NkG_JSRbKI-vrjsKXVs-X7bdXZc5buSfmx&gsc=0J65sC4AAACGBDG8M8TGJvzRE1pOMjw1FfqSSP51iaDkirffkT9Na6xjwu_rDR5r_M7pfIyfuqg

 

Seriously I definitely see your point about not wanting to check every 1000th of a second to see if the files are there. I will try out your code this morning and let you know the results later. Thanks!

 

Lonnie

Edited by lfe011969
Link to comment
Share on other sites

If PDFCreator costs money then the answer will be let us get back to you.

 

 

My office uses DeskPDF, and ScanSoft PDF Create! for our Enterprise PDF plot drivers (i.e., .PC3).

Link to comment
Share on other sites

BTW, you're talking about the network being slow. Have you mapped a network share onto the c:/Windows/Temp/CSC/ folder? IFAIK this "should" be directly on your PC's local HDD, not a network :?

 

Where the slowness of the network comes into play is our AutoCAD support path on the network. For 3/4ths of the office, the ones who have to go all the way to DC and back, the PDFs get created long after the lisp has been executed from the server because the commands are traveling up the eastern seaboard and back. The other quarter of the office is actually on the same network as the server downstairs and for them everything works fine.

 

It is the most ridiculous setup I've ever encountered but we've been told that the users who are on the slower network have to be on there because they work on government contracts and all traffic from their machines are routed to DC to be "analyzed" for security purposes. What makes this completely stupid is 1) nothing prevents a user from working on other PC's so if they indeed are supposed to be working on something secure, they could still do so from a PC not on the secure network and 2) the other users who are not on the slow network are no different in job title or job responsibilities than everyone else. To illustrate this point, recently a user who was on the slow network had computer issues so IT brought up a new machine and hooked it up. After using it for a day or so this user reported to me that his computer must be a fast computer because he had no issues any more accessing our drawing files on the server. I quick check of the computer confirmed that this user was switched to the "unsecure" faster network.

Edited by lfe011969
Link to comment
Share on other sites

I quick check of the computer confirmed that this user was switched to the "unsecure" faster network.

 

Speaking as a former US Army Officer, that is a really p!ss poor decision (by your employer), and I'd have someone's hide.

 

Even low-hanging 'Secret' fruit is taken very seriously (among those charged with maintaining security). The irony, is that all government work has legally-binding contracts, so your employer *knows* they are required to be secure, and they've not even implemented the needed precautions... it's a (Federal?) lawsuit waiting to happen.

Link to comment
Share on other sites

Speaking as a former US Army Officer, that is a really p!ss poor decision (by your employer), and I'd have someone's hide.

 

Even low-hanging 'Secret' fruit is taken very seriously (among those charged with maintaining security). The irony, is that all government work has legally-binding contracts, so your employer *knows* they are required to be secure, and they've not even implemented the needed precautions... it's a (Federal?) lawsuit waiting to happen.

 

RenderMan, I completely agree with your sentiments. I'm not sure however that this was a conscious decision by the company but rather the ineptitude of the extremely slack IT support we have on site. Whether they completely bypassed the security procedures in place on purpose or on accident, to say we have an IT problem would be an understatement.

 

Ok, now on to the results of my tests with the code suggested by irneb. I took your suggestion and modified it a little and now it's working good. I built in two separate conditional loops with a maximum time limit that will exit the program if the conditions are not met.

 

This section checks to see if the number of PDFs in the temp directory equal the number of layouts once per second until either the totals equal each other or until the condition has been checked 300 times or 5 minutes.

;; Check to see if number of PDFs in temp directory equal number of layouts
 (setq nLAY (length (layoutlist)))
 (setq nPDF 0)
 (setq xtime 0)
 (while (and (< nPDF nLAY) (<= xtime 300))
   (setq xtime (1+ xtime))
   (command ".DELAY" 1000)
   (setq PDFlist (vl-directory-files dir "*.pdf" 1))
   (setq nPDF (vl-list-length PDFlist))
 )

 

This section checks to see if the final PDF has been created yet once per second until either the file is found or until the condition has been checked 300 times (or 5 minutes again). If the file is found it then gets copied to the drawing folder.

;; Copy the new PDF to the drawing directory
(setq copyPDF (strcat dpath pname))
(setq copyPDFcount 0)
(while (and (= (findfile "c:/Windows/Temp/CSC/temp1.pdf") nil)(<= copyPDFcount 300))
(setq copyPDFcount (1+ copyPDFcount))
(command "delay" 1000)
) 
(vl-file-copy "c:/Windows/Temp/CSC/temp1.pdf" copyPDF)

 

Oh BTW, I did a check of AutoCAD on several machines and they are all up to date with the latest service patches. So the issue of why text is missing when using PUBLISH versus PLOT in my situation is still a mystery.

 

Thanks for everyone's help.

 

Lonnie

Link to comment
Share on other sites

We use PDFs mainly to import into PhotoShop, where these bugs show up excessively - even on one-off PLOT commands (never mind the Publish). :sick:

 

 

PDFCreator uses Ghostscript at its core so you are witness to G.S.'s power. Now, if you would use G.S.--outright--you could have a PSD file instead of importing a PDF.

 

Snip from G.S. Docs:

3.8 PSD

PSD is the image format used by Adobe Photoshop. It is supported by the psdcmyk and psdrgb devices. Of special interest with the psdcmyk device is that it supports spot colors. See the comments under the tiffsep device about the maximum number of spot colors supported by Ghostscript

Link to comment
Share on other sites

If PDFCreator costs money then the answer will be let us get back to you. We are a satellite office and aren't really thought of as we requested 6 more AutoCAD licenses in May due to our increased workload yet we haven't heard anything and it's now October. We literally have ACAD users waiting for people to get off the CAD stations so they can do their work. It's ridiculous.
No it costs "nothing" ... just the cost of your connection to download the Open Source program from SourceForge: http://sourceforge.net/projects/pdfcreator/
Link to comment
Share on other sites

PDFCreator uses Ghostscript at its core so you are witness to G.S.'s power. Now, if you would use G.S.--outright--you could have a PSD file instead of importing a PDF.
And yes thaks for reminding me. I have GS + GSView + PStoEdit as well ... for those times I want a DXF from a PDF. Actually PDFCreator already has that as one of it's optional filetypes: when asking for the place to save you can select the file type from PDF, PDF/a, PDF/x, PNG, JPG, BMP, PCX, TIF, PS (Post Script), EPS (Encapsulated Post Script), TXT, PSD, PCL (What most HP printers use), RAW and SVG.

 

Unfortunately it sees PSD as a normal image format. When you import a vector PDF into PS it can be scaled up without loosing resolution, not to mention the PDF file's a lot smaller than the PSD. Anyhow this is all beyond where I'm going ... I'm trying to get this office to rather use ADesk's Impressions instead of PS, but that's like trying to pull teeth with people who are ingrained with PS - yet still complain about their 3GB PC not having enough RAM. :glare:

Link to comment
Share on other sites

I'm a big PS backer. Ive done a lot of customizing for GS (and the related tools) in my office; At one point I even made a fork of RedMON (I guess you could say that i was creating my own "PDFCReator" type of progy) at one point and started messing with it but it never really panned out passed version "0.1".

 

3gb ram not enough?! ... what are you guys doing that...how big are your files? Mine are typically ~4mb for a plan and ~12mb or so for 3d stuff. Sure the bigger ones take a sec to process, but i always tell my people to go get a cup of coffee.

Link to comment
Share on other sites

Very cool discussion, guys.

 

3gb ram not enough?!

 

 

That is an interesting question...

 

We haven't received our new PC's yet, but our new internal 'standard' for Civil 3D 2011 lists 4GB RAM minimum, 8GB RAM preferred. As I do not have Civil 3D 2011 yet (I use LDC 2009), I'll be interested to see just how much of the RAM is actually used.

Link to comment
Share on other sites

RenderMan, I was only speaking in terms of processing a Postscript file (like an ACAD .PLT file for example) and turning it into a PDF or opening it in another program ...stuff like that.

 

As far as ram on a CAD machine goes i would say 6gb-8gb would be good.

 

My Theory: focus more on a high ghz processor then number of cores or whatever.

Link to comment
Share on other sites

Well for presentations we usually have the PSD at 300DPI with a page size of A1 (i.e. it becomes an image of 9933x7016 pixels). The file sizes vary from 2MB up to 500MB (depending on how much "tat" is placed on it and how much fills are used). I've also been trying to explain to them that no human can see the difference between 100DPI and 300 ... but no ... don't want to listen. :roll: Anyhow PS is using about 2GB per page, and then it starts swapping to the PS swap disk ... which takes enormous amounts of time each time they Ctrl+Tab to the other file so they can copy-n-paste between the 2. Thus they take several minutes just to swap between the 2 ... imagine how long this makes those "sit-n-wait" interfals :lol:

 

I've shown them I can create the exact same "titleblock" with its image filled background in Illustrator with a file size of 700KB, using a whopping 20MB RAM to open. Generating a JPG of exactly the same quality & resolution as when exporting from PS - of similar file size when using the Highest JPG quality (about 8MB). The PS file is 100MB and saving it through Gimp to an XCF file produces a (slightly more compressed version) 75MB file. Responsiveness is near immediate as well, and you don't have any troubles with file types since it opens the DWG directly (working with its layers in a similar manner to what ACad does).

 

As for 3GB not being the recommended minimum, you're correct! Most of us are still stuck with AC2008, since we simply don't have the cash to upgrade the PC's. 2011 is just not working on 32bit with our DWGs, and most of our PC's can't have 64bit installed - thus the 3GB maximum RAM on the old 32bit XP.

Link to comment
Share on other sites

I'm a big PS backer. Ive done a lot of customizing for GS (and the related tools) in my office; At one point I even made a fork of RedMON (I guess you could say that i was creating my own "PDFCReator" type of progy) at one point and started messing with it but it never really panned out passed version "0.1".
If you start looking into PDFCreator's source you'll notice it's actually exactly what's happening: GS with RedMon ... just a more "automatic" setup. I know about redmon, I tried it a while back on version 8 or something - I think they're now at version 17 (which is what PDFCreator bundles). The RedMon route had a lot of problems with rotated pages, which I think PDFCreator has somehow sorted out.
Link to comment
Share on other sites

RenderMan, I was only speaking in terms of processing a Postscript file ...

 

 

Ahh! Got it now, I appreciate the clarification... Sorry for the tangential topic, guys.

Link to comment
Share on other sites

My Theory: focus more on a high ghz processor then number of cores or whatever.
Definately! Most programs (especially ACad) can only use one core at a time. It's only stuff like rendering (i.e. Revit / 3dStudio) which can make use of more than one core at a time. So rather than go for a 6 core i7 at 2.4GHz, you'd find that a 2 Core Xeon at 3.8GHz is going to perform a lot faster on most tasks.
Link to comment
Share on other sites

Well for presentations we usually have the PSD at 300DPI with a page size of A1 (i.e. it becomes an image of 9933x7016 pixels). The file sizes vary from 2MB up to 500MB (depending on how much "tat" is placed on it and how much fills are used). I've also been trying to explain to them that no human can see the difference between 100DPI and 300 ... but no ... don't want to listen. :roll: Anyhow PS is using about 2GB per page, and then it starts swapping to the PS swap disk ... which takes enormous amounts of time each time they Ctrl+Tab to the other file so they can copy-n-paste between the 2. Thus they take several minutes just to swap between the 2 ... imagine how long this makes those "sit-n-wait" interfals :lol:

 

I've shown them I can create the exact same "titleblock" with its image filled...

 

"They" never listen.

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...