Design Review
Welcome to Autodesk’s Design Review Forums. Share your knowledge, ask questions, and explore popular Design Review topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ECompositeViewer2.PrintSection(...) DC argument not working

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
1351 Views, 9 Replies

ECompositeViewer2.PrintSection(...) DC argument not working

I'm having a problem with
the ADR API ECompositeViewer2.PrintSection(ModelSection, Camera, WhiteBackground, DC).
I can't redirect printing to my supplied DC argument.

 

SETUP and VERSION
    ADR Version: 2010
    Language Used to Interface: C#
    Visual Studio 2008 Version: 9.0.21022.8 RTM
        Installed Edition: Professional
    .Net Framework Version: 3.5 SP1
    Windows Version: Windows7
    Computer: HP, 64 bit

 

PROBLEM

   With 2D drawings, the IAdECompositeViewer.DrawToDC(nDC, nLeft, nTop, nRight, nBottom) draws
   to the nDC argument.
   It writes to the nDC (a JPEG in my case) as advertised.
   The nDC argument is discribed as a 'long' in the documentation.  I give it a value
   of IntPtr.ToInt32(), without a cast, and it just works.

 

   When I try to do the same thing (writing  to a JPEG) using a 3D DWF drawing,
   a call to ECompositeViewer2.PrintSection(ModelSection, Camera, WhiteBackground, DC) doesn't
   work.  The DC argument is described as a 'long'.  I gave it a value of Intptr.ToInt32(), as with 2D
   (no cast), but the program shows message box dialogs that informs the user:

       Message box 1: "Print failed"
       Message box 2: "The printer is not available for printing."

 

   Note that the PrintSection(...) call with a value of 0 (zero) for the DC argument will print
   to my default printer.

 

   Help! and Thanks!

   Jack Heller

9 REPLIES 9
Message 2 of 10
Anonymous
in reply to: Anonymous

Hi Jack,
    As I understand it, a DC (device context) is a very new handle to a device in Windows 7 that allows one to write or read to a printer.  There is no way it can ever work for JPEGs.  Your 2D code should not really work.
 
Regards,
    CADrockStar1
Message 3 of 10
herbert.he
in reply to: Anonymous

Hi Jack,

 

Thank you for reporting this issue.

 

However I cannot reproduce this issue on my machine. The ADR API ECompositeViewer2.PrintSection() works well for both 2D and 3D files.

 

Please insure the nDC argument is valid.

 

Please let me know if you have any follow-on questions.



Herbert He
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Message 4 of 10
jhargett
in reply to: Anonymous

I am having a similar problem, although I can't get it to work with 2D drawings. I would like to 'print' the dwf to an Image context. I get the same error message originally mentioned, 'Print Failed', and 'Printer not available for printing'. Here is the VB.net code I am using to try this:

 

 

Dim CompositeViewer As ECompositeViewer.ECompositeViewerImpl
CompositeViewer = ctlViewer.ECompositeViewer
Dim PlotSection As ECompositeViewer.IAdSection = CompositeViewer.Section

Dim pg As Bitmap = New Bitmap(1600, 1150)
Dim gr As Graphics = Graphics.FromImage(pg)
Dim hDC As IntPtr = gr.GetHdc

CompositeViewer.PrintSection(CompositeViewer.Section, PlotSection, True, hDC)
'CompositeViewer.DrawToDC(hDC, 0, 0, ctlViewer.Width, ctlViewer.Height)

gr.ReleaseHdc(hDC)
Me.image = pg

 

I get the error mentioned when it hits the PrintSection command. If I comment that out, and instead use the DrawToDC command, it works. So, it seems to the DC is valid.

 

I am using Autodesk Design Review 2011 and using VB.net 2005

 

Thanks,

Jon

Message 5 of 10
herbert.he
in reply to: jhargett

Thank you for your question.

 

It seems like there is no available printer in your system. Please insure your current default printer works well.

 

Please let me know if you have any further questions.

 



Herbert He
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Message 6 of 10
jhargett
in reply to: Anonymous

As I mentioned, I am not trying to print to a printer. Printing to the default printer works. I would like to 'plot' the drawing to an image in memory. The code I posted above shows that. Do you have any suggestions on why this wouldn't work? It seems that the DC parameter of the command only works printing to the default printer, but not using a device context of a graphics object.

Message 7 of 10
herbert.he
in reply to: jhargett

Thank you for your feedback.

 

PrintSection method does not support to print the section to an Image context. Please use DrawToDC method.



Herbert He
SW Engineer
PSEB-GE- ACRD PSEB
Autodesk, Inc.
Message 8 of 10
jhargett
in reply to: herbert.he

DrawToDC does not have the quality or consistency needed to do this. It seems that the resolution of the resulting image is dependant on the size of the control on the form. I have not been able to make that work. Can anyone confirm that DrawToDC is able to make print quality images? Also that function copies everything from the control like the drop shadow and such. Not really desirable for printing.
Message 9 of 10
jhargett
in reply to: Anonymous

Just wanted to post back that I did find a solution with this. It seems that the DrawToDC is like taking a screenshot of the current display of the viewer. So, if you scale the actual dimensions of the viewer to the size image you want, then perform the DrawToDC method, this will create a good quality image. Here is some code:

 

Dim ctlViewer As AxExpressViewerDll.AxCExpressViewerControl
ctlViewer = frmDwgViewer.ctlViewer

Dim viewer As EPlotViewer.IAdPageViewer2 = ctlViewer.DocumentHandler()
Me.printdoc.DefaultPageSettings.Landscape = True

' determine the available printing area
Dim pgr As Graphics = Me.printdoc.PrinterSettings.CreateMeasurementGraphics
pgr.PageUnit = GraphicsUnit.Inch
Dim rect As RectangleF = pgr.VisibleClipBounds
Dim res As Integer

' get a resolution for the print quality
If My.Settings.Resolution <> 0 Then
    res = My.Settings.Resolution
Else
    res = 240
End If
' scale the viewer the right size for the screen capture
ctlViewer.Width = rect.Height * res
ctlViewer.Height = rect.Width * res

Dim pg As Bitmap = New Bitmap(ctlViewer.Width, ctlViewer.Height)
Dim gr As Graphics = Graphics.FromImage(pg)
Dim hDC As IntPtr = gr.GetHdc
viewer.DrawToDC(hDC, 0, 0, ctlViewer.Width, ctlViewer.Height)
gr.ReleaseHdc(hDC)

Me.image = pg

 

The downside of doing this is that now you are printing a bitmap image instead of control printing it for you. Printing a bitmap creates a large file on the print queue and some printers will run out of memory.

 

Message 10 of 10
Anonymous
in reply to: jhargett

This thread looks like the most recent one on the subject so I thought I'd ask here.

 

Is there a way to print to a DC without having the AxCExpressViewerControl visible?

I'm developing a DWF batch printing utility that needs more functionality that is offered wiht the ADR batch printer addin and have been researching the DrawToDC and PrintEX methods for a few days now.

 

 

I have tired to write the DWF to a DC pointer of a Bitmap with PrintEX and DrawToDC but got nothing. I'm assuming that's because the viewer is not visible.

Is there a better method that I can use along with the .NET System.Drawing.Printing PrintDocument object?

 

 

Thanks,

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

Post to forums  

Autodesk Design & Make Report