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

Insert Method

2 REPLIES 2
Reply
Message 1 of 3
steve
354 Views, 2 Replies

Insert Method

Can someone give me an example of how you would insert the modelspace entities from an external drawing file into the active drawing with .net?

Thanks,

Steve
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: steve

Hello,

I use C# with VS 2003 and AutoCAD 2005. I haven't quite figured out how to
write attributes to it yet, but this is a start (the code is pasted at the
end).

Does anyone out there know of a way to call AutoCAD commands from C#? In
ObjectARX C++ there was the acedCommand method, so I could use:
acedCommand(RTSTR, "-INSERT", RTSTR, "My Block", ... etc etc)

It would be nice to have that again.

Hope this helps. I'm curious about the other responses too.

-Carlos

public void InsertIntoAutoCAD()

{

// Insert the block into the AutoCAD model

try

{

Document doc = Application.DocumentManager.MdiActiveDocument;

string fname = "C:\\Blocks\\My Block.dwg";

using (Database db = new Database(false, false))

{

//read block drawing

db.ReadDwgFile(fname, System.IO.FileShare.Read, true, null);

using (Transaction t = doc.TransactionManager.StartTransaction())

{

//insert the new block

Autodesk.AutoCAD.ApplicationServices.CommandLinePrompts.Message("\n
Inserting the block...");

ObjectId idBTR = doc.Database.Insert("My Block",db,false);

//create a ref to the block

BlockTable bt = (BlockTable)t.GetObject(doc.Database.BlockTableId,
OpenMode.ForRead);

BlockTableRecord btr =
(BlockTableRecord)t.GetObject(bt[BlockTableRecord.ModelSpace],
OpenMode.ForWrite);

Autodesk.AutoCAD.Geometry.Point3d location = new Point3d(0.0, 0.0, 0.0);

using (BlockReference bref = new BlockReference(location, idBTR))

{

btr.AppendEntity(bref);

t.TransactionManager.AddNewlyCreatedDBObject(bref, true);

t.Commit();

}

}

}

catch

{

}

}

wrote in message news:4906068@discussion.autodesk.com...
Can someone give me an example of how you would insert the modelspace
entities from an external drawing file into the active drawing with .net?

Thanks,

Steve
Message 3 of 3
Anonymous
in reply to: steve

Never mind...

I guess you can't. I had missed the other posts on the acedCommand topic.

-Carlos

"Carlos" wrote in message
news:4906567@discussion.autodesk.com...
Hello,

I use C# with VS 2003 and AutoCAD 2005. I haven't quite figured out how to
write attributes to it yet, but this is a start (the code is pasted at the
end).

Does anyone out there know of a way to call AutoCAD commands from C#? In
ObjectARX C++ there was the acedCommand method, so I could use:
acedCommand(RTSTR, "-INSERT", RTSTR, "My Block", ... etc etc)

It would be nice to have that again.

Hope this helps. I'm curious about the other responses too.

-Carlos

public void InsertIntoAutoCAD()

{

// Insert the block into the AutoCAD model

try

{

Document doc = Application.DocumentManager.MdiActiveDocument;

string fname = "C:\\Blocks\\My Block.dwg";

using (Database db = new Database(false, false))

{

//read block drawing

db.ReadDwgFile(fname, System.IO.FileShare.Read, true, null);

using (Transaction t = doc.TransactionManager.StartTransaction())

{

//insert the new block

Autodesk.AutoCAD.ApplicationServices.CommandLinePrompts.Message("\n
Inserting the block...");

ObjectId idBTR = doc.Database.Insert("My Block",db,false);

//create a ref to the block

BlockTable bt = (BlockTable)t.GetObject(doc.Database.BlockTableId,
OpenMode.ForRead);

BlockTableRecord btr =
(BlockTableRecord)t.GetObject(bt[BlockTableRecord.ModelSpace],
OpenMode.ForWrite);

Autodesk.AutoCAD.Geometry.Point3d location = new Point3d(0.0, 0.0, 0.0);

using (BlockReference bref = new BlockReference(location, idBTR))

{

btr.AppendEntity(bref);

t.TransactionManager.AddNewlyCreatedDBObject(bref, true);

t.Commit();

}

}

}

catch

{

}

}

wrote in message news:4906068@discussion.autodesk.com...
Can someone give me an example of how you would insert the modelspace
entities from an external drawing file into the active drawing with .net?

Thanks,

Steve

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