.NET

Reply
Member
cyconnely
Posts: 5
Registered: ‎01-26-2014
Message 1 of 3 (233 Views)
Accepted Solution

Trouble with interop Import Command

233 Views, 2 Replies
01-26-2014 04:08 PM

I'm writing a program to import a WMF into the AutoCad Drawing. I haven't been able to find any reference for the import command, so I can't figure out why it's not working. According to Visual Studio, the Import command needs these things to work.

Code:
acadDoc.Import(FileName As String, InsertionPoint As Object, ScaleFactor As Double) As Object

 

Simplified Code:

Code:
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Interop

Dim AcadApp As Autodesk.AutoCAD.Interop.AcadApplication
AcadApp = CType(GetObject(, "AutoCAD.Application.18.2"), Autodesk.AutoCAD.Interop.AcadApplication)
acadDoc = AcadApp.ActiveDocument

acadDoc.Import("C:\Users\C\Documents\Drawing1.wmf", New Point3d(2, 2, 0), 2.0)

When I comment out the last line of code,

Code:
acadDoc.Import("C:\Users\C\Documents\Drawing1.wmf", New Point3d(2, 2, 0), 2.0)

It runs fine.

The error I'm getting is when I run it AutoCAD,

Code:
************** Exception Text **************
System.ArgumentException: Value does not fall within the expected range.
   at System.StubHelpers.ObjectMarshaler.ConvertToNative(Object objSrc, IntPtr pDstVariant)
   at Autodesk.AutoCAD.Interop.IAcadDocument.Import(String FileName, Object InsertionPoint, Double ScaleFactor)
   at TestSelectingFiltering.TestSelecting.MyCommands.FilterBlueCircleOnLayer0()
   at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()

Any help would be greatly appreciated,
Thanks!

Well, the error message says exactly why the exception happems: ArgumentException, which means one of the parameter you passed to the AcadDocument.Import() method is wrong.

 

The second argument of the Import method expects a ARRAY of double (3 elements), representing an point. What you passed in is an Point3d staructure. Acad COM object does not know what Point3d is.

 

So, you need to change your code like:

 

Dim point(0 To 2) as double

point(0)=2.0 : point(1)=2.0 : point(2)=0.0

acadDoc.Import("C:\Users\C\Documents\Drawing1.wmf", point, 2.0)

 

 

*Expert Elite*
norman.yuan
Posts: 998
Registered: ‎04-27-2009
Message 2 of 3 (214 Views)

Re: Trouble with interop Import Command

01-26-2014 06:45 PM in reply to: cyconnely

Well, the error message says exactly why the exception happems: ArgumentException, which means one of the parameter you passed to the AcadDocument.Import() method is wrong.

 

The second argument of the Import method expects a ARRAY of double (3 elements), representing an point. What you passed in is an Point3d staructure. Acad COM object does not know what Point3d is.

 

So, you need to change your code like:

 

Dim point(0 To 2) as double

point(0)=2.0 : point(1)=2.0 : point(2)=0.0

acadDoc.Import("C:\Users\C\Documents\Drawing1.wmf", point, 2.0)

 

 

Member
cyconnely
Posts: 5
Registered: ‎01-26-2014
Message 3 of 3 (210 Views)

Re: Trouble with interop Import Command

01-26-2014 06:51 PM in reply to: norman.yuan
Awesome!! Thanks, this was driving me crazy.
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.