.NET

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

Insert block in AcadTable

285 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

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;

Solved the problem. Thank you.

*Expert Elite*
Jeff_M
Posts: 4,472
Registered: ‎07-22-2003
Message 2 of 6 (273 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 (265 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 (262 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,472
Registered: ‎07-22-2003
Message 5 of 6 (253 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 (245 Views)

Re: Insert block in AcadTable

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

Solved the problem. Thank you.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!