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

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

1 REPLY 1
SOLVED
Reply
Message 1 of 2
gadurai
465 Views, 1 Reply

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

 

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

1 REPLY 1
Message 2 of 2
philippe.leefsma
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

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