开发者

AInsert 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


bloqueId is the object ID of the specific block reference picked by the user. SetBlockTableRecordId needs the ID of the block definition in the drawing's block table. These are completely different types (classes), so that's what the error message means.

The Autodesk.AutoCAD.DatabaseServices.BlockReference class has a BlockTableRecord property that returns the object ID you want. My recommendation would be to redo your code to use those native C# classes everywhere instead of the Autodesk.AutoCAD.Interop (COM) classes you're currently using.

If you can't change to native classes for some reason, then the best I can find is that the AcadBlockReference class you are using exposes a Name property that is the block name, and you should be able to look up the block definition ID from the block table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