Author Topic: PLOT EXISTING DRAWING???  (Read 6695 times)

0 Members and 1 Guest are viewing this topic.

sanderson

  • Guest
PLOT EXISTING DRAWING???
« on: January 28, 2010, 05:39:33 PM »
The dosumentation is pathetic.  All I want to do is use VB.NET to plot the cirrent drawing with some plot settings.  All models are in model space.  This should be extremely simple, but there is nothing about it that I can find!!!???

Thanks,


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: PLOT EXISTING DRAWING???
« Reply #1 on: January 28, 2010, 06:20:22 PM »

Refer Plot from Model Space
in the AutoCAD .NET Developer's Guide
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

sanderson

  • Guest
Re: PLOT EXISTING DRAWING???
« Reply #2 on: February 01, 2010, 11:15:46 AM »
Thanks for the link.  Hopefully the fact that I'm using 2006 won't matter much.

sanderson

  • Guest
Re: PLOT EXISTING DRAWING???
« Reply #3 on: February 01, 2010, 03:29:18 PM »
Okay, I would a great example here...

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html

But the code errors on the first line...
  Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument

The error is External component has thrown an exception.

My goal is to plot the current active drawing.  I have referenced AutoCAD (AutoCAD 2006 Type Library), acdbmgd and acmgd.

I have the following imported into the program:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Drawing.Printing

Imports Microsoft.VisualBasic

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.PlottingServices

Any thoughts are greatly appreciated, and thank you.


sanderson

  • Guest
Re: PLOT EXISTING DRAWING???
« Reply #4 on: February 01, 2010, 03:34:21 PM »
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html

To get to where I'm talking about in the link above, go to Contents / Define Layouts and Plot / Plot Your Drawing / Plot from Model Space...

Thanks again!

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: PLOT EXISTING DRAWING???
« Reply #5 on: February 01, 2010, 03:47:06 PM »

I don't have AC2006 any longer
and I don't use VB
BUT ..
I've never seen that error before
Are the DLL's set to 'NOT copy local' ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

sanderson

  • Guest
Re: PLOT EXISTING DRAWING???
« Reply #6 on: February 01, 2010, 04:42:19 PM »
Not sure what you mean by DLL's being set to not copy local.

Perhaps I need to get the app to be a Class Library that uses DLL's???  I'm not sure how to do this and reference my form.  I was hoping to have an external EXE app that ran the active AutoCAD document.  Is this the wrong approach?

Thanks,

Bob Wahr

  • Guest
Re: PLOT EXISTING DRAWING???
« Reply #7 on: February 01, 2010, 04:48:27 PM »
I'm going to have to derail you a bit here and ask why you want an exe to do this.  It sounds a lot like you are just trying to automate plotting.  You can do this (IMO) more easily and efficiently with a menu macro using the command line plot command (-PLOT)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: PLOT EXISTING DRAWING???
« Reply #8 on: February 01, 2010, 04:55:31 PM »
The dosumentation is pathetic.  All I want to do is use VB.NET to plot the cirrent drawing with some plot settings.  All models are in model space.  This should be extremely simple, but there is nothing about it that I can find!!!???

Thanks,

Having ALL the information from you at the outset would help too :)

Check this in the Guide Out-of-Process versus In-Process
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/files/WS73099cc142f48755-5c83e7b1120018de8c0-2202.htm
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

sanderson

  • Guest
Re: PLOT EXISTING DRAWING???
« Reply #9 on: February 01, 2010, 05:17:18 PM »
Note, I am not looking for batch plotting here, but just the ability to select the printer, papersize and Plot.  VB.NET seems to have a nicer way of handling all the script options rather than  having to create a script sequence.  I want it this way because it seems cleaner.  I want the application external because it seems easier to manage.  I plan on adding it to the menu, but only externally.

Currently, we have a script that uses laserjet.pc3.  Last week we installed eight new printers and the script no longer worked.  LaserJet.pc3 is mapped to a port, and i the current program (which I did not write) is driver dependant.  Thus, new drivers means the program quits working.  I am of the opinion that we can have a program that will just print to a specified printer.  I have this part all coded.  It's getting the current AutoCAD instance to be referenced by VB.NET that I struggle with.

Thanks for the link.  It is the best thing I've found, and I did not see anything like this in the chm help files that come with AutoCAD, through 2010.  Because we have many users on 2006, we are writing the app to that standard.  It is my understanding that 2006 marked the start of .NET for AutoCAD, however.  I'm sorry if I was unclear in my post.  I did not think I mentioned anything anout dll's.  To me, it was always an external app. 

Respectfully, I do believe there is a huge difference between an end user with a question, and a muilti-million dollar software company not providing complete documentation.  I've been using Autodesk products for 25 years, and they have consistently been two to three years behind in documenting their software capabilities.  If one looks at the chm documentation for .NET in 2006, and again in 2010, they will see no difference in the documentation!  As for this website, again thanks!

sanderson

  • Guest
