How insert block from another dwg file? #372
Answered
by
DomCR
davi-blsoftwares
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
To import a block record from another document you can use this code as an example: //Read the document
CadDocument doc;
using (DwgReader reader = new DwgReader(_file))
{
doc = reader.Read();
}
//Create a new document or read another one
CadDocument transfer = new CadDocument();
//Create a clone of the block that you want to import to the new document
BlockRecord block = (BlockRecord)doc.BlockRecords["MyBlock"].Clone();
transfer.BlockRecords.Add(block);
//Save the changes
using (DwgWriter writer = new DwgWriter(outPath, transfer))
{
writer.Write();
}While using this code I've noticed an error in the clone method, I've open a branch to fix it. If you are using the Nuget Package please let me know and I'll make a release once is fixed. Hope this helps! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I would like insert blocks from another dwg files.
In AutoCAD i use this method:
///
/// Carrega bloco no dwg
///
/// Caminho completo do bloco
/// Nome do bloco
/// Retorna o ObjectId da definição do bloco
/// Retorna true se o bloco foi carregado senão false
public static bool loadBlock(string blockFileName, string blockName, ref ObjectId blockId)
{
blockName = blockName.Trim();
try
{
Database curDb = Application.DocumentManager.MdiActiveDocument.Database;
Database blockDb = new Database(false, true);
#if ZWCAD
var modo = FileShare.Read;
#else
var modo = FileOpenMode.OpenForReadAndAllShare;
#endif
How make this in AcadSharp?
Beta Was this translation helpful? Give feedback.
All reactions