.NET

.NET

Reply
Active Contributor
44 Posts
2 Kudos
Registered: ‎04-08-2006
Post 1 of 2
Accepted Solution

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

160 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
685 Posts
80 Kudos
Registered: ‎06-02-2009
Post 2 of 2

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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post