Harness proD API Help
EPLAN.Harness.API.Projects.Documents Namespace / Designer Class / RoutePathSegment Method
First point of the segment to route.
Second point of the segment to route.
An occurrence to which we want to route the segment. (bundle, control point or a leading part with only one option for routing)
In case we are routing to a leading part, which has more leading paths, we need to specify second end point of the leading path.
Example
In This Topic
    RoutePathSegment Method
    In This Topic
    Routes a path segment between two control points through some other suitable object.
    Syntax

    Parameters

    segmentPoint1
    First point of the segment to route.
    segmentPoint2
    Second point of the segment to route.
    routeTarget
    An occurrence to which we want to route the segment. (bundle, control point or a leading part with only one option for routing)
    secondLpEndpoint
    In case we are routing to a leading part, which has more leading paths, we need to specify second end point of the leading path.
    Exceptions
    ExceptionDescription
    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 input control points lie on a different path.
    Thrown when input control points are not neighboring.
    Remarks
    Segment must be from the EPLAN.Harness.API.Occurrences.Interfaces.ISegmentRoutable occurrence (or its top layer if it is a cable). The segment to route has to be specified by two neighboring control points which lie on one part of a path. When routing to a leading part which has more possible leading paths, specify first point in routeTarget argument and the second point with secondLpEndpoint.
    Example
    This example shows how to route a segment between two control points into a bundle.
    var api = HpdApi.GetInstance();
    api.Init();
    
    var project = api.OpenProject($"{myProjectPath}");
    var wsp = project.GetVariants().FirstOrDefault()?.GetWorkspaces().FirstOrDefault(w => w.Name.Contains("MyWorkspace"));
    wsp.Open(false, false);
    					
    var cp = wsp.GetAllOccurrences().FirstOrDefault(o => o.Name == "cp_1") as IControlPoint;
    var cp2 = wsp.GetAllOccurrences().FirstOrDefault(o => o.Name == "cp_2") as IControlPoint;
    var bund = wsp.GetAllOccurrences().FirstOrDefault(o => o.Name == "bundle_1");
    
    wsp.RoutePathSegment(cp, cp2, bund);
    
    wsp.Save();
    wsp.Close();
    project.Save();
    project.Close();
    This example shows how to route a first segment from desired occurrence into a bundle.
    var api = HpdApi.GetInstance();
    api.Init();
    
    var project = api.OpenProject($"{myProjectPath}");
    var wsp = project.GetVariants().FirstOrDefault()?.GetWorkspaces().FirstOrDefault(w => w.Name.Contains("MyWorkspace"));
    wsp.Open(false, false);
    					
    // Find the segment routable occurrence.
    IControlPath routable = wsp.GetAllOccurrences<ISegmentRoutable>().FirstOrDefault(o => o.Name == "path_1");
    					
    // If the occurrence is cable, limit the control path to the top layer only.
    if (routable is ICable cable)
    {
    	routable = cable.CableSubParts.OfType<ICableSublayer>().FirstOrDefault(s => s.IsTopLayer);
    }
    					
    // First and second point from this control path.
    IControlPoint cp = routable.GetControlPoints()[0];
    IControlPoint cp2 = routable.GetControlPoints()[1];
    					
    var bund = wsp.GetAllOccurrences().FirstOrDefault(o => o.Name == "bundle_1");
    					
    wsp.RoutePathSegment(cp, cp2, bund);
    
    wsp.Save();
    wsp.Close();
    project.Save();
    project.Close();
    See Also