AutoCAD Electrical Forum
Welcome to Autodesk’s AutoCAD Electrical Forums. Share your knowledge, ask questions, and explore popular AutoCAD Electrical topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get access to the Wire Sequence in VBA

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Colbjørn
505 Views, 3 Replies

Get access to the Wire Sequence in VBA

Hi.

 

Is it possible to get access to the wiresequence of a wiring diagram from VBA?

I'm looking for a more easy way to get the relationship between blocks than scanning through the wirenumbers in the TERMXX attributes.

It works, but it is very inefficient.

 

Colbjørn.

3 REPLIES 3
Message 2 of 4
rhesusminus
in reply to: Colbjørn

You can just read the project database 😊
The format is described here: https://nateholt.wordpress.com/2009/07/27/overview-of-autocad-electricals-wdata-table-intermediate-w...
And here: https://nateholt.wordpress.com/2015/02/11/how-wire-sequencing-data-is-held-in-wdata-table/

Trond Hasse Lie
AutoCAD Electrical and EPLAN expert
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
Message 3 of 4
Colbjørn
in reply to: rhesusminus

Hi.

 

I got access to the database with the following code:

TBA. Got the code at home.

 

 

Colbjørn

Message 4 of 4
Colbjørn
in reply to: Colbjørn

Here is the code I use:

It's tested and it works, just remember to put the correct database location into the function before you use it.

 

Private Function ReadAccessDataBase(intReturn As Integer, strWIRENO As String, strCMP As String, strPIN As String) As String
    Dim oConn As ADODB.Connection
    Dim oRs As ADODB.Recordset
    Dim strConn As String
    Dim strSQL As String
    Dim strDBPath As String
    On Error GoTo ERRHANDLER:
    strDBPath = "location of scratch database"
    strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strDBPath & ";Persist Security Info=False;"
    Set oConn = New ADODB.Connection
    oConn.Open strConn
    strSQL = "SELECT * FROM WFRM2ALL WHERE (WIRENO = '" & strWIRENO & "') AND (NAM1 = '" & strCMP & "' OR NAM2 = '" & _
                                                strCMP & "') AND (PIN1 = '" & strPIN & "' OR PIN2 = '" & strPIN & "')"
    Set oRs = New ADODB.Recordset
    oRs.Open strSQL, oConn, adOpenStatic, adLockReadOnly, adCmdText
    If oRs.Fields("NAM1") = strCMP And oRs.Fields("PIN1") = strPIN Then
        Select Case intReturn
        Case 0
            ReadAccessDataBase = oRs.Fields("PIN2")
            GoTo JUMP
        Case 1
            ReadAccessDataBase = oRs.Fields("NAM2")
            GoTo JUMP
        Case 2
            ReadAccessDataBase = oRs.Fields("LOC2")
            GoTo JUMP
        Case 3
            ReadAccessDataBase = oRs.Fields("INST2")
            GoTo JUMP
        End Select
    Else
        Select Case intReturn
        Case 0
            ReadAccessDataBase = oRs.Fields("PIN1")
            GoTo JUMP
        Case 1
            ReadAccessDataBase = oRs.Fields("NAM1")
            GoTo JUMP
        Case 2
            ReadAccessDataBase = oRs.Fields("LOC1")
            GoTo JUMP
        Case 3
            ReadAccessDataBase = oRs.Fields("INST1")
            GoTo JUMP
        End Select
    End If
    
    ReadAccessDataBase = ""

JUMP:
    oRs.Close
    oConn.Close
    
ERRHANDLER:
    Exit Function
    Resume
End Function

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost