Message 1 of 5
AutoCAD COM interop without referenced DLL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello I have a problem, I want to use the AutoCAD COM interop without referencing the "Interop.AutoCAD" dll. This code works fine when I reference the "Interop.AutoCAD" dll in the project.
class Program
{
static dynamic acApp;
static dynamic doc;
static dynamic modelSpace;
static void Main(string[] args)
{
if (AcadConnection())
{
object pickedObject = null;
object pickPoint = new object[3];
doc.Utility.GetEntity(out pickedObject, out pickPoint, "Sélectionnez un objet texte :");
if (pickedObject != null)
{
// TODO
}
}
}
static bool AcadConnection()
{
const string strProgId = "AutoCAD.Application";
try
{
acApp = (dynamic)ExMarshal.GetActiveObject(strProgId);
}
catch
{
try
{
acApp = (dynamic)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true);
}
catch
{
Console.WriteLine("CannotCreateAnInstanceAutoCADApplication");
return false;
}
}
if (acApp != null)
{
string version = acApp.Version;
try
{
while (true)
{
try { acApp.Visible = true; break; }
catch { }
}
doc = acApp.ActiveDocument;
modelSpace = doc.ModelSpace;
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
return false;
}
}
But at this row:
doc.Utility.GetEntity(out pickedObject, out pickPoint, "Sélectionnez un objet texte :");
I get this error: "Could not convert argument 2 for call to GetEntity."
Could you help me, thank you.