慢慢来吧 发表于 2017-12-28 09:15:00

DBX 修改块名报错 (已解决)

public void DrawingPretreatment()//String fileFullName, String curNumber)
      {
            String fileFullName = @"E:\001.dwg";
            String curNumber = "1";
            string progid = "ObjectDBX.AxDbDocument.16";
            AxDbDocument objDbx = (AxDbDocument)acadApp.GetInterfaceObject(progid);
            objDbx.Open(fileFullName, null);
            foreach (AcadEntity entity in objDbx.ModelSpace)
            {
                switch (entity.EntityName)
                {
                  case "AcDbBlockReference":
                        AcadBlockReference blkRef;
                        blkRef = (AcadBlockReference)entity;
                        try
                        {
                            blkRef.Name = blkRef.Name + curNumber;//这里出错
                        }
                        catch (Autodesk..Runtime.Exception ex)
                        {
                            throw new System.Exception(ex.Message);
                        }
                        break;
                  case "AcDbOrdinateDimension":
                        break;
                }
            }
            objDbx.SaveAs(fileFullName, null);
            objDbx = null;
      }
AutoCAD 2005& vs2008

慢慢来吧 发表于 2018-1-2 20:10:00

神啊,救救我吧!

慢慢来吧 发表于 2018-1-9 09:55:00

tempDb.ReadDwgFile(curFileName, System.IO.FileShare.ReadWrite, true, null);
                              using (Transaction curTrans = tempDb.TransactionManager.StartTransaction())
                              {
                                    BlockTable curBt = (BlockTable)curTrans.GetObject(tempDb.BlockTableId, OpenMode.ForRead);
                                    int i = 1;
                                    foreach (ObjectId acObjId in curBt)
                                    {
                                        BlockTableRecord br = curTrans.GetObject(acObjId, OpenMode.ForWrite) as BlockTableRecord;
                                        if (br.Name.StartsWith("_OPEN") || br.Name.StartsWith("DimnDraft"))
                                        {
                                          br.Name = spStr.Remove(0, 3) + "-" + i.ToString();
                                          i++;
                                        }
                                    }
                                    // 以写模式打开块表记录ModelSpace(模型空间)
                                    BlockTableRecord acBlkTblRec;
                                    acBlkTblRec = curTrans.GetObject(curBt, OpenMode.ForWrite) as BlockTableRecord;
                                    foreach (ObjectId acObjId in acBlkTblRec)
                                    {
                                        Entity cc = curTrans.GetObject(acObjId, OpenMode.ForWrite) as Entity;
                                        if (cc.GetType().Name == "OrdinateDimension")
                                        {
                                          OrdinateDimension od = cc as OrdinateDimension;
                                          od.DimensionText = "";
                                          //od.UpgradeOpen();
                                        }
                                        if (cc.GetType().Name == "RotatedDimension")
                                        {
                                          RotatedDimension rd = cc as RotatedDimension;
                                          rd.DimensionText = "";
                                          //rd.UpgradeOpen();
                                        }
                                    }
                                    curTrans.Commit();
                              }
页: [1]
查看完整版本: DBX 修改块名报错 (已解决)