muck Posted February 8, 2011 Share Posted February 8, 2011 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, Quote Link to comment Share on other sites More sharing options...
fixo Posted February 9, 2011 Share Posted February 9, 2011 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 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 24, 2011 Share Posted February 24, 2011 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.