Get Cable Cores Example (VBA)
This example shows how to get the cores of cables.
'----------------------------------------------------------------------------
' Preconditions:
' 1. Verify that the specified assembly exists.
' 2. In SOLIDWORKS, click Tools > Add-Ins > SOLIDWORKS Routing.
' 3. In Tools > Options > System Options > Routing > Routing File Locations,
' click Launch Routing Library Manager and set the
locations of your
' SOLIDWORKS Routing files.
' 4. In the IDE, click Tools > References, select
' SOLIDWORKS <version> Routing Type Library,
and click OK.
' 5. Open an Immediate window.
'
' Postconditions:
' 1. Opens the specified assembly.
' 2. Selects Harness1^RoutingAssem1-1.
' 3. Gets the cables in the electrical route.
' 4. Prints the number of wires and the properties of each wire in the cable.
' 5. Inspect the Immediate window.
'
' NOTE: Because
the model is used elsewhere, do not save changes.
'----------------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssemblyDoc As SldWorks.AssemblyDoc
Dim rtRouteManager As SWRoutingLib.RouteManager
Dim rtElectricalRoute As SWRoutingLib.ElectricalRoute
Dim rtCable As SWRoutingLib.Cable
Dim rtCableProperty As SWRoutingLib.CableProperty
Dim aWireProperty As SWRoutingLib.WireProperty
Dim aWire As SWRoutingLib.Wire
Dim lNumCores As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim vCables As Variant
Dim vCores As Variant
Dim vCoreProperties As Variant
Dim boolstatus As Boolean
Dim longstatus As Long
Dim longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.OpenDoc6("C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2018\samples\tutorial\api\RoutingAssem1.SLDASM", 2, 0, "", longstatus,
longwarnings)
swApp.ActivateDoc2 "RoutingAssem1", False, longstatus
Set swAssemblyDoc = swModel
Set rtRouteManager = swAssemblyDoc.GetRouteManager()
boolstatus = swModel.Extension.SelectByID2("Harness1^RoutingAssem1-1@RoutingAssem1",
"COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
rtRouteManager.EditRoute
Set rtElectricalRoute = rtRouteManager.GetElectricalRoute
vCables = rtElectricalRoute.GetCables
If Not IsEmpty(vCables) Then
For i = 0 To
rtElectricalRoute.GetCablesCount - 1
Set rtCable = vCables(i)
Debug.Print "Cable " & rtCable.UserName
vCores = rtCable.GetCores
If Not IsEmpty(vCores) Then
lNumCores = rtCable.GetCoresCount
Debug.Print " Cutting length: " & rtCable.GetCuttingLength
Set rtCableProperty = rtCable.GetCableProperty
Debug.Print " Diameter: " & rtCableProperty.Diameter
Debug.Print " Name of cable library: " & rtCableProperty.Name
Debug.Print " Number of wires: " & lNumCores
For k = 0 To UBound(vCores)
Set aWire = vCores(k)
Debug.Print " " & aWire.UserName
Set aWireProperty = aWire.GetWireProperty
Debug.Print " Library name: " & aWireProperty.Name
Next k
Debug.Print ""
vCoreProperties = rtCableProperty.GetCoreProperties
For j = 0 To rtCableProperty.GetCorePropertyCount - 1
Set aWireProperty = vCoreProperties(j)
Debug.Print " Wire library name: " & aWireProperty.Name
Debug.Print " Color: " & aWireProperty.Color
Debug.Print " Diameter: " & aWireProperty.Diameter
Debug.Print " Part number: " & aWireProperty.PartNumber
Debug.Print " Size: " & aWireProperty.Size
Debug.Print ""
Next j
End If
Next i
End If
rtRouteManager.ExitRoute
swAssemblyDoc.EditAssembly
End Sub