Discussion:
Create custom paper sizes programmatically
(too old to reply)
James Belshan
2003-07-17 23:05:02 UTC
Permalink
I needed hundreds of paper sizes available, so I made a simple SendKeys
utility that ran in 1" increments and drove the PC3 editor. My ACAD program
now has lots of paper sizes to choose the closest one from. It was easy to
do, but I'm sure it runs slower with all those paper sizes in the PC3. And
if the potential variety of paper sizes you'll need is tooooo huge, it won't
work for you.

FWIW, here it is...

Public Sub Add_Paper_Sizes()

' To use this sub:
' 1) have .PC3 file that is based on the AutoCAD TIF driver open to Custom
Paper tab.
' 2) set W and H to the desired width and height ranges
' 3) run it.... program will generate lots of paper sizes

Dim w As Integer
Dim h As Long

w = 5800

If MsgBox("Plotter Configuration Editor needs to be open to Custom Paper
tab before running sub. Continue?", vbOKCancel) = vbCancel Then Exit Sub

' w = Val(InputBox("Width", "Width", Format$(w)))
' h = Val(InputBox("Height", "Height", Format$(h)))

For h = 49800 To 6000 Step -200
'If MsgBox("Creating " & Format$(w) & " x " & Format$(h) & " pixel
page. Continue?", vbOKCancel) = vbCancel Then Exit Sub

AppActivate "Plotter Configuration Editor"

SendKeys "%a", True
SendKeys "%n", True
SendKeys Format$(w), True
SendKeys "%h", True
SendKeys Format$(h), True
SendKeys "%n", True
SendKeys Format$(w) & " x " & Format$(h) & " Pixels", True
SendKeys "%n", True
SendKeys "%f", True
Next 'h

End Sub

James
Uwe W. Radu
2003-07-17 23:18:36 UTC
Permalink
Post by James Belshan
I needed hundreds of paper sizes available, so I made a simple SendKeys
utility that ran in 1" increments and drove the PC3 editor. My ACAD program
now has lots of paper sizes to choose the closest one from. It was easy to
do, but I'm sure it runs slower with all those paper sizes in the PC3.
And
Post by James Belshan
if the potential variety of paper sizes you'll need is tooooo huge, it won't
work for you.
That's a real option, thanks. I can't believe this oversight in AutoCAD,
especially considering that drawing sizes can be so arbitrary, much more so
than say paper sizes in word processing. My company does have standardized
sizes, but nothing prevents someone from "accidentally" pulling a line
outside the border and thus creating non-standard sized extents.

I will also play around a bit with launching the PC3 property dialog of a
particular plotter and controlling it via PostMessage. If it gets too messy
I will probably just give up and use your method, but I'll give it a try.

Thanks.
Mike Tuersley
2003-07-18 04:49:25 UTC
Permalink
FWIW the rational behind it is that you should not be plotting from
model space - Autodesk speaking, not me. You could've accomplished what
you wanted by using a layout that is sized to standard paper sizes and
tweaking the viewport to account for the scaling differences.
--
___________________________
Mike Tuersley
AutoCAD Clinic
Rand IMAGINiT Technologies
Mike Tuersley
2003-07-18 15:03:03 UTC
Permalink
I guess, but that still wouldn't look right for many drawings. How exactly
do you determine what the "standard" paper size would be from the drawing?
You don't. You select the standard paper size for the layout and add
viewport[s] with the necessary scaling to be readable. Anyone who has
worked at any company for a period of time can tell right awway what
size paper/scale will work.
There are drawings with all the sheets concatenated side-by-side on the
same drawing, resulting in a humongously wide plot. What would be a
standard paper size for that?
Each one gets its own layout and you print All Layouts.
I can't do anything about this, it is a decades old established engineering
habit around TVA.
I hear you! Unforunately, sooner or later there will be no choice for
them. Look at the latest offerings, Inventor & Revit, you can't do the
old style so you have to learn the new. IMHO, it's only a matter of time
until AutoCAD follows suit. The evolution of plotting is just like the
evolution between DOS and Windows, sooner or later old habits have to
change. The faster, the better because it won't feel as forced. I deal
with this stuff daily and it is a hard pill for most incumbent CAD
managers/users who are stuck on their old ways. Never yet have I run
into a situation where opinion could not be swayed to the newer
approaches although sometimes the 'powers that be' are called to the
carpet and lose their credibility with their mgmt when they try to argue
their case.
As long as you keep it as a PDF and just view it on-screen, that's not a
problem, and the PDF document dimensions can easily be the same odd
dimensions of the drawing extents.
True but I wouldn't use pdfs I'd use dwfs - more functionality to the
viewer and no addittional cost for the creator.

Anyway, just my $0.02

___________________________
Mike Tuersley
AutoCAD Clinic
Rand IMAGINiT Technologies
Uwe W. Radu
2003-07-18 16:09:04 UTC
Permalink
Post by Mike Tuersley
I guess, but that still wouldn't look right for many drawings. How exactly
do you determine what the "standard" paper size would be from the drawing?
You don't. You select the standard paper size for the layout and add
viewport[s] with the necessary scaling to be readable. Anyone who has
worked at any company for a period of time can tell right awway what
size paper/scale will work.
My knowledge of AutoCAD is highly superficial (I'm just a general purpose
developer who had this project thrown in his lap), but this sounds like a
manual operation. How would you do this with legacy drawings (of which we
havemany hundreds of thousands) programmatically?
Post by Mike Tuersley
There are drawings with all the sheets concatenated side-by-side on the
same drawing, resulting in a humongously wide plot. What would be a
standard paper size for that?
Each one gets its own layout and you print All Layouts.
Actually, I wasn't entirely correct. Many of these oddly-sized drawings are
actually single drawings, perhaps of a cable run from a substation building
out into the yard, or a set of conductors spanning multiple cabinets.
Breaking them up would truncate the drawing.
Post by Mike Tuersley
True but I wouldn't use pdfs I'd use dwfs - more functionality to the
viewer and no addittional cost for the creator.
Well, the batch rendering program handles all sorts of outputs. You drop
both the drawing and a drawing.dwg.opt file into the watched folder, and the
.opt file specifies amongst other things the resired output format. A
drawing might require rendering for archiving one time (must always be PDF),
or for conversion to DWF another, or to TIF or CAL for who knows what
purpose.

Anyway, I might still have to evaluate the scaling option eventually, since
now I've discovered drawings from the GIS department--entire acres of
structures on a single drawing, which couldn't possibly be rendered to
scale. Rats!

Uwe W. Radu
2003-07-18 03:51:53 UTC
Permalink
Well, I did come up with a solution using SendKeys that works well enough
for now. If it ends up being flakey I might convert it to PostMessage
instead. It's all wrapped up into one single function AddPaperSize(). Of
course it will all break the next time the layout of either of these dialogs
changes.

Public Const SW_SHOWNORMAL = 1
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA"
( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Sub AddPaperSize( _
ByVal PlotterName As String, _
ByVal PaperWidth As Double, _
ByVal PaperHeight As Double, _
ByVal PaperSizeName As String)
Const PlottersFolder = <value of
HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R16.0\ACAD-201:409\Profiles\<<Un
named Profile>>\General\PrinterConfigDir>

' launch .pc3 editor and look for its dialog
ShellExecute 0, "open", PlottersFolder & "\" & PlotterName, vbNullString,
vbNullString, SW_SHOWNORMAL
Do While FindWindow("#32770", "Plotter Configuration Editor - " &
PlotterName) = 0
' minimize impact of busy wait
Sleep 1
Loop

' [Plotter Configuration Editor dialog]
' focus tab control
SendKeys "+{TAB}"
' move to third tab
SendKeys "{RIGHT 2}"
' focus tree control, move to last node, then back up four nodes
SendKeys "{TAB}{END}{UP 4}"
' use ALT-T shortcut to delete ten items from custom paper size list,
' hopefully getting them all (could use LVM_GETITEMCOUNT, but what the
heck)
SendKeys "%{T 10}"
' use ALT-A to press "Add..." button
SendKeys "%A"
' [Custom Paper Size dialog]
' move to next wizard page
SendKeys "%N"
' focus Width edit box
SendKeys "%W"
' set page width
SendKeys Format(PaperWidth, "0.00")
' focus Page Height edit box
SendKeys "%H"
' set page height
SendKeys Format(PaperHeight, "0.00")
' move to Paper Size Name wizard page (two pages down)
' (move to last page, then come back one in case the
' margins page is hidden, such as for raster drivers)
SendKeys "%N%N%N%B"
' set paper size name in canonical form W.WWxH.HH
SendKeys PaperSizeName
' move to last wizard page and dismiss dialog
SendKeys "%N%F"
' [Plotter Configuration Editor dialog]
' dismiss dialog with OK
SendKeys "{ENTER}"
End Sub
Loading...