Hide Table of Contents

Get Minimum Radii of Wires Example (VBA)

This example shows how to get:

  • minimum bend radius for the bundle of wires in each route segment,
  • minimum bend radius for each route segment, and
  • types of route.
'----------------------------------------------------------------------------
' Preconditions:
' 1. Add SolidWorks Routing as an add-in
'   (in SolidWorks select Tools > Add-Ins > SolidWorks Routing).
' 2. Add the SolidWorks <version> Routing Type Library as a reference
'   (in the IDE select Tools > References).
' 3. Open install_dir\samples\tutorial\api\RoutingAssem1.sldasm.
' 4. Open the Immediate window.
' 5. Run the macro.
'
' Postconditions: Examine the Immediate window.
'
' NOTE: Because the assembly document is used elsewhere, do not save 
' any changes when closing it.
'---------------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Sub main()
    Dim swModel              As SldWorks.ModelDoc2
    Dim swModelDoc           As SldWorks.ModelDocExtension
    Dim swTopLevelAssembly   As SldWorks.AssemblyDoc
    Dim rtRouteManager       As SWRoutingLib.RouteManager
    Dim bRetVal              As Boolean
    
    ' Connect to SolidWorks
    Set swApp = Application.SldWorks
    ' Get the active document
    Set swModel = swApp.ActiveDoc
    Set swModelDoc = swModel.Extension
    ' Downcast from model document to assembly document
    Set swTopLevelAssembly = swModel
    ' Get the RouteManager from the top-level assembly
    ' Use selection tied to the current document, which is the
    ' top-level assembly, so get the RouteManager from there 
    ' instead of from the route subassembly
    Set rtRouteManager = swTopLevelAssembly.GetRouteManager
    If rtRouteManager Is Nothing Then
        Debug.Print "No RouteManager found in top-level document" 
        Exit Sub
    End If
    ' Select route in subassembly
    bRetVal = swModelDoc.SelectByID2("Route1@Harness1^RoutingAssem1-1@RoutingAssem1", "ROUTEFABRICATED", 0, 0, 0, False, 0, Nothing, 0)
    swModel.EditRoute
    ' Clear selection
    swModel.ClearSelection2 True
    ' Select the 3D Sketch
    bRetVal = swModelDoc.SelectByID2("3DSketch1@Harness1-RoutingAssem1-1@RoutingAssem1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
    ' Edit the 3D Sketch
    Debug.Print "Spline1:"
    TestRoute swModelDoc, rtRouteManager, "Spline1"
    Debug.Print "Spline2:"
    TestRoute swModelDoc, rtRouteManager, "Spline2"
    ' Stop editing
    swModel.Insert3DSketch2 True
    ' Return to editing the top-level assembly
    swTopLevelAssembly.EditAssembly
    
End Sub
Private Sub TestRoute(swModelDoc As ModelDocExtension, rtRouteManager As RouteManager, strSketchSegmentName As String)
    ' Select a sketch segment
    Dim bRetVal As Boolean
    bRetVal = swModelDoc.SelectByID2(strSketchSegmentName, "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)
    If (Not (bRetVal = False)) Then
        ' Get the RouteProperty for the selected sketch segment
        Dim rtRouteProperty As SWRoutingLib.ElectricalRouteProperty
        Set rtRouteProperty = rtRouteManager.GetRouteProperty
        
        If Not rtRouteProperty Is Nothing Then
            Debug.Print "  Bundle minimum bend radius      = " & rtRouteProperty.BundleMinimumBendRadius
            Debug.Print "  Minimum bend radius             = " & rtRouteProperty.MinimumBendRadius
            Select Case rtRouteProperty.RouteType
                Case SWRoutingLib.swRouteType_e.swRouteType_Electrical
                    Debug.Print "  Type                            = Electrical"
            End Select
        End If
    End If
End Sub


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get Minimum Radii of Wires Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2014 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.