I need to find a block attribute with a particular tag "LAYT-COV" and replace it's value (regardless of what the current value is) with a new value "1234". The block is in PaperSpace. Anyone have any solution for that?
|
I need to find a block attribute with a particular tag "LAYT-COV" and replace it's value (regardless of what the current value is) with a new value "1234". The block is in PaperSpace. Anyone have any solution for that?
Iterate thru the Layouts collection, and iterate thru the Layout.Block's objects. When you get to the BlockReference that holds your atrribute, use that Block's GetAttributes method and you are almost home.
I have gotten my code to work almost exactly the way I want. However, one thing I does is set each layout as active as it iterates through them looking for the right block/attribute. Is there a way I can avoid making each layout active, while still searching through them all? Making each one active takes more time than I would like as it goes through them all.
Ok, got it to do exactly what I want. Thanks.
Montana,
Could you share that routine with me...I did something quite similar earlier this week, and I'd like to see another way of doing this operation.
Thanks very much!
Pete Naschke
641-621-3175
if you know the block name try this program I use it to edit attribute in drawing it more then you need but should work. It show all block name in the drawing and all tag in the block. it then show all inserted blocks. if the block is in paper space it show witch tab it on. It will also save and load attribute to a database.
http://forums.augi.com/attachment.php?attachmentid=1982
I am using two functions to get BlockReference and AttributeReference from the drawing.Originally Posted by naschkeps
The only thing I hate is iterating through the drawing to find the block reference. I wonder any filter options ( using Group Code & Data Value) are available for the selection of block references. Any help will be highly appreciated.Code:Function GetBlkRef(ByVal strBlkName As String) As AcadBlockReference Dim objCadEnt As AcadEntity Dim objBlkRef As AcadBlockReference Dim objActSpace As AcadObject If ThisDrawing.ActiveLayout.Name = "Model" Then Set objActSpace = ThisDrawing.ModelSpace Else Set objActSpace = ThisDrawing.PaperSpace End If For Each objCadEnt In objActSpace If objCadEnt.ObjectName = "AcDbBlockReference" Then Set objBlkRef = objCadEnt If StrComp(objBlkRef.Name, strBlkName, vbTextCompare) = 0 Then Set GetBlkRef = objBlkRef Exit Function End If End If Next Set GetBlkRef = Nothing End Function Function GetAttrRef(ByVal objBlkRef As AcadBlockReference, ByVal strAttrTag As String) As AcadAttributeReference Dim i As Integer Dim clAttr As Variant Dim curAttrRef As AcadAttributeReference If objBlkRef.HasAttributes Then clAttr = objBlkRef.GetAttributes For i = LBound(clAttr) To UBound(clAttr) Set curAttrRef = clAttr(i) If StrComp(curAttrRef.TagString, strAttrTag, vbTextCompare) = 0 Then Set GetAttrRef = curAttrRef Exit Function End If Next End If Set GetAttrRef = Nothing End Function Here is a sample program to get attributes Sub getAttr_Sample() Dim objBlkRef As AcadBlockReference Dim objAttRef As AcadAttributeReference Set objBlkRef = GetBlkRef("BLOCK_NAME") Set objAttRef = GetAttrRef(objBlkRef, "ATTRIBUTE_TAG") 'Now you can manipulate the attribute reference as per your requirement objAttRef.TextString = "New Attribute Value" objAttRef.Update End Sub
har!s
To get the blocks with the desired name, filter for the following code/value pairs:Originally Posted by zoomharis
0 "INSERT"
2 "BLOCKNAME"
To get only those in modelspace, add:
67 1
or to get those in all Paperspace Layouts:
67 0
This is based on using objSS.Select acSelectionSetAll,,,FilterCode,FilterData
HTH,
Jeff
Last edited by Jeff_M; 2006-03-25 at 10:18 PM.
Thanks Jeff, for the great piece of information. I tried both INSERT and BLOCKNAME successfully. That's all I needed. But regarding the following, I am still bit confused.
Could you please explain the presence of two values (eg:- 67 1) instead of a single value.Originally Posted by miff
A few lines of sample codes on how to use multiple values would be a great help.
har!s
Sure,
To get all BlockRefs in the drawing, including ALL Layout Tabs, of the Name "MyBlock"....assumes you already have setup/created the oSS as a valid SelectionSet object:
Now, if we only want those in Modelspace we only need to add the 67,1 code & Data:Code:Dim iCode(1) As Integer Dim vData(1) As Variant iCode(0) = 0: vData(0) = "INSERT" iCode(1) = 2: vData(1) = "MyBlock" oSS.Select acSelectionSetAll, , , iCode,vData
That help?Code:Dim iCode(2) As Integer Dim vData(2) As Variant iCode(0) = 0: vData(0) = "INSERT" iCode(1) = 2: vData(1) = "MyBlock" iCode(2) = 67: vData(2) = 1 oSS.Select acSelectionSetAll, , , iCode,vData
Jeff