- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
Recently, I have set up a c# project for plotting the .dwg file to .pdf file. However, when I try to debug the project, it has the following error:
I am using AutoCAD 2013 and Visual Studio 2010 C# express.
Here is the code of the program:
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using LWKDrawing;
using Autodesk.AutoCAD.DatabaseServices;
using Ionic.Zip;
using ConvertPDF;
namespace LWKpdfProcess
{
class Program
{
static void Main(string[] args)
{
new LWKHost();
String thisprocess = Process.GetCurrentProcess().ProcessName;
if (Process.GetProcesses().Count(p => p.ProcessName == thisprocess) > 1)
return;
registrationCycle();
}
protected static void registrationCycle()
{
//Open AutoCAD
Process[] pname = Process.GetProcessesByName("acad");
if (pname.Length > 0)
{
PDFConversionClass.PublishLayouts(); // Here is the code which pop up the exception
}
else
{
StreamReader textFile = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "Program.ini");
string ProgramPath = textFile.ReadLine();
textFile.Close();
Process p = new Process();
p.StartInfo.FileName = ProgramPath;
p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
p.Start();
p.WaitForExit();
}
}
}
}
PDFConversionClass.PublishLayouts(); , this code is calling the method "PublishLayouts()" in the class library ConvertPDF, Here is the code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices.Core;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.PlottingServices;
using Autodesk.AutoCAD.Publishing;
using Autodesk.AutoCAD.ApplicationServices;
using System.Collections.Specialized;
using System.Diagnostics;
namespace ConvertPDF
{
public class PDFConversionClass
{
// Publishes layouts to a PDF file
[CommandMethod("PublishLayouts")]
public static void PublishLayouts()
{
short bgPlot = (short)Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("BACKGROUNDPLOT");
}
}
}
For this class library, I have added reference:
accoremgd.dll
acmgd.dll
acdbmgd.dll
All are Copy Local : false and point directly insides the folder C:\Program Files\Autodesk\AutoCAD 2013.
Could anyone tell me the possible cause of the exception and the solution?
Solved! Go to Solution.