下面是我用来将文件名作为字段添加到绘图空白中的代码。
- Public Sub PopCadFile()
- '%<\AcVar Filename \f "%tc1%fn2">%
- Dim myEntity As AcadEntity
- Dim mySelSet As AcadSelectionSet
- Dim TempName As String
- Dim gpCode(0 To 1) As Integer
- Dim dataValue(0 To 1) As Variant
- Dim groupCode As Variant
- Dim dataCode As Variant
- Dim myAttrib As Variant
- Dim myCurrentAtt As Variant
- TempName = "%<\AcVar Filename \f " & Chr$(34) & "%tc1%fn2" & Chr$(34) & ">%"
- gpCode(0) = 0 'item
- gpCode(1) = 2 '?
- groupCode = gpCode
- dataValue(0) = "INSERT" 'item type
- dataValue(1) = "STL*" '?
- dataCode = dataValue
- Set mySelSet = ThisDrawing.SelectionSets.Add("Blocks")
- mySelSet.Select acSelectionSetAll, , , groupCode, dataCode
- For Each myEntity In mySelSet
- myAttrib = myEntity.GetAttributes
- For Each myCurrentAtt In myAttrib
- If myCurrentAtt.TagString = "CADFILE" Then myCurrentAtt.TextString = TempName
- If myCurrentAtt.TagString = "XXX-XXX.DWG" Then myCurrentAtt.TextString = TempName
- Next myCurrentAtt
- Next myEntity
- ThisDrawing.SelectionSets.Item("Blocks").Delete
- End Sub
我们所有的空白都是从STL开始的,所以我搜索了一个绘图空白。根据绘图的年龄,我想要的属性是CADFILE或XXX-XXX。图纸。TempName是字段值,请在其中插入您自己的值。 |