Hide Table of Contents

Get RouteProperty from Selected Sketch Segment Example (VB.NET)

This example shows how to get RouteProperty information for a sketch segment.

'----------------------------------------------------------------------------

' Preconditions:

' 1. Ensure that the latest Solidworks.Interop.SWRoutingLib is loaded

'    (right-click on the project in Project

'    Explorer, click Add Reference, and browse:

'    <SolidWorks_install_dir>\api\redist).

' 2. Open:

<SolidWorks_install_dir>\samples\tutorial\routing\electrical\top_assy.sldasm.

' 3. On the Electrical menu, click Start by Drag/Drop.

' 4. From the Design library, drag and drop

'    routing > electrical > 90_richco_hurc-4-01-clip

'    into a hole in the housing wall.

' 5. Click OK in the Select a Configuration dialog.

' 6. Drag and drop routing > electrical > plug-5pindin into another hole

'    in the same housing wall.

' 7. Click the green check mark to accept the defaults.

' 8. In the Auto Route dialog, select CPoint1 in the plug and Axis3 of the clip.

' 9. Click the green check mark to create the route.

' 10. Save to a different directory.

'     Note:  Because this assembly is used in a SolidWorks tutorial,

'     do not save changes to the original path.

' 11. Run this macro (F5).

'

' Postconditions: Inspect the Immediate Window.

'--------------------------------------------------------------------------

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swconst

Imports SolidWorks.Interop.SWRoutingLib

Imports System

Imports System.Diagnostics

Partial Class SolidWorksMacro

    Sub Main()

        Dim swModel As ModelDoc2

        Dim swModelDoc As ModelDocExtension

        Dim swTopLevelAssembly As AssemblyDoc

        Dim rtRouteManager As RouteManager

        Dim bRetVal As Boolean

        ' Get the active document

        swModel = swApp.ActiveDoc

        swModelDoc = swModel.Extension

        ' Downcast from model document to assembly document

        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 there instead of from the

        '   route subassembly

        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 in the routing assembly

        bRetVal = swModelDoc.SelectByID2("Route1@Harness1-top_assy-1@top_assy", "ROUTEFABRICATED", 0, 0, 0, False, 0, Nothing, 0)

        swModel.EditRoute()

        TestRoute(swModelDoc, rtRouteManager, "Spline1") ' Not fixed length should fail to set

        swTopLevelAssembly.EditAssembly()

    End Sub

    Private Sub TestRoute(ByVal swModelDoc As ModelDocExtension, ByVal rtRouteManager As RouteManager, ByVal strSketchSegmentName As String)

        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 RouteProperty

            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 Long

                lResult = rtRouteProperty.SetFixedLength(dNewLength)

                Dim strSetResult As String

                strSetResult = DecodeSetRouteFixedLengthResult(lResult)

                Dim dFinalLength As Double

                dFinalLength = rtRouteProperty.GetFixedLength

                Debug.Print("Is Fixed Length? = " & (dOriginalLength > 0.0#))

                Debug.Print("Fixed Length (T0)= " & dOriginalLength)

                Debug.Print("Set result       = " & lResult & " (" & strSetResult & ")")

                Debug.Print("Fixed Length (T1)= " & dFinalLength)

                Debug.Print("Bend radius      = " & rtRouteProperty.BendRadius)

                Debug.Print("Covering present = " & rtRouteProperty.HasCovering)

                Select Case rtRouteProperty.RouteType

                    Case swRouteType_e.swRouteType_Electrical

                        Debug.Print("Type             = Electrical")

                End Select

                Debug.Print("")

            End If

        End If

    End Sub

    Private Function DecodeSetRouteFixedLengthResult(ByVal lResult As Long) As String

        Select Case lResult

            Case swSetRouteFixedLengthError_e.swSetRouteFixedLengthError_NoError

                DecodeSetRouteFixedLengthResult = "swSetRouteFixedLengthError_NoError"

            Case swSetRouteFixedLengthError_e.swSetRouteFixedLengthError_NoProperty

                DecodeSetRouteFixedLengthResult = "swSetRouteFixedLengthError_NoProperty"

            Case swSetRouteFixedLengthError_e.swSetRouteFixedLengthError_NotFixedLengthSegment

                DecodeSetRouteFixedLengthResult = "swSetRouteFixedLengthError_NotFixedLengthSegment"

            Case swSetRouteFixedLengthError_e.swSetRouteFixedLengthError_NotFlexible

                DecodeSetRouteFixedLengthResult = "swSetRouteFixedLengthError_NotFlexible"

            Case swSetRouteFixedLengthError_e.swSetRouteFixedLengthError_SelectionFailed

                DecodeSetRouteFixedLengthResult = "swSetRouteFixedLengthError_SelectionFailed"

            Case swSetRouteFixedLengthError_e.swSetRouteFixedLengthError_SetLengthFailed

                DecodeSetRouteFixedLengthResult = "swSetRouteFixedLengthError_SetLengthFailed"

            Case Else

                DecodeSetRouteFixedLengthResult = "UNEXPECTED RESULT"

        End Select

    End Function

    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 RouteProperty from 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) 2011 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.