Hide Table of Contents

Add to Route Example (VBA)

This example shows how to add to a route.

'----------------------------------------------------------------------------
' 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. The routing assembly component is added to the route at
'    CPoint1 and CPoint3 on the straight cross inch pipe component.
' 2. The routing assembly component is added to the reducing outlet cross inch
'    component.
'
' 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 swRouteMgr      As SWRoutingLib.RouteManager
    Dim swModelDocExt   As SldWorks.ModelDocExtension
    Dim boolstatus      As Boolean
    Dim errors          As Long
    Dim warnings        As Long
    Dim fileName        As String    
    Set swApp = Application.SldWorks
    If swApp Is Nothing Then Exit Sub    
    ' Open assembly document and make it the active document
    fileName = "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2018\samples\tutorial\api\AddtoRoute.sldasm"
    swApp.OpenDoc6 fileName, swDocASSEMBLY, swOpenDocOptions_Silent, "Default", errors, warnings
    Set swModel = swApp.ActiveDoc
    Set swAssembly = swModel    
    ' Get the RouteManager
    Set swRouteMgr = swAssembly.GetRouteManager
    swModel.ClearSelection2 True    
   ' Select the routing assembly component to add to the route
    Set swModelDocExt = swModel.Extension
    boolstatus = swModelDocExt.SelectByID2("Route1@Pipe_2^AddToRoute-1@AddToRoute", "ROUTEFABRICATED", 0, 0, 0, False, 0, Nothing, 0)    
    ' Put the route in edit mode
    swRouteMgr.EditRoute    
    swModel.ClearSelection2 True
   ' Select the connection points where to add the routing assembly component
    boolstatus = swModelDocExt.SelectByID2("CPoint3@Pipe_2^AddToRoute-1@AddToRoute/straight cross inch-1@Pipe_2^AddToRoute", "CONNECTIONPOINT", 0#, 0#, 0#, True, 0, Nothing, 0)
    boolstatus = swModelDocExt.SelectByID2("CPoint1@Pipe_2^AddToRoute-1@AddToRoute/straight cross inch-1@Pipe_2^AddToRoute", "CONNECTIONPOINT", 0#, 0#, 0#, True, 0, Nothing, 0)    
    ' Add to the route
    boolstatus = swRouteMgr.AddToRoute()
    swModel.ClearSelection2 True    
    ' Select the assembly component where to add the routing assembly component
    boolstatus = swModelDocExt.SelectByID2("reducing outlet cross inch-1@AddToRoute", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)    
    ' Add to the route
    boolstatus = swRouteMgr.AddToRoute() 
    ' Exit the route from edit mode
    swRouteMgr.ExitRoute    
    ' Exit editing the assembly
    swAssembly.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:   Add to 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) 2024 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.