Reference Column Sheet

Reference Column Sheet

jplujan
Advocate Advocate
474 Views
8 Replies
Message 1 of 9

Reference Column Sheet

jplujan
Advocate
Advocate

Hello,

 

First of all, thank you for your time on this post.

 

By selecting each "TABLE" block with two attributes, you can get the text from the column "TITLE" block and the sheet number and place it in the "TABLE" Block attributes based on its "TABLE" position within the "TITLE" block.

 

I've attached an example.

 

Thank you in advance.

 

Best regards.

0 Likes
Accepted solutions (1)
475 Views
8 Replies
Replies (8)
Message 2 of 9

Ed__Jobe
Mentor
Mentor

You  didn't ask any questions...

 

Your title block doesn't have any attributes. If it did, you could place a field in the attribute that links to the table block's Sheet_ field. No coding necessary. See attached file.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 9

jplujan
Advocate
Advocate

Hello Ed__Jobe
Thank you for your dedication.

Sorry for not asking any questions and for not explaining myself.
The idea is that by selecting the "TABLE" block one by one, or all at once, the two block attributes can be automatically filled in, depending on their position within the "TITLE" (column and sheet).

I'm attaching a new file.

 

Best regards.

0 Likes
Message 4 of 9

Ed__Jobe
Mentor
Mentor

That's a little clearer, but can you show your code?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 9

jplujan
Advocate
Advocate

Hello
I've modified the drawing to add column number attributes to the Title Block.
I've attached a new file.
Thank you.

                                                    
'' Autodeks 21/03/2025


Sub Referencia()
    Dim Seleccion As AcadSelectionSet
    Dim nombreSeleccion As String
    Dim item As Object
    Dim valorHoja As String
    
    '' Atributos de bloque TABLE
    Dim TagTableSheet As String
    Dim TagTableColumn As String
    
    TagTableSheet = "SHEET_"
    TagTableColumn = "COLUMN_"
    
    '' Atributos Boque Hoja
    Dim TagSheet As String
    TagSheet = "SHEET"
    
       
    oApi.MensajeEditor (vbCrLf & vbCrLf & "Selecciona Sheet y Table")
    
    nombreSeleccion = "Referencia"
    
    Set Seleccion = NuevaSeleccion(nombreSeleccion)
    
    Seleccion.SelectOnScreen
    
    'NumeraHoja Sset, contador
    
    For Each item In Seleccion
        If item.EffectiveName = "TITLE" Then
            valorHoja = AtributoObjeto(item, TagSheet)

        End If
    
        If item.EffectiveName = "TABLE" Then
            valorHoja = AtributoObjeto(item, TagSheet)
            
            ActualizarAtributoPorObjeto item, TagTableSheet, valorHoja
        End If
    
    Next
    
    
    Seleccion.Delete
    
    ThisDrawing.Utility.Prompt "Proceso Terminado"

End Sub


Function AtributoObjeto(Objeto As Object, Identificador As String) As String
    Dim AttArray As Variant
    Dim Atr As Variant
    Dim i As Variant
    If Objeto.ObjectName = "AcDbBlockReference" Then
                If Objeto.HasAttributes Then
                    AttArray = Objeto.GetAttributes
                   ' For Each ilista In lista
                        For Each i In AttArray
                            For Each Atr In AttArray
                                If Atr.TagString = Identificador Then
                                    Dim retorno As String
                                    retorno = Atr.TextString
                                End If
                            Next
                        Next
                   ' Next
                End If
            End If
            
    AtributoObjeto = retorno

End Function

Sub ActualizarAtributoPorObjeto(Objeto As Object, tag As String, valor As String)
       Dim AttributeRefs As Variant
       Dim item As Variant
       Dim i As Variant
       
       AttributeRefs = Objeto.GetAttributes
       
       For i = LBound(AttributeRefs) To UBound(AttributeRefs)
           For Each item In AttributeRefs
               If AttributeRefs(i).TagString = tag Then
                   AttributeRefs(i).TextString = valor

               End If
           Next
       Next i

   End Sub

Function NuevaSeleccion(strNom As String) As AcadSelectionSet
   If SelectionExiste(strNom) Then ThisDrawing.SelectionSets.item(strNom).Delete
   Set NuevaSeleccion = ThisDrawing.SelectionSets.Add(strNom)
End Function

Function SelectionExiste(Nombre As String) As Boolean
    Dim Sset As AcadSelectionSet
    'Dim Contador As Integer
    
    'Contador = InputBox("Rele de Caldera", "Reles Caldera")
    
    For Each Sset In ThisDrawing.SelectionSets
        If Sset.Name = Nombre Then
            SelectionExiste = True
            Exit Function
        End If
    Next Sset
End Function

Function DevolverSeleccion(cadena As String) As AcadSelectionSet
    Dim Seleccion As AcadSelectionSet
    LimpiarSeleccion (cadena)
    Set Seleccion = ThisDrawing.SelectionSets.Add(cadena)
    Seleccion.SelectOnScreen
    Set DevolverSeleccion = Seleccion
End Function

