Hide Table of Contents

Get Cable Cores Example (C#)

This example shows how to get the cores of cables.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified assembly exists.
// 2. In SOLIDWORKS, click Tools > Add-Ins > SOLIDWORKS Routing.
// 3. In Tools > Options > System Options > Routing > Routing File Locations,
//    click Launch Routing Library Manager and set the locations of your
//    SOLIDWORKS Routing files.
// 4. In the IDE, right-click the project, 
//    click Add Reference, browse install_dir\api\redist\CLR2, click
//    SolidWorks.Interop.SwRoutingLib.dll, and click OK.
// 5. Open an Immediate window.
//
// Postconditions:
// 1. Opens the specified assembly.
// 2. Selects Harness1^RoutingAssem1-1.
// 3. Gets the cables in the electrical route.
// 4. Prints the number of wires and the properties of each wire in the cable.
// 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 GetCores_CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        ModelDoc2 swModel;
        AssemblyDoc swAssemblyDoc;
        RouteManager rtRouteManager;
        ElectricalRoute rtElectricalRoute;
        Cable rtCable;
        CableProperty rtCableProperty;
        WireProperty aWireProperty;
        Wire aWire;
        int lNumCores;
        int i;
        int j;
        int k;
        object[] vCables;
        object[] vCores;
        object[] vCoreProperties;
        bool boolstatus;
        int longstatus;
        int longwarnings;
 
        public void Main()
        {
            swModel = swApp.OpenDoc6("C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\api\\RoutingAssem1.SLDASM", 2, 0, ""ref longstatus, ref longwarnings);
            swApp.ActivateDoc2("RoutingAssem1"falseref longstatus);
            swAssemblyDoc = (AssemblyDoc)swModel;
            rtRouteManager = (RouteManager)swAssemblyDoc.GetRouteManager();
            boolstatus = swModel.Extension.SelectByID2("Harness1^RoutingAssem1-1@RoutingAssem1""COMPONENT", 0, 0, 0, false, 0, null, 0);
 
            rtRouteManager.EditRoute();
            rtElectricalRoute = rtRouteManager.GetElectricalRoute();
 
            vCables = (object[])rtElectricalRoute.GetCables();
 
 
            if ((vCables != null))
            {
                for (i = 0; i <= rtElectricalRoute.GetCablesCount() - 1; i++)
                {
                    rtCable = (Cable)vCables[i];
 
                    Debug.Print("Cable " + rtCable.UserName);
 
                    vCores = (object[])rtCable.GetCores();
 
 
                    if ((vCores != null))
                    {
                        lNumCores = rtCable.GetCoresCount();
 
                        Debug.Print("  Cutting length: " + rtCable.GetCuttingLength());
                        rtCableProperty = rtCable.GetCableProperty();
 
                        Debug.Print("  Diameter: " + rtCableProperty.Diameter);
                        Debug.Print("  Name of cable library: " + rtCableProperty.Name);
                        Debug.Print("  Number of wires: " + lNumCores);
                        for (k = 0; k <= vCores.GetUpperBound(0); k++)
                        {
                            aWire = (Wire)vCores[k];
                            Debug.Print("    " + aWire.UserName);
                            aWireProperty = aWire.GetWireProperty();
                            Debug.Print("      Library name: " + aWireProperty.Name);
                        }
 
                        Debug.Print("");
 
                        vCoreProperties = (object[])rtCableProperty.GetCoreProperties();
                        for (j = 0; j <= rtCableProperty.GetCorePropertyCount() - 1; j++)
                        {
                            aWireProperty = (WireProperty)vCoreProperties[j];
                            Debug.Print("    Wire library name: " + aWireProperty.Name);
                            Debug.Print("      Color: " + aWireProperty.Color);
                            Debug.Print("      Diameter: " + aWireProperty.Diameter);
                            Debug.Print("      Part number: " + aWireProperty.PartNumber);
                            Debug.Print("      Size: " + aWireProperty.Size);
                            Debug.Print("");
                        }
 
                    }
 
                }
 
            }
 
            rtRouteManager.ExitRoute();
            swAssemblyDoc.EditAssembly();
 
        }
 
 
 
        /// <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 Cable Cores 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) 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.