.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Troubles in a C# interop to access a ActiveLayo ut.PlotTyp e
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi!
I doesen't acces or modify nothing in a ActiveLayout.
I'm using c# and interop and need to plot to a file a dwg.
The plot to file works well, but I need to change some properties like Plot Scale or Plot Type.
A conversion error occours.
In second place, the DefaultPlotStyleTable doesen't work too.
Somebody can helpe me?
My test code:
using System;
using System.IO;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
namespace ProcessoCAD
{
static class Program
{
private static Autodesk.AutoCAD.Interop.AcadApplication oAcadApp = null;
private static string sAcadID = "AutoCAD.Application.18";
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// Abre AutoCAD
try
{
oAcadApp = (Autodesk.AutoCAD.Interop.AcadApplication)System.R
}
catch
{
System.Type AcadProg = System.Type.GetTypeFromProgID(sAcadID);
oAcadApp = (Autodesk.AutoCAD.Interop.AcadApplication)System.A
}
// Inicia ciclo de execução
if (oAcadApp != null)
{
string StyleTable = "AZEVEDO.ctb";
oAcadApp.Visible = true; //could leave this false to hide Acad from the user
Autodesk.AutoCAD.Interop.AcadDocument dm; // = oAcadApp.ActiveDocument;
dm = oAcadApp.Documents.Open("d:\\teste\\Teste.dwg", true, null);
dm.SetVariable("BACKGROUNDPLOT", 0);
dm.ActiveSpace = AcActiveSpace.acPaperSpace;
dm.ActiveLayout.PlotType = AcPlotType.acExtents;
dm.ActiveLayout.StandardScale = AcPlotScale.ac1_1;
oAcadApp.Preferences.Output.DefaultPlotStyleTable = StyleTable;
dm.Regen(AcRegenType.acActiveViewport);
// dm.Application.ZoomExtents();
// dm.Regen(AcRegenType.acAllViewports);
dm.Plot.QuietErrorMode = true;
dm.Plot.NumberOfCopies = 1;
dm.Plot.PlotToFile("d:\\teste\\Teste.pdf", "C:\\Program Files\\AutoCAD 2010\\UserDataCache\\Plotters\\DWG To PDF.pc3");
// dm.Plot.PlotToFile("d:\\teste\\Teste.plt", "C:\\Program Files\\AutoCAD 2010\\UserDataCache\\Plotters\\DWF6 ePlot.pc3");
//dm.Close(null, null);
//oAcadApp.Quit();
}
}
}
}
Re: Troubles in a C# interop to access a ActiveLayo ut.PlotTyp e
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Try this code snip, change to your settins and file name:
' Abre AutoCAD
Try
oAcadApp = DirectCast(System.Runtime.InteropServices.Marshal. GetActiveObject(sAcadID), Autodesk.AutoCAD.Interop.AcadApplication)
Catch
Dim AcadProg As System.Type = System.Type.GetTypeFromProgID(sAcadID)
oAcadApp = DirectCast(System.Activator.CreateInstance(AcadPro g), Autodesk.AutoCAD.Interop.AcadApplication)
End Try
oAcadApp.Visible = True
Try
' Inicia ciclo de execução
If oAcadApp IsNot Nothing Then
Dim StyleTable As String = "MyPlotStyle.ctb"
' set application to be visible
oAcadApp.Visible = True
' expand window to max
oAcadApp.WindowState = AcWindowState.acMax
'could leave this false to hide Acad from the user
Dim dm As Autodesk.AutoCAD.Interop.AcadDocument
' = oAcadApp.ActiveDocument;
dm = oAcadApp.Documents.Open("c:\test\layouts.dwg", True, Nothing)
' set desired layouts first
dm.ActiveLayout = dm.Layouts.Item("FLOOR PLAN")
dm.SetVariable("BACKGROUNDPLOT", 0)
dm.ActiveSpace = AcActiveSpace.acPaperSpace
dm.ActiveLayout.PlotType = AcPlotType.acExtents
dm.ActiveLayout.StandardScale = AcPlotScale.ac1_1
dm.Utility.Prompt(vbLf & oAcadApp.Preferences.Output.DefaultPlotStyleTable)
'MsgBox(dm.ActiveLayout.GetPlotStyleTableNames(0). ToString)
Dim pstyle As String
Dim pstyles() As String = TryCast(dm.ActiveLayout.GetPlotStyleTableNames, String())
For Each pstyle In pstyles
If String.Compare(StyleTable, StringComparison.InvariantCulture) = 0 Then
oAcadApp.Preferences.Output.DefaultPlotStyleTable = StyleTable
Else
oAcadApp.Preferences.Output.DefaultPlotStyleTable = "acad.stb"
End If
Next
dm.Regen(AcRegenType.acActiveViewport)
' dm.Application.ZoomExtents();
' dm.Regen(AcRegenType.acAllViewports);
dm.Plot.QuietErrorMode = True
dm.Plot.NumberOfCopies = 1
' dm.Plot.PlotToFile("d:\\teste\\Teste.plt", "C:\\Program Files\\AutoCAD 2010\\UserDataCache\\Plotters\\DWF6 ePlot.pc3");
'dm.Close(null, null);
'oAcadApp.Quit();
dm.Plot.PlotToFile("c:\test\layouts.pdf", "C:\Program Files\AutoCAD 2009\UserDataCache\Plotters\DWG To PDF.pc3")
End If
Catch ex As System.Exception
MsgBox(ex.Message & vbLf & ex.StackTrace)
End Try
End Sub
C6309D9E0751D165D0934D0621DFF27919
Re: Troubles in a C# interop to access a ActiveLayo ut.PlotTyp e
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks for help!
I converted the code to VB, but when it executes the line
dm.ActiveLayout = dm.Layouts.Item(0)
I have a conversion error:
"Unable to cast COM object of type 'Autodesk.AutoCAD.Interop.Common.AcadLayoutsClass' interface type 'Autodesk.AutoCAD.Interop.Common.IAcadLayouts.' This operation failed because the QueryInterface call on the COM component for the interface with IID '{9AEBED7B-03A9-4C9E-B358-4E95FA5B07F4}' failed due to the following error: No support for this interface (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Is it because my dwg or a wrong reference?
I'm send the dwg and need to use the AR2 Layout.
Thanks
Re: Troubles in a C# interop to access a ActiveLayo ut.PlotTyp e
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Sorry for the belating I was busy
I tested code I posted above on my machine -
the plotting is looks good,
See plot copy log:
| Job: - Plotted Job ID: 1 Sheet set name: Date and time started: 24.10.2012 20:52:47 Date and time completed: 24.10.2012 20:52:49 UserID: Олег Profile ID: <<Unnamed Profile>> Total sheets: 1 Sheets plotted: 1 Number of errors: 0 Number of warnings: 0
|
C6309D9E0751D165D0934D0621DFF27919
Re: Troubles in a C# interop to access a ActiveLayo ut.PlotTyp e
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks for help!
I reinstall the ARX SDK for 2010 and works fine!
But, the DefaultPlotStyleTable insists in not work.
The code set all preferences, but the result (in pdf) doesn't reflect them.
For example, if I use the monochrome.ctb to plot into a pdf, it's doesn't plot in monochrome.
I saw too that a file stb raises a exception.
Re: Troubles in a C# interop to access a ActiveLayo ut.PlotTyp e
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi!
I include the line dm.ActiveLayout.StyleSheet = "AZEVEDO.ctb" and all works fine!
Thanks for help!!!!
Following code examples for those who have questions:
--------------------------------------------------
VB
--------------------------------------------------
Dim oAcadApp As Autodesk.AutoCAD.Interop.AcadApplication
Dim sAcadID = "AutoCAD.Application.18"
' Abre AutoCAD
Try
oAcadApp = DirectCast(System.Runtime.InteropServices.Marshal.
Catch
Dim AcadProg As System.Type = System.Type.GetTypeFromProgID(sAcadID)
oAcadApp = DirectCast(System.Activator.CreateInstance(AcadPro
End Try
oAcadApp.Visible = True
Try
' Inicia ciclo de execução
If oAcadApp IsNot Nothing Then
Dim StyleTable As String = "AZEVEDO.ctb"
' set application to be visible
oAcadApp.Visible = True
' expand window to max
oAcadApp.WindowState = AcWindowState.acMax
'could leave this false to hide Acad from the user
Dim dm As Autodesk.AutoCAD.Interop.AcadDocument
dm = oAcadApp.Documents.Open("d:\teste\teste.dwg", True, Nothing)
' set desired layouts first
dm.ActiveLayout = dm.Layouts.Item(0)
dm.SetVariable("BACKGROUNDPLOT", 0)
dm.ActiveLayout.PlotType = AcPlotType.acExtents
dm.ActiveLayout.StandardScale = AcPlotScale.ac1_1
dm.ActiveLayout.PlotWithPlotStyles = True
dm.ActiveLayout.UseStandardScale = True
dm.ActiveLayout.CenterPlot = True
dm.ActiveLayout.StyleSheet = "AZEVEDO.ctb"
' dm.ActiveLayout.CanonicalMediaName = "ISO_B5_(182.00_x_237.00_MM)"
oAcadApp.Preferences.Output.AutomaticPlotLog = False
oAcadApp.Preferences.Output.ContinuousPlotLog = False
'oAcadApp.Preferences.Output.DefaultOutputDevice = "DWG To PDF.pc3"
oAcadApp.Preferences.Output.DefaultPlotStyleTable = "AZEVEDO.ctb"
dm.Regen(AcRegenType.acActiveViewport)
dm.Plot.QuietErrorMode = True
dm.Plot.NumberOfCopies = 1
dm.ActiveLayout.RefreshPlotDeviceInfo()
dm.Plot.PlotToFile("d:\teste\layouts.pdf", "C:\Program Files\AutoCAD 2009\UserDataCache\Plotters\DWG To PDF.pc3")
'dm.Close(null, null);
'oAcadApp.Quit();
End If
Catch ex As System.Exception
MsgBox(ex.Message & vbLf & ex.StackTrace)
End Try
--------------------------------------------------
C#
--------------------------------------------------
using System;
using System.IO;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
namespace ProcessoCAD
{
static class Program
{
private static Autodesk.AutoCAD.Interop.AcadApplication oAcadApp = null;
private static string sAcadID = "AutoCAD.Application.18";
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// Abre AutoCAD
try
{
oAcadApp = (Autodesk.AutoCAD.Interop.AcadApplication)System.R
}
catch
{
System.Type AcadProg = System.Type.GetTypeFromProgID(sAcadID);
oAcadApp = (Autodesk.AutoCAD.Interop.AcadApplication)System.A
}
// Inicia ciclo de execução
if (oAcadApp != null)
{
string StyleTable = "AZEVEDO.ctb";
// App Visível
oAcadApp.Visible = true;
// Expande Janela
oAcadApp.WindowState = AcWindowState.acMax;
// Documento
Autodesk.AutoCAD.Interop.AcadDocument dm;
dm = oAcadApp.Documents.Open("d:\\teste\\Teste.dwg", true, null);
// Plotagem Síncrona
dm.SetVariable("BACKGROUNDPLOT", 0);
// Seleciona Layout
dm.ActiveSpace = AcActiveSpace.acPaperSpace;
// Configurações da Plotagem
dm.ActiveLayout.PlotType = AcPlotType.acExtents;
dm.ActiveLayout.StandardScale = AcPlotScale.ac1_1;
dm.ActiveLayout.PlotWithPlotStyles = true;
dm.ActiveLayout.UseStandardScale = true;
dm.ActiveLayout.CenterPlot = true;
dm.ActiveLayout.StyleSheet = "AZEVEDO.ctb";
// Aplica Estilo
oAcadApp.Preferences.Output.DefaultPlotStyleTable = StyleTable;
dm.Regen(AcRegenType.acActiveViewport);
// Gera Arquivo
dm.Plot.QuietErrorMode = true;
dm.Plot.NumberOfCopies = 1;
dm.ActiveLayout.RefreshPlotDeviceInfo();
dm.Plot.PlotToFile("d:\\teste\\Teste.pdf", "C:\\Program Files\\AutoCAD 2010\\UserDataCache\\Plotters\\DWG To PDF.pc3");
dm.Close(null, null);
//oAcadApp.Quit();
}
}
}
}

