.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Insert block in AcadTable

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
jlsantiago
511 Views, 5 Replies

Insert block in AcadTable

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
Tags (1)
5 REPLIES 5
Message 2 of 6
Jeff_M
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
EESignature
Message 3 of 6
jlsantiago
in reply to: Jeff_M

objBlock does not allow me to use "BlockTableRecord"

Message 4 of 6
jlsantiago
in reply to: jlsantiago

I'm not using API.NET

Message 5 of 6
Jeff_M
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
EESignature
Message 6 of 6
jlsantiago
in reply to: Jeff_M

Solved the problem. Thank you.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost