Harness proD API Help
EPLAN.Harness.API.Projects.Documents Namespace / Designer Class / PlaceCable Method
Library part of placed cable.
Connections of wires of placed cable. The dictionary keys are EPLAN.Harness.API.LibraryParts.CableEntities.CableWireInfo which can be obtained as children of placed library cable. The value specifies more details about how the wire would be connected.
Parameter holding positions and structure of control points of the cable which is being placed. You can find more info in EPLAN.Harness.API.DataStructures.CableLayersPositionData class.
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
    PlaceCable Method
    In This Topic
    Places a cable from library.
    Syntax

    Parameters

    apiLibCable
    Library part of placed cable.
    connections
    Connections of wires of placed cable. The dictionary keys are EPLAN.Harness.API.LibraryParts.CableEntities.CableWireInfo which can be obtained as children of placed library cable. The value specifies more details about how the wire would be connected.
    positionData
    Parameter holding positions and structure of control points of the cable which is being placed. You can find more info in EPLAN.Harness.API.DataStructures.CableLayersPositionData class.
    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.HpdApi.Status property. If API is uninitialized, you can initialize it by calling EPLAN.Harness.API.HpdApi.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 input structure based on positionData is validated and an exception will be thrown whenever the resulting cable would not be manually placeable in Harness proD Studio.

    No connector pin may be a child of a ribbon pin.

    Count of connections must be less than or equal to the count of wires of the cable.

    To connect cable's conductive shield directly to a pin, place the cable first with this method and then use ConnectShield to connect the shield.

    Example
    This simple example shows how to place a library cable with a top insulator and two wires. We will specify the insulator end points positions and we will connect both wires to specific pins.
    // Obtain workspace and project beforehand by an arbitrary way.
    HpdApi api = HpdApi.GetInstance();
    api.Init();
    					
    Project proj = api.OpenProject($"{pathToMyProject}");
    Variant variant = proj.GetVariants().First();
    Workspace workspace = variant.GetWorkspaces().First();
    workspace.Open(false, false);
    
    // Choose a library part for cable by some method, e.g. GetLibraryPartsByPartNumber().
    LibCable cable = (LibCable)proj.ActiveConnection.GetLibraryPartsByPartNumber("Cable1").FirstOrDefault();
    
    // For simplicity, leave sub-layers positions empty in this example.
    Dictionary<BaseCablePlaceableEntityInfo, (List<PlacePosition>, List<PlacePosition>)> emptySublayersPositionData = new Dictionary<BaseCablePlaceableEntityInfo, (List<PlacePosition>, List<PlacePosition>)>();
    
    // Get wire sub-entities of our cable.
    var wires = cable?.GetCableSubentities().OfType<CableWireInfo>().ToList();
    
    // Get pins to which the wires will be connected by an arbitrary way, assume there already are at least 4 distinct pins in the workspace.
    List<IPinBase> allPins = workspace.GetAllOccurrences().OfType<IPinBase>().ToList();
    
    IPinBase pin1 = allPins[0];
    IPinBase pin2 = allPins[1];
    IPinBase pin3 = allPins[2];
    IPinBase pin4 = allPins[3];
    
    // Set up the dictionary and populate it with connections, suppose that our cable has at least two wires.
    Dictionary<CableWireInfo, Connection> connectionsDict = new Dictionary<CableWireInfo, Connection>();
    
    connectionsDict.Add(wires[0], new Connection(pin1, pin2));
    connectionsDict.Add(wires[1], new Connection(pin3, pin4));
    
    // Now lets define the positions for cable's top insulator end points.
    TransformProperty<LengthProperty> layerEnd1 = new TransformProperty<LengthProperty>
    (
    	new LengthProperty(-80, Unit.Millimeter),
    	new LengthProperty(220, Unit.Millimeter),
    	new LengthProperty(140, Unit.Millimeter)
    );
    
    TransformProperty<LengthProperty> layerEnd2 = new TransformProperty<LengthProperty>
    (
    	new LengthProperty(-50, Unit.Millimeter),
    	new LengthProperty(120, Unit.Millimeter),
    	new LengthProperty(70, Unit.Millimeter)
    );
    
    // Aggregate position data to a wrapping class.
    CableLayersPositionData clpd = new CableLayersPositionData(new PlacePosition(layerEnd1), new PlacePosition(layerEnd2), new List<TransformProperty<LengthProperty>>(), emptySublayersPositionData);
    
    // And finally place the cable.
    IOccCable placedCable = workspace.PlaceCable(cable, connectionsDict, clpd);
    
    workspace.Save();
    workspace.Close();
    proj.Save();
    proj.Close();
    api.Close();
    This example shows how to place a library cable with two (or more) shields under top insulator. We will specify two control points for each shield.
    // Obtain workspace and project beforehand by an arbitrary way.
    HpdApi api = HpdApi.GetInstance();
    api.Init();
    					
    Project proj = api.OpenProject($"{pathToMyProject}");
    Variant variant = proj.GetVariants().First();
    Workspace workspace = variant.GetWorkspaces().First();
    workspace.Open(false, false);
    
    // Choose a library part for cable by some method, e.g. GetLibraryPartsByPartNumber().
    LibCable cableLib = (LibCable)proj.ActiveConnection.GetLibraryPartsByPartNumber("MyLibCable").FirstOrDefault();
    
    // Get wire subentities of our cable.
    var wires = cableLib?.GetCableSubentities().OfType<CableWireInfo>().ToList();
    
    // Get pins and set up connections, similarly as in previous example.
    List<IPinBase> allPins = workspace.GetAllOccurrences().OfType<IPinBase>().ToList();
    
    IPinBase pin1 = allPins[0];
    IPinBase pin2 = allPins[1];
    IPinBase pin3 = allPins[2];
    IPinBase pin4 = allPins[3];
    
    Dictionary<CableWireInfo, Connection> connectionsDict = new Dictionary<CableWireInfo, Connection>();
    
    // Assume cable has at least two child wires.
    connectionsDict.Add(wires[0], new Connection(pin1, pin2));
    connectionsDict.Add(wires[1], new Connection(pin3, pin4));
    
    
    // Define positions of top insulator's control points.
    TransformProperty<LengthProperty> topEntityEnd1 = new TransformProperty<LengthProperty>
    (
    	new LengthProperty(30, Unit.Millimeter),
    	new LengthProperty(30, Unit.Millimeter),
    	new LengthProperty(30, Unit.Millimeter)
    );
    
    TransformProperty<LengthProperty> topEntityEnd2 = new TransformProperty<LengthProperty>
    (
    	new LengthProperty(-30, Unit.Millimeter),
    	new LengthProperty(-30, Unit.Millimeter),
    	new LengthProperty(-30, Unit.Millimeter)
    );
    
    //Get all cable sub-entities of type shield.
    IEnumerable<BaseCableEntityInfo> cableShields = cableLib?.GetCableSubentities()?.Where(c => c is CableShieldInfo);
    
    Dictionary<BaseCablePlaceableEntityInfo, (List<PlacePosition>, List<PlacePosition>)> sublayersPositionData = new Dictionary<BaseCablePlaceableEntityInfo, (List<PlacePosition>, List<PlacePosition>)>();
    
    // Define some coordinates for control points.
    int oddEnd = -100;
    int evenEnd = 100;
    int distanceNewLayer = 0;
    int distanceSameLayer = 30;
    int offsetZ = 0;
    
    // Cycle through cable shields and define positions of control points for each of them.
    foreach (BaseCablePlaceableEntityInfo cableEntity in cableShields)
    {
    	TransformProperty<LengthProperty> placePosition1 = new TransformProperty<LengthProperty>
    	(
    		new LengthProperty(oddEnd - distanceNewLayer, Unit.Millimeter),
    		new LengthProperty(oddEnd - distanceNewLayer, Unit.Millimeter),
    		new LengthProperty(oddEnd + offsetZ, Unit.Millimeter)
    	);
    	TransformProperty<LengthProperty> placePosition3 = new TransformProperty<LengthProperty>
    	(
    		new LengthProperty(oddEnd - distanceNewLayer + distanceSameLayer, Unit.Millimeter),
    		new LengthProperty(oddEnd - distanceNewLayer + distanceSameLayer, Unit.Millimeter),
    		new LengthProperty(oddEnd + offsetZ, Unit.Millimeter)
    	);
    	TransformProperty<LengthProperty> placePosition2 = new TransformProperty<LengthProperty>
    	(
    		new LengthProperty(evenEnd + distanceNewLayer, Unit.Millimeter),
    		new LengthProperty(evenEnd + distanceNewLayer, Unit.Millimeter),
    		new LengthProperty(evenEnd + offsetZ, Unit.Millimeter)
    	);
    	TransformProperty<LengthProperty> placePosition4 = new TransformProperty<LengthProperty>
    	(
    		new LengthProperty(evenEnd + distanceNewLayer - distanceSameLayer, Unit.Millimeter),
    		new LengthProperty(evenEnd + distanceNewLayer - distanceSameLayer, Unit.Millimeter),
    		new LengthProperty(evenEnd + offsetZ, Unit.Millimeter)
    	);
    
    	sublayersPositionData.Add(cableEntity, (new List<PlacePosition> { new PlacePosition(placePosition1), new PlacePosition(placePosition3) }, new List<PlacePosition> { new PlacePosition(placePosition2), new PlacePosition(placePosition4) }));
    
    	distanceNewLayer += 60;
    	offsetZ += 50;
    }
    
    // Aggregate position data to a wrapping class.
    CableLayersPositionData clpd = new CableLayersPositionData(new PlacePosition(topEntityEnd1), new PlacePosition(topEntityEnd2), new List<TransformProperty<LengthProperty>>(), sublayersPositionData);
    
    // And finally place the cable.
    IOccCable cable = workspace.PlaceCable(cableLib, connectionsDict, clpd);
    
    workspace.Save();
    workspace.Close();
    proj.Save();
    proj.Close();
    api.Close();
    Third example shows how to connect a cable sublayer to a grouped pin.
    // Obtain workspace and project beforehand by an arbitrary way.
    HpdApi api = HpdApi.GetInstance();
    api.Init();
    					
    Project proj = api.OpenProject($"{pathToMyProject}");
    Variant variant = proj.GetVariants().First();
    Workspace workspace = variant.GetWorkspaces().First();
    workspace.Open(false, false);
    
    // Choose a library part for cable by some method, e.g. GetLibraryPartsByPartNumber().
    LibCable cableLib = (LibCable)proj.ActiveConnection.GetLibraryPartsByPartNumber("MyLibCable").FirstOrDefault();
    
    // Get wire sub-entities of our cable.
    var wires = cableLib?.GetCableSubentities().OfType<CableWireInfo>().ToList();
    
    // Get pins and set up connections for wires.
    List<IOccVirtualPin> allPins = workspace.GetAllOccurrences().OfType<IOccVirtualPin>().ToList();
    
    IPinBase pin1 = allPins[0];
    IPinBase pin2 = allPins.Where(p => p.Parents.First().ID != pin1.Parents.First().ID).ToList()[0];
    
    IPinBase pin3 = allPins[1];
    IPinBase pin4 = allPins.Where(p => p.Parents.First().ID != pin3.Parents.First().ID).ToList()[1];
    
    Dictionary<CableWireInfo, Connection> connectionsDict = new Dictionary<CableWireInfo, Connection>();
    
    // Assume cable has at least two wires.
    connectionsDict.Add(wires[0], new Connection(pin1, pin2));
    connectionsDict.Add(wires[1], new Connection(pin3, pin4));
    
    // Let's assume that pin1 and pin3 have mutual parent grouped pin, and so if we took parent from pin3 instead of pin1, the result would be the same.
    // This assumption is important because of validation.
    IOccGroupedPin groupedPin = pin1.Parents.OfType<IOccGroupedPin>().First();
    
    // When PlacePosition is created like this, i.e. from an occurrence instead of coordinates, the cable layer will be connected to a grouped pin which is used in PlacePosition constructor.
    // In this case, we connect one end of the top insulator to a grouped pin.
    PlacePosition topEntityPosition = new PlacePosition(groupedPin as Base3DOccurrence);
    
    // Define the second end of top insulator by coordinates - we know this from other examples.
    TransformProperty<LengthProperty> topEntityEnd2 = new TransformProperty<LengthProperty>
    (
    	new LengthProperty(-30, Unit.Millimeter),
    	new LengthProperty(-30, Unit.Millimeter),
    	new LengthProperty(-30, Unit.Millimeter)
    );
    
    // Now lets create a structure of cable sub-layers. Assume the cable only has shields and a top insulator.
    
    //Get all cable sub-entities of type shield.
    IEnumerable<BaseCableEntityInfo> cableShields = cableLib?.GetCableSubentities()?.Where(c => c is CableShieldInfo);
    
    Dictionary<BaseCablePlaceableEntityInfo, (List<PlacePosition>, List<PlacePosition>)> sublayersPositionData = new Dictionary<BaseCablePlaceableEntityInfo, (List<PlacePosition>, List<PlacePosition>)>();
    
    // Define some coordinates for control points.
    int evenEnd = 100;
    int distanceNewLayer = 0;
    int distanceSameLayer = 30;
    int offsetZ = 0;
    
    // Cycle through cable shields and define positions of control points for each of them.
    foreach (BaseCablePlaceableEntityInfo cableEntity in cableShields)
    {
    	TransformProperty<LengthProperty> placePosition2 = new TransformProperty<LengthProperty>
    	(
    		new LengthProperty(evenEnd + distanceNewLayer, Unit.Millimeter),
    		new LengthProperty(evenEnd + distanceNewLayer, Unit.Millimeter),
    		new LengthProperty(evenEnd + offsetZ, Unit.Millimeter)
    	);
    	TransformProperty<LengthProperty> placePosition4 = new TransformProperty<LengthProperty>
    	(
    		new LengthProperty(evenEnd + distanceNewLayer - distanceSameLayer, Unit.Millimeter),
    		new LengthProperty(evenEnd + distanceNewLayer - distanceSameLayer, Unit.Millimeter),
    		new LengthProperty(evenEnd + offsetZ, Unit.Millimeter)
    	);
    
    	// Leave the first list empty for each shield. First list belongs to "first" end of top insulator and since this end is connected to a grouped pin, all shields must also end
    	// on that grouped pin. We can define some control points for the "second" end though.
    	sublayersPositionData.Add(cableEntity, (new List<PlacePosition>(), new List<PlacePosition> { new PlacePosition(placePosition2), new PlacePosition(placePosition4) }));
    
    	distanceNewLayer += 60;
    	offsetZ += 50;
    }
    
    // Aggregate position data to a wrapping class.
    CableLayersPositionData clpd = new CableLayersPositionData(topEntityPosition, new PlacePosition(topEntityEnd2), new List<TransformProperty<LengthProperty>>(), sublayersPositionData);
    
    // And finally place the cable without any accessory.
    IOccCable cable = workspace.PlaceCable(cableLib, connectionsDict, clpd, ApiLinkType.None);
    
    workspace.Save();
    workspace.Close();
    proj.Save();
    proj.Close();
    api.Close();
    See Also