谢谢你的回复,杰夫,看起来我不像是一个标准的领导者。如果我使用MLeaders,是的,这与我使用的类似,但对于标准leader,没有从我看到的内容中实际分配BlockId的选项。同样,我只是希望创建一个标准的领导者与相关的动态块。抱歉,如果我有点误导。
这正是我想要的...
- Using _LeaderItm As Leader = New Leader()
- Dim _BlkRef As BlockReference = New BlockReference(New Point3d(4, 4, 0), _LeaderItm.BlockId)
- _LeaderItm.AppendVertex(New Point3d(0, 0, 0))
- _LeaderItm.AppendVertex(New Point3d(4, 4, 0))
- ''' Somehow set block id below. '''
- _LeaderItm.BlockId ' PromptStatus.OK Then Exit Do
- Dim CurrentBlkTbl As BlockTable
- CurrentBlkTbl = CurrentTrans.GetObject(CurrentDB.BlockTableId, OpenMode.ForRead)
- Dim CurrentBlkTblRec As BlockTableRecord
- CurrentBlkTblRec = CurrentTrans.GetObject(CurrentBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
- Dim _PntStartRes As PromptPointResult = CurrentEd.GetPoint(_PntStart)
- If _PntStartRes.Status PromptStatus.OK Then Exit Do
- _PntEnd.BasePoint = _PntStartRes.Value
- Dim _PntEndRes As PromptPointResult = CurrentEd.GetPoint(_PntEnd)
- If _PntEndRes.Status PromptStatus.OK Then Exit Do
- Dim _RotMat As Matrix3d = CurrentEd.CurrentUserCoordinateSystem
- Dim _BaseStartPnt As Point3d = _PntStartRes.Value.TransformBy(_RotMat)
- Dim _BaseEndPnt As Point3d = _PntEndRes.Value.TransformBy(_RotMat)
- Dim _BlkTbl As BlockTable = CurrentTrans.GetObject(CurrentDB.BlockTableId, OpenMode.ForRead)
- Dim _BlkId = _BlkTbl(_BlkNameString)
- Dim _BlkRef As BlockReference = New BlockReference(_BaseEndPnt, _BlkId)
- _LeaderItm.AppendVertex(_BaseStartPnt)
- _LeaderItm.AppendVertex(_BaseEndPnt)
- _LeaderItm.HasArrowHead = True
- CurrentBlkTblRec.AppendEntity(_LeaderItm)
- CurrentTrans.AddNewlyCreatedDBObject(_LeaderItm, True)
- CurrentBlkTblRec.AppendEntity(_BlkRef)
- CurrentTrans.AddNewlyCreatedDBObject(_BlkRef, True)
- '
- _LeaderItm.Annotation = _BlkRef.ObjectId
- Dim _DynBlkRef As BlockReference = DirectCast(CurrentTrans.GetObject(_BlkRef.ObjectId, OpenMode.ForWrite), BlockReference)
- Dim _DynBlkTblRec As BlockTableRecord = DirectCast(CurrentTrans.GetObject(_DynBlkRef.DynamicBlockTableRecord, OpenMode.ForWrite), BlockTableRecord)
- For Each _AttID As ObjectId In _DynBlkTblRec
- Dim ent As DBObject = CurrentTrans.GetObject(_AttID, OpenMode.ForWrite)
- If TypeOf ent Is AttributeDefinition Then
- Dim AttDef As AttributeDefinition = ent
- If AttDef.Tag = "NT" Then AttDef.TextString = _NoteStrRes.StringResult
- _DynBlkTblRec.SynchronizeAttributes
- End If
- Next
- _LeaderItm.EvaluateLeader()
- CurrentTrans.Commit()
- CurrentEd.Regen()
- End Using
|