• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Visual Basic Customization

    Reply
    Member
    john
    Posts: 3
    Registered: ‎09-18-2011
    Accepted Solution

    Vba code wanted

    204 Views, 6 Replies
    02-14-2012 08:51 PM

    Hi all,

     

    I would like to know if anyone has some code that they would like to share.

    What i am looking for is something that would allow be to auto number a particular attributte within ablock on a drawing

    The block attribute would be called ID and i would like to run the code and then just go around and select the first instance of the block, set a starting number and have it incrementally continue numbering from that number on as i select the blocks thereafter.

    The block  which is a component id mark would generally have about 10 attributes and only 1 of them is needed to be changed.

     

    Thanks in anticipation

    John B 

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,332
    Registered: ‎10-08-2008

    Re: Vba code wanted

    02-14-2012 11:57 PM in reply to: john

    Give this a shot

    {code}

    Option Explicit
    'Tools --> Options --> General tab --> Error Trapping --> Break on Unhandled Errors
        Sub Block_Renumbering()

        Dim bRef As AcadBlockReference
        Dim pick As Variant
        Dim atArr As Variant
        Dim oAtt As AcadAttributeReference
        Dim aTag As String
        Dim i As Integer, k As Integer
       
        On Error GoTo ProblemHere
           
    k = CInt(InputBox("Enter initial number:", "Block Renumbering", 1))
       
        Do
       
        ThisDrawing.Utility.GetEntity bRef, pick, "Select a block reference"
       
        If Err <> 0 Then
            Err.Clear
            MsgBox "Program ended.", , "Block Selection Error"
            Exit Sub
        Else
            atArr = bRef.GetAttributes
            For i = 0 To UBound(atArr)
            Set oAtt = atArr(i)
            aTag = oAtt.TagString
            If aTag = "ID" Then
            oAtt.TextString = k
            k = k + 1
            End If
            Next
    End If

    Loop Until Err.Description Like "keyword"

    ProblemHere:

        End Sub

    {code}

     

    ~'J'~

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Distinguished Contributor
    truss_85
    Posts: 131
    Registered: ‎02-13-2011

    Re: Vba code wanted

    02-15-2012 12:05 AM in reply to: john

    Hi John,

     

    here is what you want I suppose...

     

    Public Sub att_sort()
    
    Dim waz As String
    Dim pt As Variant
    Dim xy As Variant
    Dim objBlock As AcadBlockReference
    Dim var_atts As Variant
    
    On Error Resume Next
    ThisDrawing.SelectionSets.Item("SS1").Delete
    Dim ssetObj As AcadSelectionSet
    Set ssetObj = ThisDrawing.SelectionSets.Add("SS1")
    Dim FilterType(0) As Integer
    Dim FilterData(0) As Variant
    
    m = ThisDrawing.Utility.GetReal("Enter a number to start:")
    m_s = ThisDrawing.Utility.GetString(True, "Enter a prefix:")
    
    FilterType(0) = 0
    FilterData(0) = "INSERT"
    ssetObj.SelectOnScreen FilterType, FilterData
    
    n = 0
    For Each Item In ssetObj
    Set objBlock = ssetObj.Item(n)
    var_atts = objBlock.GetAttributes
        For i = 0 To UBound(var_atts)
            If var_atts(i).TagString = "TYPE HERE ATTRIBUTE NAME" Then
                var_atts(i).TextString = m_s & m
                m = m + 1
            End If
        Next
    n = n + 1
    Next Item
    ThisDrawing.SelectionSets.Item("SS1").Delete
    
    End Sub

     

    Please use plain text.
    Distinguished Contributor
    truss_85
    Posts: 131
    Registered: ‎02-13-2011

    Re: Vba code wanted

    02-15-2012 12:06 AM in reply to: Hallex

    Faster then me :smileyhappy:

     

    I did not see your post

     

    Sorry...

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,332
    Registered: ‎10-08-2008

    Re: Vba code wanted

    02-15-2012 01:00 AM in reply to: truss_85

    It's good to allow to choose user what he needs :smileyhappy:

    Regards,

     

    ~'J'~

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Member
    john
    Posts: 3
    Registered: ‎09-18-2011

    Re: Vba code wanted

    02-22-2012 09:57 PM in reply to: Hallex

    Hallex,

    Thanks for that it worked a treat. Exactly what i was looking for.

    Regards

    John

     

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,332
    Registered: ‎10-08-2008

    Re: Vba code wanted

    02-22-2012 10:02 PM in reply to: john

    You're welcome

    Happy coding :smileyhappy:

    Oleg

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.