Hide Table of Contents

Get Route Properties of Selected Sketch Segment Example (C#)

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.
//----------------------------------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using SolidWorks.Interop.SWRoutingLib;
using System.Runtime.InteropServices;
 
namespace GetRouteProperties_CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        ModelDoc2 swModel;
        ModelDocExtension swModelDoc;
        AssemblyDoc swTopLevelAssembly;
        RouteManager rtRouteManager;
        Covering rtCovering;
        bool bRetVal;
 
        RouteProperty rtRouteProperty;
 
        public void Main()
        {
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swModelDoc = swModel.Extension;
            swTopLevelAssembly = (AssemblyDoc)swModel;
            rtRouteManager = (RouteManager)swTopLevelAssembly.GetRouteManager();
            if (rtRouteManager == null)
            {
                Debug.Print("No RouteManager found in top-level document: " + swModel.GetPathName());
                return;
            }
 
            // Select the route
            bRetVal = swModelDoc.SelectByID2("Route1@Harness1^RoutingAssem1-1@RoutingAssem1""ROUTEFABRICATED", 0, 0, 0, false, 0, null, 0);
            swModel.EditRoute();
 
            TestRoute(swModelDoc, rtRouteManager);
 
            rtRouteManager.ExitRoute();
            swTopLevelAssembly.EditAssembly();
 
        }
 
 
 
        private void TestRoute(ModelDocExtension swModelDoc, RouteManager rtRouteManager)
        {
            bRetVal = swModelDoc.SelectByID2("Spline1""SKETCHSEGMENT", 0, 0, 0, false, 0, null, 0);
 
 
            if ((!(bRetVal == false)))
            {
                rtRouteProperty = rtRouteManager.GetRouteProperty();
 
 
                if ((rtRouteProperty != null))
                {
                    double dOriginalLength = 0;
                    dOriginalLength = rtRouteProperty.GetFixedLength();
 
                    double dNewLength = 0;
                    dNewLength = dOriginalLength * 1.1;
 
                    int lResult = 0;
                    lResult = rtRouteProperty.SetFixedLength(dNewLength);
 
                    double dFinalLength = 0;
                    dFinalLength = rtRouteProperty.GetFixedLength();
 
                    Debug.Print("Spline1");
                    Debug.Print("  Fixed length? " + (dOriginalLength < dFinalLength));
                    if ((dOriginalLength < dFinalLength))
                    {
                        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);
                    }
 
                    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.HasCovering))
                    {
                        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);
                    }
 
                    Debug.Print("");
 
                }
 
            }
 
        }
 
 
        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
 
        public SldWorks swApp;
 
    }
}



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 (C#)
*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) 2020 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.