.NET

Reply
*Artem Shutov
Message 1 of 7 (311 Views)

CopyObjects function problem

311 Views, 6 Replies
05-24-2006 12:29 AM
Hello, is there anybody in there?

Function, which should create new layout, a copy of available layout, in one
document, written on C#:
================
private void layout_new(String strFrom, String strTo,
Autodesk.AutoCAD.Interop.AcadDocument doc)
{
Autodesk.AutoCAD.Interop.Common.AcadLayout objLayOut;
Autodesk.AutoCAD.Interop.Common.AcadLayout objNewLayOut;

objNewLayOut = doc.Layouts.Add(strTo);
objLayOut=colLayOuts.Item(strFrom);
object[] objEntArray = new object[objLayOut.Block.Count];
int intCnt = 0;

foreach (Autodesk.AutoCAD.Interop.Common.AcadObject objEnt in
objLayOut.Block)
{
objEntArray[intCnt] = objEnt;
intCnt=intCnt+1;
}

try
{
doc.CopyObjects(objEntArray[1], objNewLayOut.Block,
ref missing);
objNewLayOut.CopyFrom((Autodesk.AutoCAD.Interop.Common.AcadPlotConfiguration)objLayOut);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}

}
================


Gives out a COMException (0x8021007B) "Incorrect file of objects"
at line "doc.CopyObjects(objEntArray[1], objNewLayOut.Block, ref missing);"

Prompt, please, in what there can be a problem?
Beforehand thanks!


Wish you were here, All!
np: Jimmy Page - Liquid Mercury
*Artem Shutov
Message 2 of 7 (309 Views)

Re: CopyObjects function problem

05-24-2006 12:44 AM in reply to: *Artem Shutov
Hello, is there anybody in there?

Artem Shutov to All × Wed, 24 May 2006 07:29:15 +0000:

... _missing_ ...

AS> doc.CopyObjects(objEntArray[1],
objNewLayOut.Block,
AS> ref missing);

Sorry , mean doc.CopyObjects(objEntArray, objNewLayOut.Block, ref
missing);

and:

AS> Gives out a COMException (0x8021007B) "Incorrect array of objects"

... _missing_ ...

Wish you were here, Artem!
np: Jimmy Page & Robert Plant - Shining In The Light
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 3 of 7 (311 Views)

Re: CopyObjects function problem

05-24-2006 04:19 PM in reply to: *Artem Shutov
Try this code:
[code]
private static void DuplicateLayout(String strFrom, String strTo,
Autodesk.AutoCAD.Interop.AcadDocument doc)
{
Autodesk.AutoCAD.Interop.Common.AcadLayout objLayOut = null;
Autodesk.AutoCAD.Interop.Common.AcadLayout objNewLayOut = null;

try
{
objLayOut = doc.Layouts.Item(strFrom);
objNewLayOut = doc.Layouts.Item(strTo);
}
catch (System.Exception)
{
objNewLayOut = doc.Layouts.Add(strTo);
}

if (objLayOut != null && objNewLayOut != null)
{
Object missing = Type.Missing;
try
{
Autodesk.AutoCAD.Interop.Common.AcadEntity[] blks =
new Autodesk.AutoCAD.Interop.Common.AcadEntity[objLayOut.Block.Count];
for (int j=0; j < blks.Length; j++) {
blks = objLayOut.Block.Item(j);
}
doc.Database.CopyObjects(blks, objNewLayOut.Block, ref missing);
objNewLayOut.CopyFrom((Autodesk.AutoCAD.Interop.Common.AcadPlotConfiguration)objLayOut);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
}
}
[/code]
*Artem Shutov
Message 4 of 7 (309 Views)

Re: CopyObjects function problem

05-24-2006 09:48 PM in reply to: *Artem Shutov
Hello, is there anybody in there?

Alexander Rivilis at Wed, 24 May 2006 23:23:25 +0000:

AR> Try this code:
AR> [code]

... _ÐÒÏÐÕÝÅÎÏ_ ...

AR> [/code]

Many thanks!
It works!

Wish you were here, Alexander!
np: John Mayall - What'd I Say
Active Contributor
d00_ape
Posts: 49
Registered: ‎08-17-2004
Message 5 of 7 (309 Views)

Re: CopyObjects function problem

06-15-2006 11:06 AM in reply to: *Artem Shutov
In which dll do I find Autodesk.AutoCAD.Interop.Common?
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 6 of 7 (309 Views)

Re: CopyObjects function problem

06-15-2006 04:02 PM in reply to: *Artem Shutov
Add Reference > COM Tab > AutoCAD 200? Type Library.

Regards - Nathan
Active Contributor
d00_ape
Posts: 49
Registered: ‎08-17-2004
Message 7 of 7 (309 Views)

Re: CopyObjects function problem

06-16-2006 12:39 AM in reply to: *Artem Shutov
Ok, I got an exclamation mark on the added AutoCad refference in Visual Studio.

Do you know how it can be that?
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.