.NET

Reply
Contributor
jlsantiago
Posts: 14
Registered: ‎03-29-2011
Message 1 of 6 (284 Views)
Accepted Solution

Insert block in AcadTable

284 Views, 5 Replies
04-13-2011 02:28 AM
I need to insert an AcadBlockReference into AcadTable, but i've got an error with the block ObjectId property. 


//*****************Sample Code*************************************
AcadApplication
 gbl_app = null;
AcadDocument gbl_doc = null;
AcadLayout presentacion = null;
AcadTable tablaAcad = null;
            gbl_app = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application");
gbl_doc = gbl_app.ActiveDocument;
object AC_entidad = new object();
object basePnt2 = null;

gbl_doc.Utility.GetEntity(out AC_entidad, out basePnt2, "Seleccione objeto:");
AcadBlockReference objBlock = (AcadBlockReference)AC_entidad;
bloqueId = objBlock.ObjectID;

double[] vertices = new double [3];
vertices[0] = 49.24;
vertices[1] = 155;
vertices[2] = 0;


tablaAcad = gbl_doc.ActiveLayout.Block.AddTable(vertices, 4, 2, 3, 10);
tablaAcad.SetCellTextHeight(0, 0, 2);

tablaAcad.SetTextHeight(5, 1.5);
tablaAcad.SetColumnWidth(0, 5);
tablaAcad.SetColumnWidth(1, 50);

tablaAcad.SetBlockTableRecordId(3, 0, bloqueId , true);

//ERROR: Not valid class
*Expert Elite*
Jeff_M
Posts: 4,297
Registered: ‎07-22-2003
Message 2 of 6 (272 Views)

Re: Insert block in AcadTable

04-13-2011 02:01 PM in reply to: jlsantiago

The SetBlockTableRecordId() needs the Id of the BLOCK, not the BlockReference as you are passing.

 

Change this: 

bloqueId = objBlock.ObjectId;

to this:

bloqueId = objBlock.BlockTableRecord;

Jeff_M, also a frequent Swamper
Contributor
jlsantiago
Posts: 14
Registered: ‎03-29-2011
Message 3 of 6 (264 Views)

Re: Insert block in AcadTable

04-13-2011 03:01 PM in reply to: Jeff_M

objBlock does not allow me to use "BlockTableRecord"

Contributor
jlsantiago
Posts: 14
Registered: ‎03-29-2011
Message 4 of 6 (261 Views)

Re: Insert block in AcadTable

04-13-2011 03:13 PM in reply to: jlsantiago

I'm not using API.NET

*Expert Elite*
Jeff_M
Posts: 4,297
Registered: ‎07-22-2003
Message 5 of 6 (252 Views)

Re: Insert block in AcadTable

04-13-2011 07:27 PM in reply to: jlsantiago

OK, sorry about that, same idea, though. You still need the BlockId, it's just a bit different to get it. I don't have Acad here to test, but based on the code you posted, this should work:

 

bloqueId = gbl_doc.Blocks.Item(objBlock.Name).ObjectID;

Jeff_M, also a frequent Swamper
Contributor
jlsantiago
Posts: 14
Registered: ‎03-29-2011
Message 6 of 6 (244 Views)

Re: Insert block in AcadTable

04-13-2011 10:37 PM in reply to: Jeff_M

Solved the problem. Thank you.

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.