nobody 发表于 2019-6-14 00:39:37

外部图形是动态块吗

第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);
                        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();
                }
            }
      }



**** Hidden Message *****

nobody 发表于 2019-6-14 01:15:41

没有关系。只需重写块插入以检查内容

gile 发表于 2019-6-14 01:17:46

Hi,
没有深入测试,但可以检查模型空间块表记录的扩展字典是否包含“ACAD_ENHANCEDBLOCK”。

nobody 发表于 2019-6-14 01:50:09


谢谢
页: [1]
查看完整版本: 外部图形是动态块吗