VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CanonicalMediaName

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
5045 Views, 7 Replies

CanonicalMediaName

Hi all ! I read on the VBA doc that to set the paper size from code one have
to use the CanonicalMediaName property of the Plotconfiguration or Layout
object. I use the following code where siz is a string variabile that
contains one of the paper sizes of the plotter.

layout.CanonicalMediaName = siz

I always get a 80200003 error with the description "invalid entry". I'm
wondering what is wrong. the doc states that the CanonicalMediaName
property is a read/write one. I'm able to read it without any problem but
how to write it ? Just for information... the paper size I'm tryng to set is
a custom size and as a String I use the name I gave to the custome size when
I defined. Is there some hidden name to use ? My custom size when accessed
via the GetLocaleMediaName function give me a UserDefineMetric (something
here..) string. I tried this too but it didn't work. Is there someone that
knows the meaning og the 80200003 error code ?

Sandro
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: Anonymous

The actual canonical media name for a paper size is usually not simply the
paper size. You need to use the GetCanonicalMediaNames method to get all the
available valid media names for a given plotter.

Below is a function that creates an Excel spreadsheet listing all the
canonical media names for all your installed plotters and printers. Perhaps
it will help.

Public Sub tl_showplotsizes()
Dim oldplotter As String
Dim layout As AcadLayout
Dim plottername As String
Dim plotters As Variant
Dim plotsizes As Variant
Dim rownum As Integer, cnt As Integer
Dim Excel As Object
Dim excelsheet As Object
Dim excelbook As Object
Set layout = ActiveDocument.ActiveLayout
oldplotter = layout.configname
plotters = layout.GetPlotDeviceNames
Dim plotter As Variant
On Error Resume Next
Set Excel = GetObject(, "Excel.Application")
If Err <> 0 Then
Err.Clear
Set Excel = CreateObject("Excel.Application")
If Err <> 0 Then
MsgBox "Could not start Excel.", vbExclamation
Exit Sub
End If
End If
' On Error GoTo 0
With Excel
.Visible = True
.Workbooks.Add
End With
Set excelbook = Excel.ActiveWorkbook
Set excelsheet = excelbook.ActiveSheet
rownum = 1
With excelsheet
.Unprotect
.Columns("A").ColumnWidth = 5
For Each plotter In plotters
On Error Resume Next
layout.configname = plotter
If Err.number = 0 Then
.Cells(rownum, 1) = "Plot size names for " & UCase(plotter)
rownum = rownum + 1
plotsizes = layout.GetCanonicalMediaNames
For cnt = 0 To UBound(plotsizes)
.Cells(rownum, 2) = plotsizes(cnt)
rownum = rownum + 1
Next cnt
.Cells(rownum, 1) = ""
rownum = rownum + 1
Else
Err.Clear
End If
Next plotter
.Columns("B").AutoFit
.Protect
End With
Set excelsheet = Nothing
Set excelbook = Nothing
layout.configname = oldplotter

End Sub


"kombian" wrote in message
news:5102204@discussion.autodesk.com...
Hi all ! I read on the VBA doc that to set the paper size from code one have
to use the CanonicalMediaName property of the Plotconfiguration or Layout
object. I use the following code where siz is a string variabile that
contains one of the paper sizes of the plotter.

layout.CanonicalMediaName = siz

I always get a 80200003 error with the description "invalid entry". I'm
wondering what is wrong. the doc states that the CanonicalMediaName
property is a read/write one. I'm able to read it without any problem but
how to write it ? Just for information... the paper size I'm tryng to set is
a custom size and as a String I use the name I gave to the custome size when
I defined. Is there some hidden name to use ? My custom size when accessed
via the GetLocaleMediaName function give me a UserDefineMetric (something
here..) string. I tried this too but it didn't work. Is there someone that
knows the meaning og the 80200003 error code ?

Sandro
Message 3 of 8
Anonymous
in reply to: Anonymous

Thanks for your suggestions Tony. I solved the problem with the following
code :

Dim mediaNames As Variant
Dim name As String
Dim siz as String

siz = "my_custom_paper_size"
mediaNames = layout.GetCanonicalMediaNames()

For x = LBound(mediaNames) To UBound(mediaNames)
name = layout.GetLocaleMediaName(mediaNames(x))
If InStr(1, name, siz, vbTextCompare) = 1 Then
layout.CanonicalMediaName = mediaNames(x)
layout.RefreshPlotDeviceInfo
GoTo fine_ciclo
End If
Next
fine_ciclo:

this way the 80200003 error disappeared. It seems that the descriptions you
see in the paper size list of the plotter are not stored with that name. One
have to translate via the GetLocaleMediaName function the paper sizes
returned from GetCanonicalMediaNames. Now it works !






"Tony Burba" wrote in message
news:5102472@discussion.autodesk.com...
The actual canonical media name for a paper size is usually not simply the
paper size. You need to use the GetCanonicalMediaNames method to get all the
available valid media names for a given plotter.

Below is a function that creates an Excel spreadsheet listing all the
canonical media names for all your installed plotters and printers. Perhaps
it will help.

Public Sub tl_showplotsizes()
Dim oldplotter As String
Dim layout As AcadLayout
Dim plottername As String
Dim plotters As Variant
Dim plotsizes As Variant
Dim rownum As Integer, cnt As Integer
Dim Excel As Object
Dim excelsheet As Object
Dim excelbook As Object
Set layout = ActiveDocument.ActiveLayout
oldplotter = layout.configname
plotters = layout.GetPlotDeviceNames
Dim plotter As Variant
On Error Resume Next
Set Excel = GetObject(, "Excel.Application")
If Err <> 0 Then
Err.Clear
Set Excel = CreateObject("Excel.Application")
If Err <> 0 Then
MsgBox "Could not start Excel.", vbExclamation
Exit Sub
End If
End If
' On Error GoTo 0
With Excel
.Visible = True
.Workbooks.Add
End With
Set excelbook = Excel.ActiveWorkbook
Set excelsheet = excelbook.ActiveSheet
rownum = 1
With excelsheet
.Unprotect
.Columns("A").ColumnWidth = 5
For Each plotter In plotters
On Error Resume Next
layout.configname = plotter
If Err.number = 0 Then
.Cells(rownum, 1) = "Plot size names for " & UCase(plotter)
rownum = rownum + 1
plotsizes = layout.GetCanonicalMediaNames
For cnt = 0 To UBound(plotsizes)
.Cells(rownum, 2) = plotsizes(cnt)
rownum = rownum + 1
Next cnt
.Cells(rownum, 1) = ""
rownum = rownum + 1
Else
Err.Clear
End If
Next plotter
.Columns("B").AutoFit
.Protect
End With
Set excelsheet = Nothing
Set excelbook = Nothing
layout.configname = oldplotter

End Sub


"kombian" wrote in message
news:5102204@discussion.autodesk.com...
Hi all ! I read on the VBA doc that to set the paper size from code one have
to use the CanonicalMediaName property of the Plotconfiguration or Layout
object. I use the following code where siz is a string variabile that
contains one of the paper sizes of the plotter.

layout.CanonicalMediaName = siz

I always get a 80200003 error with the description "invalid entry". I'm
wondering what is wrong. the doc states that the CanonicalMediaName
property is a read/write one. I'm able to read it without any problem but
how to write it ? Just for information... the paper size I'm tryng to set is
a custom size and as a String I use the name I gave to the custome size when
I defined. Is there some hidden name to use ? My custom size when accessed
via the GetLocaleMediaName function give me a UserDefineMetric (something
here..) string. I tried this too but it didn't work. Is there someone that
knows the meaning og the 80200003 error code ?

Sandro
Message 4 of 8
Anonymous
in reply to: Anonymous

Hi there kmobian,

Are you using the standard Postscript Level 2.pc3 printer that is available with AutoCAD to plot these drawings to Postscript? (I am assuming that this post is related to your other one in that you are trying to PDF the drawings).

If so, the CanonicalMediaName for each of the paper sizes are actually related to the names shown in the Configuration dialogue (opened by going to Start>Settings>Control Panel>Autodesk Plotter Manager and double clicking on the desired .pc3 printer config) on the 'Device & Document Settings' tab.

The CanonicalMediaName for a paper size listed here is the same as in the list except that the spaces in the name are to be replaced with the underscore character "_".

And yes, it is a get/set property - you assign it simply as follows:-

LayoutToPlot.CanonicalMediaName = "ISO_A1_(841.00_x_594.00_MM)"

You can of course replace the literal name that I've shown above with a string variable containing the name you desire. You will get an error though if the name is not recognized.

This rule does not apply to paper sizes under other printers though as you have no doubt found out (and as pointed out in the previous post).

Regards,

Glenn.
Message 5 of 8
Anonymous
in reply to: Anonymous

Thnaks Glen. I used a custom defined postscript plotter for my application.
I solved the problem this way :

mediaNames = layout.GetCanonicalMediaNames()

For x = LBound(mediaNames) To UBound(mediaNames)
name = layout.GetLocaleMediaName(mediaNames(x))
' Debug.Print mediaNames(x) & " >> Local " & name
If InStr(1, name, siz, vbTextCompare) = 1 Then
layout.CanonicalMediaName = mediaNames(x)
GoTo Out_Of_For_Next
End if
Next


wrote in message
news:5107158@discussion.autodesk.com...
Hi there kmobian,

Are you using the standard Postscript Level 2.pc3 printer that is available
with AutoCAD to plot these drawings to Postscript? (I am assuming that this
post is related to your other one in that you are trying to PDF the
drawings).

If so, the CanonicalMediaName for each of the paper sizes are actually
related to the names shown in the Configuration dialogue (opened by going to
Start>Settings>Control Panel>Autodesk Plotter Manager and double clicking on
the desired .pc3 printer config) on the 'Device & Document Settings' tab.

The CanonicalMediaName for a paper size listed here is the same as in the
list except that the spaces in the name are to be replaced with the
underscore character "_".

And yes, it is a get/set property - you assign it simply as follows:-

LayoutToPlot.CanonicalMediaName = "ISO_A1_(841.00_x_594.00_MM)"

You can of course replace the literal name that I've shown above with a
string variable containing the name you desire. You will get an error though
if the name is not recognized.

This rule does not apply to paper sizes under other printers though as you
have no doubt found out (and as pointed out in the previous post).

Regards,

Glenn.
Message 6 of 8
Anonymous
in reply to: Anonymous

How did you set name siz = "my_custom_paper_size" to plotter format? I get the same problem with UserDefineMetric format, but how can I set the name of format? Name I defined inside the pc3 file is "myname", but when I specify it here .CanonicalMediaName = "myname" I get an error...

Message 7 of 8
Anonymous
in reply to: Anonymous

I understood your method, thanks!

Message 8 of 8
apovas333
in reply to: Anonymous

Which the method? Can you explain me please , since I am trying to find the solution?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta