指定基点插入dwg文件,如何做?
<p><font face="Verdana"> 这是《手册》上的代码,画两个圆并复制到另一个文件里,我想复制过去后将圆放在我指定的位置,请教大家看看,如何修改</font></p><p><font face="Verdana"></font> </p>
<p><font face="Verdana"></font> </p>
<p><font face="Verdana"> <br/> public static void CopyObjectsBetweenDatabases()<br/> {<br/> ObjectIdCollection acObjIdColl = new ObjectIdCollection();</font></p>
<p><font face="Verdana"> // Get the current document and database<br/> Document acDoc = Application.DocumentManager.MdiActiveDocument;<br/> Database acCurDb = acDoc.Database;</font></p>
<p><font face="Verdana"> // Lock the current document<br/> using (DocumentLock acLckDocCur = acDoc.LockDocument())<br/> {<br/> // Start a transaction<br/> using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())<br/> {<br/> // Open the Block table record for read<br/> BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;</font></p>
<p><font face="Verdana"> // Open the Block table record Model space for write<br/> BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl, OpenMode.ForWrite) as BlockTableRecord;</font></p>
<p><font face="Verdana"> // Create a circle that is at (0,0,0) with a radius of 5<br/> Circle acCirc1 = new Circle();<br/> acCirc1.SetDatabaseDefaults();<br/> acCirc1.Center = new Point3d(0, 0, 0);<br/> acCirc1.Radius = 5;</font></p>
<p><font face="Verdana"> // Add the new object to the block table record and the transaction<br/> acBlkTblRec.AppendEntity(acCirc1);<br/> acTrans.AddNewlyCreatedDBObject(acCirc1, true);</font></p>
<p><font face="Verdana"> // Create a circle that is at (0,0,0) with a radius of 7<br/> Circle acCirc2 = new Circle();<br/> acCirc2.SetDatabaseDefaults();<br/> acCirc2.Center = new Point3d(0, 0, 0);<br/> acCirc2.Radius = 7;</font></p>
<p><font face="Verdana"> // Add the new object to the block table record and the transaction<br/> acBlkTblRec.AppendEntity(acCirc2);<br/> acTrans.AddNewlyCreatedDBObject(acCirc2, true);</font></p>
<p><font face="Verdana"> // Add all the objects to copy to the new document<br/> acObjIdColl = new ObjectIdCollection();<br/> acObjIdColl.Add(acCirc1.ObjectId);<br/> acObjIdColl.Add(acCirc2.ObjectId);</font></p>
<p><font face="Verdana"> // Save the new objects to the database<br/> acTrans.Commit();<br/> }</font></p>
<p><font face="Verdana"> // Unlock the document<br/> }</font></p>
<p><font face="Verdana"> // Change the file and path to match a drawing template on your workstation<br/> string sLocalRoot = Application.GetSystemVariable("LOCALROOTPREFIX") as string;<br/> string sTemplatePath = sLocalRoot + "Template\\acad.dwt";</font></p>
<p><font face="Verdana"> // Create a new drawing to copy the objects to<br/> DocumentCollection acDocMgr = Application.DocumentManager;<br/> Document acNewDoc = acDocMgr.Add(sTemplatePath);<br/> Database acDbNewDoc = acNewDoc.Database;</font></p>
<p><font face="Verdana"> // Lock the new document<br/> using (DocumentLock acLckDoc = acNewDoc.LockDocument())<br/> {<br/> // Start a transaction in the new database<br/> using (Transaction acTrans = acDbNewDoc.TransactionManager.StartTransaction())<br/> {<br/> // Open the Block table for read<br/> BlockTable acBlkTblNewDoc;<br/> acBlkTblNewDoc = acTrans.GetObject(acDbNewDoc.BlockTableId,<br/> OpenMode.ForRead) as BlockTable;</font></p>
<p><font face="Verdana"> // Open the Block table record Model space for read<br/> BlockTableRecord acBlkTblRecNewDoc;<br/> acBlkTblRecNewDoc = acTrans.GetObject(acBlkTblNewDoc,<br/> OpenMode.ForRead) as BlockTableRecord;</font></p>
<p><font face="Verdana"> // Clone the objects to the new database<br/> IdMapping acIdMap = new IdMapping();<br/> acCurDb.WblockCloneObjects(acObjIdColl, acBlkTblRecNewDoc.ObjectId, acIdMap,<br/> DuplicateRecordCloning.Ignore, false);</font></p>
<p><font face="Verdana"> // Save the copied objects to the database<br/> acTrans.Commit();<br/> }<br/> foreach(ObjectId id in acObjIdColl)<br/> {</font></p>
<p><font face="Verdana"> CxwEdit.Mirror(id, new Point3d(100, 100, 0), new Point3d(100, 200, 0), false);<br/> }<br/> // Unlock the document<br/> }</font></p>
<p><font face="Verdana"> // Set the new document current<br/> // acDocMgr.MdiActiveDocument = acNewDoc;<br/> }</font></p> <p>对不起,以下两句是我加的,不能正确运行, </p>
<p> foreach(ObjectId id in acObjIdColl)<br/> { </p>
<p><font face="Verdana"> CxwEdit.Mirror(id, new Point3d(100, 100, 0), new Point3d(100, 200, 0), false);<br/> }</font></p> <p>你的acObjIdColl是源数据库的,</p>
<p>应该改变的是目标数据库</p> 看不懂,但一定要顶
页:
[1]