第2部分:
1)动态块存储的一个小技巧是在一个图形中创建它,然后使用wblock命令将其保存为自己的图形(见图)。
2)在通过.net/autocad API导入之前,是否有人知道我可以确定图形是否是这样的动态块的方法?当我使用下面的代码导入它时,它会将其作为一个典型的块插入,没有动态功能。我得把它炸了。
感谢您提供的任何意见/建议
- public void blocktry()
- {
- Insert.Enabled = false;
- Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
- Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
- Editor ed = acDoc.Editor;
- using (DocumentLock lockmedoc = acDoc.LockDocument())
- {
- string blockName = listBox1.SelectedItem.ToString();
- string blockQualifiedFileName = path + "\" + comboBox1.Text + "\" + listBox1.SelectedItem.ToString() + ".dwg";
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- try
- {
- BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
- if (!bt.Has(blockName))
- {
- Database tmpDb = new Database(false, true);
- tmpDb.ReadDwgFile(blockQualifiedFileName, System.IO.FileShare.Read, true, "");
- // add the block to the ActiveDrawing blockTable
- try
- {
- db.Insert(blockName, tmpDb, true);
- }
- catch
- {
- }
- }
- PromptPointResult ppr = ed.GetPoint("\nSpecify insertion point: ");
- if (ppr.Status == PromptStatus.Cancel)
- Insert.Enabled = true;
- if (ppr.Status != PromptStatus.OK)
- return;
- BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- BlockReference br = new BlockReference(Point3d.Origin, bt[blockName]);
- br.ScaleFactors = new Scale3d(1);
- br.Rotation = 0;
- br.TransformBy(Matrix3d
- .Displacement(ppr.Value - Point3d.Origin)
- .PreMultiplyBy(ed.CurrentUserCoordinateSystem));
- btr.AppendEntity(br);
- tr.AddNewlyCreatedDBObject(br, true);
- ed.WriteMessage("\n" + br.Name + " Inserted");
- Insert.Enabled = true;
- }
- catch (Autodesk.AutoCAD.Runtime.Exception exx)
- {
- ed.WriteMessage("\n" + exx.ToString());
- Insert.Enabled = true;
- }
- tr.Commit();
- tr.Dispose();
- }
- }
- }
fnwsqnfix4q.JPG
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |