使用ObjectArx将现有dwg文件添加到新图形的正确方法
我正在创建一个新的dwg文件,如下所示:DocumentCollection acDocMgr = acApp.DocumentManager;
Document acDoc = acDocMgr.Add("acad");
acApp.DocumentManager.MdiActiveDocument = acDoc;
我要做的下一件事是将现有的dwg文件导入到这个新图形中。 我的问题是,将现有 dwg 图形导入新图形的正确方法是什么?主要关注点是新图形不会以任何方式进行修改。 以下是我见过的一些方法,但我想确保我没有修改要导入到新图形中的原始图形:
使用DocumentManager
DocumentCollection acDocMgr = Application.DocumentManager;
acDocMgr.Open(strFileName, false);
方法2的方法1,使用ReadDwgFile
Using db As New Database(False, True)
db.ReadDwgFile(strFileName, FileOpenMode.OpenForReadAndWriteNoShare, True, "")
再次,我所寻找的只是在不修改原始dwg文件的情况下将现有dwg导入到新图形中的正确方法。 谢谢。
**** Hidden Message ***** Database.Insert(matrixTransform, source ceDb, HRC veSourceDb)将源数据库的Modelspace插入到调用该方法的数据库中。 杰夫:谢谢!快速问题:由于新图形当前处于打开状态,我应该将第一个参数(blockName)设置为什么?以下是我到目前为止所做的:
// Get the current document and database
Document doc = acApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = acApp.DocumentManager.MdiActiveDocument.Database;
// Create a temporary database to import an existing file
using (Database tmpDB = new Database(false, false))
{
string strPath = @"C:\a\1.dwg";
// Read the 'strPath' file into the new database
tmpDB.ReadDwgFile(strPath, System.IO.FileShare.Read, true, "");
// Try to insert our the dwg file as a block and get the return id of
// the new block table record.
ObjectId BlockID = db.Insert(blockName, tmpDB, true);
}
如果使用我展示的方法,第一个参数是用于转换的矩阵3d。你可能希望这是没有转换。您不需要提供名称,也不需要将块定义插入到modelspace中,因为函数会为您这样做
“通过调用insert()函数将数据库指向的数据库模型空间插入数据库的模型空间。在插入过程中,所有插入的对象都将变换矩阵传递到其transformBy()函数中。” 如果第一步是克隆图形并将其打开。那么为什么不先使用File.Copy()呢? 然后只需打开新文件? 谢谢Jeff,我最终使用了你的建议并将matrixTransform参数设置为null。这很好。 杰夫,我认为它是工作的,但我有一个问题。当我创建第一个绘图并使用“db.insert”方法时,它工作正常。但是,如果我让autocad保持打开状态并创建另一个图形,则“db.insert”将不再插入该图形。
页:
[1]