Hide Table of Contents

Start Route Example (VBA)

This example shows how to start a route using a selected routing component.

'----------------------------------------------------------------------------
' Preconditions:
' 1. Add SOLIDWORKS Routing as an add-in (select Tools > Add-Ins > SOLIDWORKS
'    Routing in SOLIDWORKS).
' 2. Add the SOLIDWORKS <version> Routing Type Library as a reference
'    (select Tools > References in the IDE).
' 3. In Tools > Options > System Options > Routing > Routing File Locations,
'    add the locations of your SOLIDWORKS Routing files.
' 4. Press F5 to run the macro.
'
' Postconditions:
' 1. When the macro stops, click the green checkmark in the Route 
'    Properties PropertyManager page to create the route. 
' 2. A route is added to the assembly. To verify, expand
'    Pipe_1StartRoute and locate the Route1 feature in the
'    FeatureManager design tree. 
'
' NOTE: Because the models are used elsewhere,
' do not save changes when closing the models.
' ---------------------------------------------------------------------------
Option Explicit
Dim SwApp               As SldWorks.SldWorks
Sub main()
    Dim swModel         As SldWorks.ModelDoc2
    Dim swAssembly      As SldWorks.AssemblyDoc
    Dim swModelDocExt   As SldWorks.ModelDocExtension
    Dim swRouteMgr      As SWRoutingLib.RouteManager
    Dim status          As Boolean
    Dim warnings        As Long
    Dim errors          As Long
    Dim fileName        As String
    ' Connect to SOLIDWORKS
    Set SwApp = Application.SldWorks
    If SwApp Is Nothing Then Exit Sub
    ' Open the assembly and make it the active document
    fileName = "public_documents\tutorial\api\StartRoute.sldasm"
    SwApp.OpenDoc6 fileName, swDocASSEMBLY, swOpenDocOptions_Silent, "Default", errors, warnings
    Set swModel = SwApp.ActiveDoc
    Set swAssembly = swModel
    Set swModelDocExt = swModel.Extension    
    ' Get the RouteManager
    Set swRouteMgr = swAssembly.GetRouteManager
    ' Select slip on weld flange component
    status = swModelDocExt.SelectByID2("slip on weld flange-1@MyStartRoute", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)    
    ' Start the route
    status = swRouteMgr.StartRoute("", "")    
    ' In SOLIDWORKS, click the green check mark in the Route
    ' Properties PropertyManager page to create the route
    ' Exit the route from edit mode
    swRouteMgr.ExitRoute    
    ' Exit editing the assembly
    swModel.EditAssembly
    swModel.ViewZoomtofit
    
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:   Start Route 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) 2021 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.