.NET

Reply
Active Contributor
gadurai
Posts: 36
Registered: ‎04-08-2006
Message 1 of 2 (135 Views)
Accepted Solution

Which is best method to insert an external Dwg as a block

135 Views, 1 Replies
05-05-2014 04:05 AM

 

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.

 

Refer: http://through-the-interface.typepad.com/through_the_interface/2011/01/combining-autocad-blocks-in-s...

 

**********

 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

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.

 

 

ADN Support Specialist
philippe.leefsma
Posts: 631
Registered: ‎06-02-2009
Message 2 of 2 (96 Views)

Re: Which is best method to insert an external Dwg as a block

05-06-2014 12:25 AM in reply to: gadurai

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.

 

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

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.