Re: PLOT EXISTING DRAWING???
« Reply #10 on: February 02, 2010, 10:05:07 AM »
So my question still is, can I do this externally in .NET?

sanderson

  • Guest
Re: PLOT EXISTING DRAWING???
« Reply #11 on: February 02, 2010, 05:29:29 PM »
And, for anyone who wants to know, the answer to my question is yes!

Here is the code:

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Drawing.Printing

Imports Microsoft.VisualBasic

Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common

Public Class frmQuiickPlot
    Dim prtDoc As New PrintDocument
    Public WithEvents AcadApp As Autodesk.AutoCAD.Interop.AcadApplication
    Dim acadDoc As Autodesk.AutoCAD.Interop.AcadDocument

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' Retrieve Name of Default Printer, Driver Name and Printer Port
        Dim strDefaultPrinter As String = prtdoc.PrinterSettings.PrinterName

        ' Define Printer
        Dim strPrinter As String
        For Each strPrinter In PrinterSettings.InstalledPrinters
            cboPrinter.Items.Add(strPrinter)

            If strPrinter = strDefaultPrinter Then
                cboPrinter.SelectedIndex = cboPrinter.Items.IndexOf(strPrinter)

            End If

        Next

        GetPaperSizes(prtDoc, cboPrinter.Text)

    End Sub

    Private Sub cboPrinter_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboPrinter.TextChanged
        GetPaperSizes(prtDoc, cboPrinter.Text)

    End Sub

    Private Sub GetPaperSizes(ByVal prtdoc As PrintDocument, ByVal strPrinter As String)
        cboPrintSize.Items.Clear()
        cboPrintSize.Items.Add("11x17")
        cboPrintSize.Items.Add("Letter")

        ' Set cbo to 11 x 17
        cboPrintSize.SelectedIndex = 0

        'Dim ps As PaperSize
        'For ix As Integer = 0 To prtdoc.PrinterSettings.PaperSizes.Count - 1
        '    If prtdoc.PrinterSettings.PaperSizes(ix).Kind = PaperKind.Letter Or prtdoc.PrinterSettings.PaperSizes(ix).Kind = PaperKind.Standard11x17 Then
        '        ps = prtdoc.PrinterSettings.PaperSizes(ix)
        '        prtdoc.DefaultPageSettings.PaperSize = ps
        '        cboPrintSize.Items.Add(ps.ToString)

        '    End If

        'Next

    End Sub

    Private Sub cmdPlotMe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlotMe.Click
        cmdPlotMe.Text = "Plotting..."
        cboPrinter.Enabled = False
        cboPrintSize.Enabled = False
        cmdPlotMe.Enabled = False

        Try
            AcadApp = GetObject(, "AutoCAD.Application.16.2") ' AutoCAD 2006 Only
            AcadApp.Visible = True

        Catch
            Try
                AcadApp = CreateObject("AutoCAD.Application.16.2") ' AutoCAD 2006 Only
                AcadApp.Visible = True

            Catch ex As Exception
                MsgBox(ex.ToString, MsgBoxStyle.Critical)
                Exit Sub

            End Try

        End Try

        ' Retrieve Active Drawing
        Try
            acadDoc = AcadApp.ActiveDocument
            Debug.WriteLine("acadDoc.Name: " & acadDoc.Name)

        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Critical)

        End Try

        ' Initialize
        acadDoc.ActiveSpace = AcActiveSpace.acModelSpace
        Dim Layout As AcadLayout
        Layout = acadDoc.ActiveLayout

        ' Get Canonical Media Names
        Layout.RefreshPlotDeviceInfo()
        Dim mediaNames() As Object = Layout.GetCanonicalMediaNames()
        Dim c As Integer
        For c = LBound(mediaNames) To UBound(mediaNames)
            cboPrintSize.Items.Clear()
            cboPrintSize.Items.Add(mediaNames(c))
            Debug.WriteLine(mediaNames(c))

        Next

        ' Plot Active Drawing
        Layout.RefreshPlotDeviceInfo()
        Layout.ConfigName = cboPrinter.Text
        Layout.PlotRotation = AcRotationAngle.acDegrees090
        Layout.StyleSheet = "monochrome.ctb"
        Layout.PlotWithPlotStyles = True
        Layout.PlotViewportBorders = False
        Layout.PlotViewportsFirst = True
        Layout.CanonicalMediaName = Me.cboPrintSize.Text
        Layout.PaperUnits = AcPlotPaperUnits.acInches
        Layout.StandardScale = AcPlotScale.acScaleToFit
        Layout.ShowPlotStyles = False
        acadDoc.Plot.NumberOfCopies = 1
        Layout.ScaleLineweights = False
        Layout.CenterPlot = True
        acadDoc.Regen(AcRegenType.acAllViewports)
        Layout = Nothing

        acadDoc.Plot.PlotToDevice()

        ' Need to pause for 20 seconds
        Threading.Thread.Sleep(20000)

        MessageBox.Show("Plot Complete...")
        Close()

    End Sub
End Class