本节介绍VBAPI如何获取修改标注尺寸显示的文字。
VBAPI提供了IpfcBaseDimension和其子类IpfcDimension描述尺寸对象,而尺寸显示的文字由IpfcBaseDimension类的Texts属性描述。Texts属性为一个Istringseq对象,对其进行修改、增删操作即可完成标注尺寸显示的文字的修改。尺寸修饰如图7-1所示,示例代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| Public Sub Modify_text(ByVal Prefix As String, ByVal Surffix As String, ByVal DownText As String) Dim selectionOptions As IpfcSelectionOptions Dim selections As CpfcSelections Dim selectDim As IpfcSelection Dim bdimesion As IpfcBaseDimension Dim TextStrs As Istringseq If Isdrawding() = True Then selectionOptions = (New CCpfcSelectionOptions).Create("dimension") selectionOptions.MaxNumSels = 1 selections = asyncConnection.Session.Select(selectionOptions, Nothing) If selections Is Nothing Then Exit Sub End If If selections.Count < 1 Then Throw New Exception("请选择一个尺寸元素!") End If selectDim = selections.Item(0) bdimesion = selectDim.SelItem TextStrs = bdimesion.Texts TextStrs.Set(0, Prefix + bdimesion.Texts.Item(0) + Surffix) If DownText <> "" Then If TextStrs.Count > 1 Then TextStrs.Set(1, DownText) Else TextStrs.Insert(1, DownText) End If End If bdimesion.Texts = TextStrs End If End Sub
|
图7-1 尺寸修饰流程
完整代码可在Github.com下载。