AcadDocument.Import() throws System.ArgumentException
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I'm trying to automate importing Microstation files into AutoCad (and then doing interesting things with them). I'm stuck on the import, as it keeps throwing an "Invalid Argument Exception".
I've beaten my head against this one... for the filename, I've thrown empty strings, "hello world" strings, ensured that the string points to a valid file, ensured that the string points to a vaild Microstation file... for the scale factor, I've thrown constants, symbolic constants, variable doubles... and where I think the error lies, the insertion point, I've thrown Points, Point2d's, Point3d's, arrays of integers, arrays of doubles, and AcadPoints, and all of the above even cast as objects.
Supposedly, the signature for import is:
object IAcadDocument.Import(string FileName, object InsertionPoint, double ScaleFactor)
but the <object InsertionPoint> is throwing me... what kind of object is wanted? I'm assuming an AcadPoint but how do I know?
The following is a complete working program; you'll just have to add the two autocad references.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
namespace Snippet
{
class Program
{
static void Main(string[] args)
{
const string DEFAULTACADDWG = "c:\\users\\greg.mathews\\0.dwg";
string fullname = "c:\\users\\greg.mathews\\0.dgn";
const string strProgId = "AutoCAD.Application.18";
double[] zerozero = { 0.0, 0.0, 0.0 };
double SCALEFACTORONE = 1.0;
AcadApplication acAppComObj = (AcadApplication)Marshal.GetActiveObject(strProgId);
AcadDocument newdoc = acAppComObj.Documents.Open(DEFAULTACADDWG);
AcadDatabase db = newdoc.Database;
AcadPoint insertPoint = db.ModelSpace.AddPoint(zerozero);
Console.WriteLine("Importing: " + fullname);
try
{
newdoc.Import(fullname, insertPoint, SCALEFACTORONE); //<<< Exception thrown here >>>
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}
and the exception detail
System.ArgumentException was unhandled
HelpLink=C:\Program Files\AutoCAD Map 3D 2010\HELP\OLE_ERR.CHM#-2145320901
Message=Invalid argument
Source=AutoCAD
StackTrace:
at Autodesk.AutoCAD.Interop.AcadDocumentClass.Import(String FileName, Object InsertionPoint, Double ScaleFactor)
at Snippet.Program.Main(String[] args) in c:\users\greg.mathews\documents\visual studio 2010\Projects\Snippet\Snippet\Program.cs:line 32
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Versions I'm using:
Microsoft Visual Studio 10
Target Framework is .Net 3.5
AutoCAD Map3D 2010
c:\users\greg.mathews\0.dwg is a valid, empty, autocad 2010 drawing
c:\users\greg.mathews\0.dgn is a valid 168 kb Microstation file
(Obviously the intent is not to use hard coded filenames, these are for debug purposes. I'm also running as a Windows project rather than a Console project, but the exception is the same.)
Anyway. Thanks in advance for taking time to read.