Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Block selection without the physical click???

Status
Not open for further replies.

creatorofpeace

Programmer
Jun 4, 2003
1
US
I am trying to write up a program that does a lot of things with just the press of a button but I am stuck on one problem that I can not get working and am hoping you may be able to help. I can not write a VBA script that will select a block with attributes, so I can edit the attributes, without having to physically click on the block. I have tried all I can think of to have VB select the block without me clicking it. If anyone can help me in anyway I would greatly appreciate it.
 
Hi,

Try this little piece of code. Obviously, you'll have to add extra code to suit for the display and update of the attribute values.
If you want only a particular block selected or a type of block(s), then create a
Code:
Selection Set
to filter out the unwanted blocks..

Code:
Option Explicit
'**********************************************
'********* VARIABLE DECLARATIONS **************
'**********************************************
Dim entX As AcadObject  'Entity object..
Dim attribZ As Variant  'Attributes..
Dim countX As Integer  'Counter..
Dim blnAttributes As Boolean  'Has Attributes?..
Dim Your_variable1, Your_variable2 As String  'Attribute value string..
'**********************************************
'********* VARIABLE DECLARATIONS **************
'**********************************************

' GET THE ATTRIBUTE VALUES..
Sub GET_Attributes()
For Each entX In ThisDrawing.ModelSpace
    ' If the found object is a block..
    If entX.EntityName = "AcDbBlockReference" Then
            If entX.HasAttributes Then  'Check if object has attributes..
            blnAttributes = True  ' True if yes..
Exit For
            
            ' If no attributes found....
            ElseIf Not blnAttributes Then
                MsgBox "No attributes found for this block in the drawing..", vbInformation
                'GoTo Finished
            End If
    End If
Next
            
            
' Start main loop to get attribute values for the attributes..
For Each entX In ThisDrawing.PaperSpace
    ' If the found object is a block..
    If entX.EntityName = "AcDbBlockReference" Then
                attribZ = entX.GetAttributes
                
                    For countX = LBound(attribZ) To UBound(attribZ)
                        Select Case attribZ(countX).TagString
  'your code for displaying the value o a form or something goes here..
                            Case "insert an attribute tag here"
                                Your_variable1 = attribZ(countX).TextString
  'your code for displaying the value o a form or something goes here..
                            Case "insert another attribute tag here"
                                Your_variable2 = attribZ(countX).TextString
                                                       End Select
                    Next countX
                    
    End If
Next  ' End main loop..
End Sub




' SET THE ATTRIBUTE VALUES..
Sub SET_Attributes()
For Each entX In ThisDrawing.ModelSpace
    ' If the found object is a block..
    If entX.EntityName = "AcDbBlockReference" Then
            If entX.HasAttributes Then  'Check if object has attributes..
            blnAttributes = True  ' True if yes..
Exit For
            
            ' If no attributes found....
            ElseIf Not blnAttributes Then
                MsgBox "No attributes found for this block in the drawing..", vbInformation
                'GoTo Finished
            End If
    End If
Next
            
            
' Start main loop to get attribute values for the attributes..
For Each entX In ThisDrawing.PaperSpace
    ' If the found object is a block..
    If entX.EntityName = "AcDbBlockReference" Then
                attribZ = entX.GetAttributes
                
                    For countX = LBound(attribZ) To UBound(attribZ)
                        Select Case attribZ(countX).TagString
  'your code for updating the value o a form or something goes here..
                            Case "insert an attribute tag here"
                                attribZ(countX).TextString = Your_variable1
  'your code for updating the value o a form or something goes here..
                            Case "insert another attribute tag here"
                                attribZ(countX).TextString = Your_variable2
                                                       End Select
                    Next countX
                    
    End If
Next  ' End main loop..
End Sub


Anyway, I hope this sheds some light on your problem..

If you required any more help, please feel free to email me (address below)..



Cheers,

Renegade..


BULLET-PROOF DESiGNZ
renegade@tiscali.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top