Jump to content

Placing a partical Block Attribute Value in a Field?


muck

Recommended Posts

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,

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...