Harness proD API Help
EPLAN.Harness.API.Projects.Documents Namespace / Designer Class / PlaceRibbonCable Method / PlaceRibbonCable(LibRibbonCable,List<RibbonCableInputBranchInfo>,List<Connection>,ApiLinkType) Method
Library part of placed cable.
List holding information about branching of ribbon cable.
Connections of wires of placed cable. Determines which pins on connectors will be connected by a wire.
Determines if part's accessories will be placed with part. Mandatory, Optional, both types or None accessories can be placed. This enum has the Flags attribute.
Example
In This Topic
    PlaceRibbonCable(LibRibbonCable,List<RibbonCableInputBranchInfo>,List<Connection>,ApiLinkType) Method
    In This Topic
    Places a ribbon cable from library to designer.
    Syntax

    Parameters

    libRibbonCable
    Library part of placed cable.
    branches
    List holding information about branching of ribbon cable.
    connections
    Connections of wires of placed cable. Determines which pins on connectors will be connected by a wire.
    linkType
    Determines if part's accessories will be placed with part. Mandatory, Optional, both types or None accessories can be placed. This enum has the Flags attribute.

    Return Value

    Placed cable.
    Exceptions
    ExceptionDescription
    This file is not opened.
    Api is not in an initialized state. You can get current state from EPLAN.Harness.API.Studio.Status property. If API is uninitialized, you can initialize it by calling EPLAN.Harness.API.Studio.Init method. If API is in failed state, you can not resurrect it.
    The object is in invalid state. Obtain a new one.
    Thrown when the occurrence is not part of this document.
    Remarks

    The order of branch infos in branches is important. The branches have to be sorted exactly as they are placed manually in HpD Studio (i.e. main branch is first in the list, then comes main branch's first subbranch, then next first subbranch etc.). Also the wire counts and first wire indices in each branch have to be entered precisely.

    The order of connections in connections is important too. First item in the list defines connections of the first wire, second item stands for second wire etc. It means that if we want to define connections for fifth wire only, we need to add four empty connections (i.e. both pins are null) to the beginning of the list and the fifth connection is the one for the fifth wire.

    Example
    This example shows how to connect four connectors with a ribbon cable.
    // initialize API and obtain workspace
    var api = Studio.GetInstance();
    api.Init();
    					
    var project = api.OpenProject("path to project");
    var variant = project.GetVariants().FirstOrDefault();
    var wsp = project.GetVariants().FirstOrDefault()?.GetWorkspaces().FirstOrDefault(w => w.Name.Contains("my workspace name"));
    wsp.Open(false, false);
    
    // obtain ribbon cable from library
    var ribbonCableLib = project.ActiveConnection.GetLibraryPartsByType(new List<ApiPartType>{ApiPartType.RibbonCable}).FirstOrDefault();
    
    // find connector occurrences by name
    var conn1 = wsp.GetAllOccurrences().FirstOrDefault(o => o.Name == "cn_00001") as OccWsRibbonConnector;
    var conn2 = wsp.GetAllOccurrences().FirstOrDefault(o => o.Name == "cn_00002") as OccWsRibbonConnector;
    var conn3 = wsp.GetAllOccurrences().FirstOrDefault(o => o.Name == "cn_00003") as OccWsRibbonConnector;
    var conn4 = wsp.GetAllOccurrences().FirstOrDefault(o => o.Name == "cn_00004") as OccWsRibbonConnector;
    
    // find inline ribbon pin occurrence by name (it will be one of ribbon cable's control points)
    var inline = wsp.GetAllOccurrences().FirstOrDefault(o => o.Name == "inline");
    
    // define first branch info - this will be the main branch, method GetPostions1 returns two PlacePositions of cable's control points, it is declared below
    var branchInfo = new RibbonCableInputBranchInfo(
    									conn1.Children.FirstOrDefault(ch => ch is IOccRibbonPin) as IOccRibbonPin,
    									null,
    									GetPositions1(),
    									8,
    									0);
    
    // first subbranch of the cable, it is connected to "cn_00002" and has some middle control points (depends on definition of GetPositions2, which is analogical to GetPositions1)
    var branchInfo2 = new RibbonCableInputBranchInfo(
    									 null,
    									 conn2.Children.FirstOrDefault(ch => ch is IOccRibbonPin) as IOccRibbonPin,
    									 GetPositions2(),
    									 4,
    									 0);
    
    
    // initialize a PlacePosition list with an occurrence - the inline ribbon pin and add some coordinate based positions returned by GetPositions5
    var positionsList = new List<PlacePosition> {new PlacePosition(inline.Children.FirstOrDefault(ch => ch is IOccInlineRibbonPin) as IOccInlineRibbonPin)}.ToList();
    positionsList.AddRange(GetPositions5());
    
    // define second subbranch of the main branch, this branch will split in two new subbranches and contains an inline connector as a control point
    var branchInfo3 = new RibbonCableInputBranchInfo(
    										null,
    										null,
    										positionsList,
    										4,
    										4);
    
    // last two subbranches which are connected to a connector
    var branchInfo4 = new RibbonCableInputBranchInfo(
    										 null,
    										 conn3.Children.FirstOrDefault(ch => ch is IOccRibbonPin) as IOccRibbonPin,
    										 GetPositions3(),
    										 1,
    										 4);
    
    var branchInfo5 = new RibbonCableInputBranchInfo(
    										 null,
    										 conn4.Children.FirstOrDefault(ch => ch is IOccRibbonPin) as IOccRibbonPin,
    										 GetPositions4(),
    										 3,
    										 5);
    
    // we keep connections empty in this example - the wires are connected to super pins
    var connections = new List<Connection>();
    var cable = wsp.PlaceRibbonCable(ribbonCableLib as LibRibbonCable, new List<RibbonCableInputBranchInfo>{ branchInfo, branchInfo2, branchInfo3, branchInfo4, branchInfo5 } , connections);
    
    wsp.Save();
    wsp.Close();
    project.Save();
    project.Close();
    
    // local method which returns a list of two PlacePositions
    List<PlacePosition> GetPositions1()
    {
    	var x = new LengthProperty(2.000, Unit.Meter);
    	var y = new LengthProperty(-0.125, Unit.Meter);
    	var z = new LengthProperty(1.900, Unit.Meter);
    	var first = new TransformProperty<LengthProperty>(x, y, z);
    
    	x = new LengthProperty(1.850, Unit.Meter);
    	y = new LengthProperty(0.380, Unit.Meter);
    	z = new LengthProperty(0.160, Unit.Meter);
    	var second = new TransformProperty<LengthProperty>(x, y, z);
    
    	return new List<PlacePosition>{new PlacePosition(first), new PlacePosition(second)};
    }
    See Also