Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Find a block attribute by Tag and replace Value

  1. #1
    Member
    Join Date
    2006-02
    Posts
    10
    Login to Give a bone
    0

    Default Find a block attribute by Tag and replace Value

    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?

  2. #2
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Find a block attribute by Tag and replace Value

    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.

  3. #3
    Member
    Join Date
    2006-02
    Posts
    10
    Login to Give a bone
    0

    Default Re: Find a block attribute by Tag and replace Value

    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.

  4. #4
    Member
    Join Date
    2006-02
    Posts
    10
    Login to Give a bone
    0

    Default Re: Find a block attribute by Tag and replace Value

    Ok, got it to do exactly what I want. Thanks.

  5. #5
    Member
    Join Date
    2001-10
    Posts
    34
    Login to Give a bone
    0

    Default Re: Find a block attribute by Tag and replace Value

    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

  6. #6
    I could stop if I wanted to
    Join Date
    2002-02
    Location
    Kansas
    Posts
    487
    Login to Give a bone
    0

    Default Re: Find a block attribute by Tag and replace Value

    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

  7. #7
    All AUGI, all the time zoomharis's Avatar
    Join Date
    2005-02
    Location
    Abu Dhabi (Native-India)
    Posts
    506
    Login to Give a bone
    0

    Post Re: Find a block attribute by Tag and replace Value

    Quote Originally Posted by naschkeps
    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.
    I am using two functions to get BlockReference and AttributeReference from the drawing.

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


    har!s

  8. #8
    All AUGI, all the time
    Join Date
    2015-12
    Location
    Central Oregon
    Posts
    591
    Login to Give a bone
    0

    Default Re: Find a block attribute by Tag and replace Value

    Quote Originally Posted by zoomharis
    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.
    har!s
    To get the blocks with the desired name, filter for the following code/value pairs:
    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.

  9. #9
    All AUGI, all the time zoomharis's Avatar
    Join Date
    2005-02
    Location
    Abu Dhabi (Native-India)
    Posts
    506
    Login to Give a bone
    0

    Default Re: Find a block attribute by Tag and replace Value

    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.

    Quote Originally Posted by miff
    To get only those in modelspace, add:
    67 1
    or to get those in all Paperspace Layouts:
    67 0
    Could you please explain the presence of two values (eg:- 67 1) instead of a single value.
    A few lines of sample codes on how to use multiple values would be a great help.


    har!s

  10. #10
    All AUGI, all the time
    Join Date
    2015-12
    Location
    Central Oregon
    Posts
    591
    Login to Give a bone
    0

    Default Re: Find a block attribute by Tag and replace Value

    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:
    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
    Now, if we only want those in Modelspace we only need to add the 67,1 code & Data:
    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
    That help?
    Jeff

Page 1 of 2 12 LastLast

Similar Threads

  1. 2014: Wildcard key-in for Find/Replace text in attribute
    By imacad in forum AutoCAD General
    Replies: 9
    Last Post: 2015-08-04, 03:23 PM
  2. Find Block by Attribute
    By timharris677625 in forum Dot Net API
    Replies: 3
    Last Post: 2014-11-29, 07:20 AM
  3. FIND AND REPLACE BLOCK.
    By aijazahmed in forum AutoLISP
    Replies: 11
    Last Post: 2013-08-05, 04:14 PM
  4. Find and Replace Attributed Block
    By xdbk07445198 in forum Dot Net API
    Replies: 1
    Last Post: 2012-12-05, 06:29 AM
  5. Find block by attribute value
    By lshivers in forum AutoLISP
    Replies: 2
    Last Post: 2009-04-12, 01:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •