PDA

View Full Version : Placing a partical Block Attribute Value in a Field?



muck
8th Feb 2011, 02:02 pm
AutoCAD 2010, VBA

Is there a way to place a partical attribute value in a AutoCAD Field form a specifc block.
Stay the field is placed in a text string. Maybe a diesel statment in a field could do this?
Maybe visual basic could help if it could access the field.
Having a Field to read a block attribute and place it in the field string as a partical attribute value would
be helpful. I do not want the full attribute value seen in the field, I want to see a partical attribute
value. Say For example a prefix shown in the field. Say the attribute value is "LOOP21-6520" I would
like to see only "LOOP21" in the field.

Thank you,

fixo
9th Feb 2011, 09:26 am
Try this quickie


Public Sub LinkTextWithAttrib()
Dim oEnt As AcadEntity
Dim oAttr As AcadAttributeReference
Dim oText As AcadText
Dim idAttr As Long
Dim strVal As String
Dim attFieldStr As String
Dim varPt, tmax, contx

On Error GoTo Err_Control
'prefix = InputBox("Enter a Prefix:", "Link Text with Attribute","LOOP21-")
''If prefix = "" Then
'MsgBox "You did not entered the value."
'Exit Sub
'End If
ThisDrawing.Utility.GetSubEntity oEnt, varPt, tmax, contx, _
"Select an attribute :"
If oEnt Is Nothing Then
MsgBox "Nothing Selected"
Exit Sub
End If
If Not TypeOf oEnt Is AcadAttributeReference Then
MsgBox "Selected is not an AttributeReference"
Exit Sub
End If
Set oAttr = oEnt
strVal = oAttr.TextString
If Not strVal Like "LOOP21-*" Then
MsgBox "This attribute doesn't contain a prefix ""АВВ"""
Exit Sub
End If
Dim pos
pos = InStr(strVal, "-")
ThisDrawing.Utility.GetSubEntity oEnt, varPt, tmax, contx, "Select a Text:"
If oEnt Is Nothing Then
MsgBox "Nothing Selected"
Exit Sub
End If
If Not TypeOf oEnt Is AcadText Then
MsgBox "Selected is not a Text"
Exit Sub
End If
Set oText = oEnt
Dim txtFieldStr As String
' how to use diesel in field:
txtFieldStr = "%<\AcDiesel $(substr, " & strVal & ", 1, " & CStr(pos) & ")>%" '<--do not wordwrap!
Debug.Print txtFieldStr
oText.TextString = txtFieldStr
oText.UPDATE

ThisDrawing.Regen acActiveViewport
Err_Control:
If Err.Number <> 0 Then MsgBox Err.Description
End Sub

BIGAL
24th Feb 2011, 03:12 am
Not sure but rather than LOOP-21 wouldnt you just add the letters together till you hit - then it will work for any text combo. maybe also , = / etc enter the seperator