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!

Changing a Block Attribute Value? 1

Status
Not open for further replies.

mfleming

Technical User
Jul 2, 2003
65
CA
Hey.

I'm trying to get an area of an object by selecting the object then changing one of the blocks attributes to the value of the area.

My problem is trying to change the attributes in the block.

The block id = "new id"
tag = "SQFT"

I know this should be really easy but I can't seem to get it. Any help would be great.

Thanks

Matt
 
Hi,

Are you trying to do do this manually or by using a program? If so, is it code that you're after?



Cheers,

Paul @ Bullet-Proof Designz..


BULLET-PROOF DESiGNZ
renegade@tiscali.co.uk
 
I just need the code to be able to access and change Attributes in a block reference. Just the values not the tags or anything else. If I get this code I will be able to do it half manually and half using the code.

Thanks

Matt
 
Hi,

Try this on for size. Here's a snippet of code that will access all blocks in modelspace and get or update the attribute value. I used AREA as the attribute tag but you can use whatever you have called it.
With regards to the update of the values, you may need a userform to receive and edit the values before updating them..


Code:
Option Explicit
'*********** DECLARE VARIABLES *****************
Dim entX As AcadObject  'Entity object..
Dim attribZ As Variant  'Attributes..
Dim countX As Integer  'Counter..
Dim blnAttributes As Boolean  'Has Attributes?..
Dim areaX As Double  'Area value for entity..
'*********** DECLARE VARIABLES *****************

Sub Attribute_values()
' Start loop to access 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.ModelSpace
    ' 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  'The name of the attitrubute tag..
                            Case "AREA"
                                areaX = attribZ(countX).TextString
                        End Select
                    Next countX
    End If  'End main if statement..
Next entX



' Start main loop to update attribute values for the attributes..
For Each entX In ThisDrawing.ModelSpace
    ' 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  'The name of the attitrubute tag..
                            Case "AREA"
                                attribZ(countX).TextString = Textbox1.Text  'For example, textbox1 is on a userform..
                        End Select
                    Next countX
    End If  'End main if statement..
Next entX

Finished:
End Sub




I hope this helps. let me know if it's what your after..

Cheers,

Paul @ Bullet-Proof Designz..


BULLET-PROOF DESiGNZ
renegade@tiscali.co.uk
 
I'm still learning VBA so I don't completely know how to modify it to suit me. I don't want it to go through all blocks in the drawing. I'm wanting to use a "Selection Set" to select one object using the "OnscreenSelect" and change the attributes of just the one.

I'm just not familiar in how to get to the attribute value from the block.

Any help would be great.

Thanks

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top