mrl989 发表于 2016-7-5 13:24:47

如何编辑插入的动态块的属性文本字符串和参数值

我可以使用VB.NET修改插入的普通块引用的属性文本字符串,但它不适用于插入的动态块。请帮我把这件事做好。
**** Hidden Message *****

Atook 发表于 2016-7-5 23:48:58

如果你把你目前得到的代码发给我们,即使它不工作,你也更有可能得到回应。
我们喜欢在这里阅读代码。

mrl989 发表于 2016-7-6 08:32:54


    Public Sub UpdateAtt(ByVal tr As Transaction, ByVal objID As ObjectId)      
            Dim br As BlockReference = DirectCast(tr.GetObject(objID, OpenMode.ForWrite), BlockReference)
            Dim btr As BlockTableRecord = DirectCast(tr.GetObject(br.DynamicBlockTableRecord, OpenMode.ForWrite), BlockTableRecord)
      
            For Each attID As ObjectId In btr
                Dim ent As DBObject = tr.GetObject(attID, OpenMode.ForWrite)
                If TypeOf ent Is AttributeDefinition Then
                  Dim AttDef As AttributeDefinition = ent
                  If AttDef.Tag = "SH" Then AttDef.TextString = "111"                  
                End If            Next

如果br不是动态块,br的属性可以通过br的属性集合进行编辑,但不适用于动态块,因此我认为这项工作可以通过属性定义完成,但也不起作用,感谢阅读。。。

Atook 发表于 2016-7-6 10:29:12

我不会说VB,但看起来你是在遍历块定义中的attdef,而不是block ref。以下是我用来更新块中属性的代码,请注意,我正在遍历blockref.AttributeCollection.中的属性希望这有所帮助。///。
///更新属性,。
>/// ///块引用对象ID,。
//其中键是标签的字典,文本字符串的值。
公共静态int更新属性(ObjectId block RefID,字典atts)。
{。
int updatedAtts=0;。
使用(LockedTransaction acTr=Active.Document.TransactionManager.StartLockedTransaction())。
{。
BlockRef=acTr.GetObject(block RefID,OpenMode.ForRead, true)作为BlockRef;。
如果(块Ref!=null)。
{。
foreach(KeyValuePairatt in atts)。
{。
foreach(ObjectId attId inblockRef.AttributeCollection )//。
{。
属性引用ar=acTr.GetObject(attId,OpenMode.ForRead)作为属性引用;。
如果(ar!=null&&string.Equals(ar.Tag,att.Key,StringComparison.CurrentCultureIgnoreCase))。
{。
ar.UpgradeOpen();。
ar.TextStringatt.Value。
ar.DowngradeOpen();。
updatedAtts++;。
}。
}。

}。

}。
acTr.Commit();。
}。
返回更新的属性;。
}。

mrl989 发表于 2016-7-7 09:29:46

你说得对,我通过attref编辑属性textstring,但它对动态块不起作用,但很奇怪,它现在起作用了,也许我以前在代码上犯了一些错误,所以感谢Atook的帮助...非常感谢

dublinwesley 发表于 2016-7-25 08:34:10

如何从图形中的块内删除所有文本? 我试图为此编写一个命令,它在下面,当它编译时,它不能正常运行:


      public void DelText()
      {
            // Get the current document and database, and start a transaction
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Block table record for read
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,OpenMode.ForRead) as BlockTable;
                // Open the Block table record Model space for read
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl,OpenMode.ForRead) as BlockTableRecord;
                int nCnt = 0;
                acDoc.Editor.WriteMessage("\nModel space objects: ");
                // Step through each object in Model space and display the Name of the Object
                foreach (ObjectId acObjId in acBlkTblRec)
                {
                  //If the ObjectClass.DxFName is INSERT, then this block is a reference.
                  if (acObjId.ObjectClass.DxfName == "INSERT")
                  {
                        //acDoc.Editor.WriteMessage("\n" + myBlk.Name);
                        //acDoc.Editor.WriteMessage("\n" + myBlk.BlockName);
                        //acDoc.Editor.WriteMessage("\n" + myBlk.ObjectId.ObjectClass.DxfName);
                        //acDoc.Editor.WriteMessage("\n" + myBlk.ObjectId.ObjectClass.Name);
                        //Open the Block Reference
                        BlockReference myBlkReference = acTrans.GetObject(acObjId, OpenMode.ForRead) as BlockReference;                  
                        BlockTableRecord xRefBlkTableRecs = acTrans.GetObject(myBlkReference.BlockTableRecord,OpenMode.ForRead) as BlockTableRecord;
                        
                        //For each Object in the Block Table Record of the Block Reference
                        foreach (ObjectId myBlkObjId in xRefBlkTableRecs)
                        {
                            acDoc.Editor.WriteMessage("\n Object Class Name: " + myBlkObjId.ObjectClass.Name);
                            acDoc.Editor.WriteMessage("\n Object Class DxFName: " + myBlkObjId.ObjectClass.DxfName);
                            //Check if the object is a text object
                            if (myBlkObjId.ObjectClass.DxfName.ToString().Equals("TEXT"))
                            {
                              acDoc.Editor.WriteMessage("\n This is a Text Item and Will be Deleted");
                               //This is certainly a text object - count it.
                              nCnt = nCnt + 1;
                              //Delete it
                              myBlkReference.UpgradeOpen();
                              myBlkObjId.GetObject(OpenMode.ForWrite).Erase();                           
                              acTrans.Commit();
                              //acDoc.Editor.Regen();
                            }
                        }
                  }
                  else
                  {
                        acDoc.Editor.WriteMessage("\n" + acObjId.ObjectClass.Name.ToString());
                        acDoc.Editor.WriteMessage("\n" + acObjId.ObjectClass.DxfName.ToString());
                  }
                  //acTrans.Commit();
                  //acDoc.Editor.Regen();
                }
                acDoc.Editor.WriteMessage("\n" + nCnt + "Text Objects in Document");
                // If no objects are found then display a message
                if (nCnt == 0)
                {
                  acDoc.Editor.WriteMessage("\n No Text objects found");
                }
            }
      }

gile 发表于 2016-7-25 09:05:27

嗨,你应该已经开始了另一个主题。无论如何,试试这个(不需要迭代模型空间,只需迭代块表):[命令方法("DELTEXT")]。
公共无效DelText()。
{。
var doc=Application.DocumentManager.MdiActiveDocument;。
var db=doc.Database;。
var ed=doc.Editor;。
var text Class=RXObject.GetClass(typeof(DBText));。
使用(var tr=db.TransactionManager.StartTransaction())。
{。
var bt=(BlockTable)tr.GetObject(db.BlockTableId,OpenMode.ForRead);。
foreach(bt中的ObjectId btrId)。
{。
var btr=(BlockTableRecords)tr.GetObject(btrId,OpenMode.ForRead);。
如果(!(btr.IsLayout

dublinwesley 发表于 2016-7-25 11:53:39

btr.IsFromExternalReference

dublinwesley 发表于 2016-7-25 13:02:28

btr.IsDependent))。
{。
foreach(btr中的ObjectId id)。
{。
如果(id.ObjectClass==text Class)。
{。
var Text=(DBText)tr.GetObject(id,OpenMode.ForWrite, false, false);。
Text.Erase();。
}。
}。
}。
}。
tr.Commit();。
}。
ed.Regen();。
}。

mrl989 发表于 2016-7-25 14:38:15

美丽 - 像魅力一样工作! 谢谢!
页: [1]
查看完整版本: 如何编辑插入的动态块的属性文本字符串和参数值