Hide Table of Contents

Get Route Properties of Selected Sketch Segment Example (VB.NET)

This example shows how to get the route and covering properties of a sketch segment.

'----------------------------------------------------------------------------
' Preconditions:
' 1. In SOLIDWORKS, click Tools > Add-Ins > SOLIDWORKS Routing.
' 2. In Tools > Options > System Options > Routing > Routing File Locations,
'    click Launch Routing Library Manager and set the locations of your
'    SOLIDWORKS Routing files.
' 3. In the IDE, right-click the project, 
'    click Add Reference, browse install_dir\api\redist\CLR2, click
'    SolidWorks.Interop.SwRoutingLib.dll, and click OK.
' 4. Open public_documents\samples\tutorial\api\RoutingAssem1.sldasm.
' 5. Add a covering to the longest cable.
' 6. Open an Immediate window.
'
' Postconditions:
' 1. Edits Route1@Harness1^RoutingAssem1-1@RoutingAssem1.
' 2. Selects the Spline1 sketch segment.
' 3. Attempts to set the length of Spline1.
' 4. Prints the route and covering properties of Spline1.
' 5. Inspect the Immediate window.
'
' NOTE: Because the model is used elsewhere, do not save changes.
'----------------------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports SolidWorks.Interop.SWRoutingLib
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
 
 
Partial Class SolidWorksMacro
 
    Dim swModel As ModelDoc2
    Dim swModelDoc As ModelDocExtension
    Dim swTopLevelAssembly As AssemblyDoc
    Dim rtRouteManager As RouteManager
    Dim rtCovering As Covering
    Dim bRetVal As Boolean
    Dim rtRouteProperty As RouteProperty
 
    Sub Main()
 
        swModel = swApp.ActiveDoc
        swModelDoc = swModel.Extension
        swTopLevelAssembly = swModel
        rtRouteManager = swTopLevelAssembly.GetRouteManager
        If rtRouteManager Is Nothing Then
            Debug.Print("No RouteManager found in top-level document: " & swTopLevelAssembly.GetPathName)
            Exit Sub
        End If
 
        ' Select the route
        bRetVal = swModelDoc.SelectByID2("Route1@Harness1^RoutingAssem1-1@RoutingAssem1""ROUTEFABRICATED", 0, 0, 0, False, 0, Nothing, 0)
        swModel.EditRoute()
 
        TestRoute(swModelDoc, rtRouteManager)
 
        rtRouteManager.ExitRoute()
        swTopLevelAssembly.EditAssembly()
 
    End Sub
 
 
    Private Sub TestRoute(ByVal swModelDoc As ModelDocExtension, ByVal rtRouteManager As RouteManager)
 
        bRetVal = swModelDoc.SelectByID2("Spline1""SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)
 
        If (Not (bRetVal = False)) Then
 
            rtRouteProperty = rtRouteManager.GetRouteProperty
 
            If Not rtRouteProperty Is Nothing Then
 
                Dim dOriginalLength As Double
                dOriginalLength = rtRouteProperty.GetFixedLength
 
                Dim dNewLength As Double
                dNewLength = dOriginalLength * 1.1
 
                Dim lResult As Integer
                lResult = rtRouteProperty.SetFixedLength(dNewLength)
 
                Dim dFinalLength As Double
                dFinalLength = rtRouteProperty.GetFixedLength
 
                Debug.Print("Spline1")
                Debug.Print("  Fixed length? " & (dOriginalLength < dFinalLength))
                If (dOriginalLength < dFinalLength) Then
                    Debug.Print("  Original fixed length (T0): " & dOriginalLength)
                    Debug.Print("  Set fixed length result code as defined in swSetRouteFixedLengthError_e: " & lResult)
                    Debug.Print("  Final fixed length (T1): " & dFinalLength)
                End If
 
                Debug.Print("  Bend radius: " & rtRouteProperty.BendRadius)
                Debug.Print("  Minimum bend radius: " & rtRouteProperty.MinimumBendRadius)
                Debug.Print("  Route type as defined in swRouteType_e: " & rtRouteProperty.RouteType)
 
                If (rtRouteProperty.HasCoveringThen
                    rtCovering = rtRouteProperty.GetCovering
                    Debug.Print("  Covering properties:")
                    Debug.Print("    Name: " & rtCovering.Name)
                    Debug.Print("    Color: " & rtCovering.Color)
                    Debug.Print("    Outer diameter: " & rtCovering.OuterDiameter)
                    Debug.Print("    Part number: " & rtCovering.PartNumber)
                End If
 
                Debug.Print("")
 
            End If
 
        End If
 
    End Sub
 
 
    ''' <summary>
    ''' The SldWorks swApp variable is pre-assigned for you.
    ''' </summary>
    Public swApp As SldWorks
 
 
End Class
 



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 Route Properties of Selected Sketch Segment Example (VB.NET)
*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) 2019 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.