I have two drawings, dg1 and dg2. I have defined a block 'b1' in dg1 which I want to copy in dg2. It works well in Early Binding but giving error when I try code in late binding. The code in question is:
private void Form1_Load(object sender, EventArgs e)
{
AcadApplication m_oAcadApp = null;
AcadCircle circle = null;
AcadAcCmColor color = null;
AcadDocument oSourceFile = null;
AcadDocument m_oActiveDoc = null;
try
{
object obj = Marshal.GetActiveObject("AutoCAD.Application.17");
if (obj != null)
{
m_oAcadApp = obj as AcadApplication;
m_oActiveDoc = m_oAcadApp.ActiveDocument;
foreach (AcadDocument oTempDoc in m_oAcadApp.Documents)
{
if((@"c:\d1.dwg").ToUpper() == oTempDoc.FullName.ToUpper())
{
Console.WriteLine(oTempDoc.FullName);
oSourceFile = oTempDoc;
break;
}
}
try
{
object[] objCollection = new object[1];
objCollection[0] = null;
objCollection[0] = oSourceFile.Blocks.Item("b1");
oSourceFile.CopyObjects(objCollection, m_oActiveDoc.Blocks);
}
catch (Exception ex)
{
MessageBox.Show("Opening Blocks " + ex.Message);
}
/*double[] cen = new double[] { 0, 0, 0 };
circle = m_oAcadApp.ActiveDocument.Database.ModelSpace.AddCircle(cen, 2);
color = m_oAcadApp.GetInterfaceObject("Autocad.AcCmColor.17") as AcadAcCmColor;
color.SetRGB(150, 150, 250);
circle.TrueColor = color;
m_oAcadApp.ZoomExtents();
* */
}
}
catch (Exception ex)
{
MessageBox.Show("AutoCAD not opened");
}
finally
{
// if (color != null) Marshal.FinalReleaseComObject(color);
//if (circle != null) Marshal.FinalReleaseComObject(circle);
if (m_oAcadApp != null) Marshal.FinalReleaseComObject(m_oAcadApp);
}
}
And I get exception: Invalid object array exception while I try to copy a block in other drawing.
How do I do it in late Binding?
I am using Autocad 2009.
The Objective of implement Late Binding for Autocad and copying Object
Thanks