I am Using the "Insert" method to import external Dwg file as a block in to my current database.Its working fine.But I am facing Issues in some systems and the Autocad application get crashed while executing the Db.insert.
Refer : http://through-the-interface.typepad.com/through_the_interface/2011/01/combining-autocad-blocks-in-s...
I did Framework 4.5 uninstalled,cleanup and re-installed.And it was working for some time and subsequently it didn't work fro me.
So have decided to use the method described in the below linked post.
**********
IdMapping im = new IdMapping();
db.WblockCloneObjects(
ids,
destDb.BlockTableId,
im,
DuplicateRecordCloning.MangleName,
false
);
/***********
It is Working now in all systems.
Can any one suggest me which method is good and right approach to insert a external drawing as a block.Why my Autocad Appication is getting crashed in some machines if i am using db.Insert.?
I have attached 2 txt files in my codes are available for your reference.
ImportBlock.txt : using db.insert
ImportBLockUsingClone.txt : using Clone method
Regards,
Appadurai.G
Solved! Go to Solution.
Solved by philippe.leefsma. Go to Solution.
Hi Appadurai,
We have a change request logged against the behavior of Insert, unfortunately it isn't fixed yet. One workaround you may want to consider can be to rely on the COM API and use the C# "dynamic" keyword to avoid referencing the AutoCAD COM dlls:
[CommandMethod("INSERTBLOCK")] public void InsertBlock() { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; string strBlock = "c:\\temp\\Testblock.dwg"; //ObjectId blkId; //using (Database dbBlock = new Database(false, false)) //{ // dbBlock.ReadDwgFile(strBlock, System.IO.FileShare.Read, true, ""); // blkId = db.Insert("Testblock", dbBlock, true); //} double[] pt = new double[]{0,0,0}; dynamic acadDoc = doc.GetAcadDocument(); //AcadBlockReference bRef = //acadDoc.ModelSpace.InsertBlock(pt, "drawing.dwg", xScale, yScale, zScale, rot); acadDoc.ModelSpace.InsertBlock(pt, strBlock, 1, 1, 1, 0); }
Philippe.