See the top rated post in this thread. Click here

Results 1 to 9 of 9

Thread: Copy previous Block Attribute Value to next Block Attribute

  1. #1
    100 Club
    Join Date
    2007-07
    Posts
    104
    Login to Give a bone
    0

    Arrow Copy previous Block Attribute Value to next Block Attribute

    We often have a smoke detectors, wich have an indicatorlamp with the same adres above the door of the room. I want to select the detector, then the indicator (all through the drawing), press enter and the values from the detectors are copied to the indicators.
    So the routine I want to make should copy (remember) the value of the first selected block-attribute, and paste it to the next selected block attribute.
    I have made a serious yet sketchy attempt to get some code going here, but I feel I'm still quite far off. Can someone help me out?

    Heres my code so far:

    Code:
     
    Option Explicit
        Dim BlkAtts As Variant
        
    Public Sub BlockValtoNextBlock()
    
        Dim SelSet As AcadSelectionSet
        Dim Ent As AcadEntity
        Dim BlockInsert As AcadBlock
        Dim i As Integer
        Dim AttText As String
        
        Set SelSet = ThisDrawing.SelectionSets.Add("SS0")
        SelSet.SelectOnScreen
        SelSet.Highlight True
        
        For Each Ent In SelSet
            If Not BlockInsert.Name = "Nevenindicator" Then
                AttText = BlkAtts(0).TextString
                End If
            Next
        For Each Ent In SelSet
            If BlockInsert.Name = "Nevenindicator" Then
                UpdateAttrib 0, AttText
                End If
            Next
    
    
        SelSet.Highlight False
    
    End Sub
    
    Sub UpdateAttrib(TagNumber As Integer, BTextString As String)
     
    'This procedure checks to see if there is a value.
    
        If BTextString = "" Then
        BlkAtts(TagNumber).TextString = ""
        Else
        BlkAtts(TagNumber).TextString = BTextString
        End If
        
    End Sub

  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: Copy previous Block Attribute Value to next Block Attribute

    A couple of areas to start with:
    1. Your iteration thru the loop assumes all objects are block references. Poor assumption. The code will need to be more robust. Use TypeOf Is tests.
    2. BlkAtts is never bound to the attributes. Use the GetAttributes method.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  3. #3
    100 Club
    Join Date
    2007-07
    Posts
    104
    Login to Give a bone
    0

    Default Re: Copy previous Block Attribute Value to next Block Attribute

    Ok, the macro works to a certain point now (the comments of Robert have been integrated, and the value of each attribute is returned in the selected order).

    The part that I 'm stuck on, is how to seperate the list of selected values. The remote indicater will always be the second block that gets selected (after the detector). So I hope somehow, each first attributevalue can be copied to the second attributevalue.

    Does anyone know if this is possible, and how it can be done?

  4. #4
    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: Copy previous Block Attribute Value to next Block Attribute

    You need to get the 2nd block reference's attributes in exactly the same manner as you got the 1st but in this case you will be modifying the TextString property instead of storing its value.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  5. #5
    100 Club
    Join Date
    2007-07
    Posts
    104
    Login to Give a bone
    0

    Default Re: Copy previous Block Attribute Value to next Block Attribute

    What you suggest implies that the macro will come to work this way:
    1) first select all the detectors (detector - detector - detector), then....
    2) make a second selection in which all the appropriate indicators are selected in the exact same order (indicator - indicator - indicator)

    In practise, that could cause some clumsiness. So it would be more practical if i could let the program create one long list (detector - indicator - detector - indicator - detector - indicator) which then automatically gets seperated. Or perhaps there is a way of passing the first value on to the second automatically, without seperating the list.

    Right now, this is what I 've got working:
    Code:
     
    Public Sub Test()
        
        Dim SelSet As AcadSelectionSet
        Dim BlockRef As AcadBlockReference
        Dim AllSelectedAtts As Variant
        Dim i As Double
        Dim Entities As AcadEntity
        Dim BlockObj As AcadBlock
        Dim MyNewValue As String
        Dim MyTagName As String
        MyTagName = "Nummer"
    
        On Error Resume Next
        ThisDrawing.SelectionSets.Item("SS0").Delete
        On Error GoTo 0
        
        Set SelSet = ThisDrawing.SelectionSets.Add("SS0")
        SelSet.SelectOnScreen
        SelSet.Highlight True
        
        With ThisDrawing.Utility
        
            For Each Entities In SelSet
            If TypeOf Entities Is AcadBlockReference Then
                    Set BlockRef = Entities
                    AllSelectedAtts = BlockRef.GetAttributes
                    
             For i = 0 To UBound(AllSelectedAtts)
             If AllSelectedAtts(i).TagString = MyTagName Then
                MsgBox AllSelectedAtts(i).TextString
                ' AllSelectedAtts(i).TextString = "121" '
                ' MyNewValue = AllSelectedAtts(i).TextString
                ' AllSelectedAtts(i).Update
             End If
                Next
             End If
                Next
                
        End With
    
    ' MsgBox (MyNewValue)
    
    SelSet.Highlight False
    
    End Sub
    Last edited by darfnuggi; 2008-10-02 at 05:27 AM.

  6. #6
    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: Copy previous Block Attribute Value to next Block Attribute

    Quote Originally Posted by darfnuggi View Post
    What you suggest implies that the macro will come to work this way:
    1) first select all the detectors (detector - detector - detector), then....
    2) make a second selection in which all the appropriate indicators are selected in the exact same order (indicator - indicator - indicator)
    No, what I would suggest is to create a macro that selects one object, the source, and another object, the target. The user would just repeat the command to perform the same task on other object pairs.

    You cannot count on the order of objects in the selection set for several reasons:
    1. User may pick in a bad order
    2. The user may use window or crossing for selection
    3. When window or crossing is used, AutoCAD can also change the order of objects in the selection set depending on configuration
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  7. #7
    100 Club
    Join Date
    2007-07
    Posts
    104
    Login to Give a bone
    0

    Default Re: Copy previous Block Attribute Value to next Block Attribute

    What I would really like to know is how do I copy every first attribute value (in a long list) to the second value. Can someone explain how this can be done?

  8. #8
    100 Club
    Join Date
    2007-07
    Posts
    104
    Login to Give a bone
    0

    Default Re: Copy previous Block Attribute Value to next Block Attribute

    Ok, I got this working (though the code is lacking in certain aspects). It needs some improving, but I put it in this post for anyone who is looking for something like this.

    Code:
    Public Sub Indicator()
    
        Dim SelSet As AcadSelectionSet
        Dim BlockRef As AcadBlockReference
        Dim AllSelectedAtts As Variant
        Dim i As Double
        Dim Entities As AcadEntity
        Dim BlockObj As AcadBlock
        Dim NewValue As String
        Dim MyTagName As String
        MyTagName = "Nummer"
    
        On Error Resume Next
        ThisDrawing.SelectionSets.Item("SS0").Delete
        On Error GoTo 0
        
        Set SelSet = ThisDrawing.SelectionSets.Add("SS0")
        SelSet.SelectOnScreen
        SelSet.Highlight True
        
        With ThisDrawing.Utility
            For Each Entities In SelSet
            If TypeOf Entities Is AcadBlockReference Then
                Set BlockRef = Entities
                AllSelectedAtts = BlockRef.GetAttributes
                For i = 0 To UBound(AllSelectedAtts)
                If AllSelectedAtts(i).TagString = MyTagName Then
                    If Not AllSelectedAtts(i).TextString = "" Then
                    'Non empty block is Detector
                    NewValue = AllSelectedAtts(i).TextString
                    End If
                    If AllSelectedAtts(i).TextString = "" Then
                    'Empty block is Indicator
                    AllSelectedAtts(i).TextString = NewValue
                    AllSelectedAtts(i).Update
                    End If
                End If
                Next
            End If
            Next
        End With
        
    SelSet.Highlight False
    
    End Sub

  9. #9
    Woo! Hoo! my 1st post
    Join Date
    2009-02
    Posts
    1
    Login to Give a bone
    1

    Default Re: Copy previous Block Attribute Value to next Block Attribute

    working with attributes is not as easy task, in .net it involves to get the attributes definitions from thee block definitions the get the attributes references from block reference then create new attribute references and add to the database and the target block reference.

    The code is quite long, if you want, you can contact to me or view the site www.hsbmas.com

Similar Threads

  1. How to change dynamic block attribute default values based on block selected?
    By zeirz109180 in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2013-12-13, 02:20 PM
  2. Replies: 13
    Last Post: 2012-09-18, 07:51 PM
  3. Block Attribute Table Values Dont' Appear in Block
    By stusic in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2011-12-27, 02:58 PM
  4. Block attribute text size is incorrect when the Block is not selected
    By lwhitney.133796 in forum AutoCAD General
    Replies: 3
    Last Post: 2007-02-16, 10:01 PM
  5. Block Attribute Manager Vs. Enhanced Attribute Editor
    By zoomharis in forum AutoCAD General
    Replies: 0
    Last Post: 2006-04-15, 11:53 AM

Posting Permissions

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