Jump to content

VBA Custom Attribute Editor


Ander

Recommended Posts

I am trying to create a custom attribute editor by using fixo and metal_pro's code as a base but I'm getting runtime error '424' object required. The de****** is pointing out line AttList = oBlkRef.GetAttributes but I can't figure out what's wrong. I know the basic's of VBA but i'm new to it, so any help would be appreciated.

 

Option Explicit
Dim oBlkRef As AcadBlockReference
Sub Change_it()
   Dim inspt As Variant
   Dim oEnt As AcadEntity
   Dim i
   ParentSymbolForm.Hide
   ThisDrawing.Utility.GetEntity oEnt, inspt, "Select object:"
   ' Checks if you selected a block.
   If TypeOf oEnt Is AcadBlockReference Then
       Set oBlkRef = oEnt
       ' Check for attributes.
       If oBlkRef.HasAttributes Then
           Dim AttList As Variant
           ' Build a list of attributes for the current block.
           AttList = oBlkRef.GetAttributes
           ' Cycle throught the list of attributes.
           For i = LBound(AttList) To UBound(AttList)
               ' Check for the correct attribute tag.
               If AttList(i).TagString = "TAG1" Then
                   ParentSymbolForm.ComponetTag.Text = AttList(i).TextString
               End If
               If AttList(i).TagString = "DESC1" Then
                   ParentSymbolForm.TextBoxDesc1.Text = AttList(i).TextString
               End If
               If AttList(i).TagString = "DESC2" Then
                   ParentSymbolForm.TextBoxDesc2.Text = AttList(i).TextString
               End If
               If AttList(i).TagString = "TERM01" Then
                   ParentSymbolForm.TextBoxPin1.Text = AttList(i).TextString
               End If
               If AttList(i).TagString = "POS1" Then
                   ParentSymbolForm.TextBoxSwPos1.Text = AttList(i).TextString
               End If
           Next
       End If

       ParentSymbolForm.Show

   Else
       MsgBox "You did not select a block."
   End If
End Sub

Private Sub SelectButton_Click()
   Call Change_it
End Sub

Private Sub ChangeButton_Click()
   Me.Hide
   Dim AttList As Variant
   Dim i
   ' Change attributes for the selected block.
   AttList = oBlkRef.GetAttributes
   ' Cycle throught the list of attributes.
   For i = LBound(AttList) To UBound(AttList)
       ' Check for the correct attribute tag.
       Select Case AttList(i).TagString
       Case "TAG1"
           AttList(i).TextString = ParentSymbolForm.ComponetTag.Text
       Case "DESC1"
           AttList(i).TextString = ParentSymbolForm.TextBoxDesc1.Text
       Case "DESC2"
           AttList(i).TextString = ParentSymbolForm.TextBoxDesc2.Text
       Case "TERM01"
           AttList(i).TextString = ParentSymbolForm.TextBoxPin1.Text
       Case "POS1"
           AttList(i).TextString = ParentSymbolForm.TextBoxSwPos1.Text
       End Select
   Next

End Sub

Link to comment
Share on other sites

Not sure but oBlkRef.HasAttributes maybe oBlkRef.Attributes search here under BIGAL for some block attribute code should give correct wording.

 

Found this aAttributes = blk.GetAttributes if true block has attributes. Look at your code your doing this but need to move up to IF

 

If oBlkRef.HasAttributes Then change this line
.
.

' Build a list of attributes for the current block.
Dim AttList As Variant
If AttList = oBlkRef.GetAttributes Then
.
.

Link to comment
Share on other sites

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...