Sub LimpiarSeleccion(ByVal cadena As String)
        Dim SSS As AcadSelectionSets
        On Error Resume Next
        Set SSS = ThisDrawing.SelectionSets
        If SSS.count > 0 Then
            SSS.item(cadena).Delete
        End If
End Sub

 

0 Likes
Message 6 of 9

Ed__Jobe
Mentor
Mentor
Accepted solution

This code works when there is only one title block. I'll let you figure out how to do it if there are multiple title blocks.


Public Sub SetTableText()
    Dim ss As AcadSelectionSet
    Dim oblk As AcadBlockReference
    Dim oTblk As AcadBlockReference
    Dim oAtt As AcadAttributeReference
    Dim oAtts As Variant
    Dim ip As Variant
    Dim attSHEET As AcadAttributeReference
    Dim N1s As String
    Dim N2s As String
    Dim N3s As String
    Dim N4s As String
    Dim attCol As AcadAttributeReference
    Dim attSht As AcadAttributeReference
    Dim i As Integer
    Dim sht As String
    Dim N1x As Double
    Dim N2x As Double
    Dim N3x As Double
    Dim N4x As Double

    
    'Get Title block values
    Set ss = GetSS_BlockName("TITLE")
    Set oTblk = ss(0)
    If oTblk.HasAttributes Then
        oAtts = oTblk.GetAttributes
        For i = 0 To UBound(oAtts)
            Select Case oAtts(i).TagString
             Case Is = "SHEET"
                sht = oAtts(i).TextString
                
             Case Is = "ELEM_N1"
                N1s = oAtts(i).TextString
                'Get X value of InsertionPoint
                ip = oAtts(i).InsertionPoint
                N1x = ip(0)
                
             Case Is = "ELEM_N2"
                N2s = oAtts(i).TextString
                ip = oAtts(i).InsertionPoint
                N2x = ip(0)
                
             Case Is = "ELEM_N3"
                N3s = oAtts(i).TextString
                ip = oAtts(i).InsertionPoint
                N3x = ip(0)
                
             Case Is = "ELEM_N4"
                N4s = oAtts(i).TextString
                ip = oAtts(i).InsertionPoint
                N4x = ip(0)
            End Select
        Next i
    Else
        ThisDrawing.Utility.Prompt "\nNo Title block found."
        Exit Sub
    End If
    
    'Process Table blocks
    Set ss = GetSS_BlockName("TABLE")
    
    If ss.Count > 0 Then
        For Each oblk In ss
                
            If oblk.HasAttributes Then
                oAtts = oblk.GetAttributes
                For i = 0 To UBound(oAtts)
                    If oAtts(i).TagString = "COLUM_" Then
                        Set attCol = oAtts(i)
                        'Set column property to correct column determined by block insertion point
                        Select Case attCol.InsertionPoint(0)
                            Case (N1x - 21) To (N1x + 21)
                                attCol.TextString = N1s
                            Case (N2x - 21) To (N2x + 21)
                                attCol.TextString = N2s
                            Case (N3x - 21) To (N3x + 21)
                                attCol.TextString = N3s
                            Case (N4x - 21) To (N4x + 21)
                                attCol.TextString = N4s
                        End Select
                    Else
                        'Set sheet number
                        oAtts(i).TextString = sht
                    End If
                Next i
            End If
            oblk.Update
        Next oblk
        'ThisDrawing.Regen
    Else
        ThisDrawing.Utility.Prompt "\nNo Table blocks found."
    End If
    
End Sub

Public Function AddSelectionSet(SetName As String) As AcadSelectionSet
' This routine does the error trapping neccessary for when you want to create a
' selectin set. It takes the proposed name and either adds it to the selectionsets
' collection or sets it.
    On Error Resume Next
    Set AddSelectionSet = ThisDrawing.SelectionSets.Add(SetName)
    If Err.Number <> 0 Then
        Set AddSelectionSet = ThisDrawing.SelectionSets.item(SetName)
        AddSelectionSet.Clear
    End If
End Function

Public Function GetSS_BlockName(BlockName As String) As AcadSelectionSet
    'creates a ss of blocks with the name supplied in the argument
    Dim s2 As AcadSelectionSet
    
    Set s2 = AddSelectionSet("ssBlocks")                ' create ss with a name
    s2.Clear                                        ' clear the set
    Dim intFtyp(1) As Integer                       ' setup for the filter
    Dim varFval(1) As Variant
    Dim varFilter1, varFilter2 As Variant
    intFtyp(0) = 0: varFval(0) = "INSERT"           ' get only blocks
    intFtyp(1) = 2: varFval(1) = BlockName          ' of this name
    varFilter1 = intFtyp: varFilter2 = varFval
    s2.Select acSelectionSetAll, , , varFilter1, varFilter2        ' do it
    Set GetSS_BlockName = s2

End Function

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 9

jplujan
Advocate
Advocate

Hi, Ed
Thanks a lot. I'll get on it, I'll try to figure it out.

Thanks.

0 Likes
Message 8 of 9

Ed__Jobe
Mentor
Mentor

Since my code answers your original question, you should be able to mark it as the solution.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 9 of 9

jplujan
Advocate
Advocate

Good morning,
I wanted to try it in case I had any questions, but I was going to do it today.

Thanks

0 Likes