Harness proD API Help
EPLAN.Harness.API.Projects.Documents Namespace / Designer Class / CreateConstraints Method
Occurrence which will be master in the constraint.
Collection of occurrences which will be slaves in the constraint.
Example
In This Topic
    CreateConstraints Method
    In This Topic
    Create a constraint between occurrences.
    Syntax

    Parameters

    master
    Occurrence which will be master in the constraint.
    slaves
    Collection of occurrences which will be slaves in the constraint.

    Return Value

    Created constraint.
    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.
    This file is not opened.
    Remarks
    Constraint has to contain at least one slave.
    Example
    Create a constraint between occurrences. It freezes position between master and slave objects. The slave objects are moved and rotated with the master together.
    // Initialize API
    HpdApi api = HpdApi.GetInstance();
    api.Init();
    
    // Open a project and a workdesk.
    Project project = api.OpenProject(@"d:\Harness proD 2.9\Projects\Demo\Demo.hxproj");
    Variant variant = project.GetVariants()[0];
    variant.Open(false, false);
    Designer designer = variant.GetWorkdesks().FirstOrDefault(w => w.Name == "Workdesk_1");
    designer.Open(false, false);
    
    // Create a constraint between two connectors and a part.
    IOccPart part = designer.GetAllOccurrences<IOccPart>().FirstOrDefault(p => p. Name == "Part_1");
    IEnumerable<IOccConnector> conectors = designer.GetAllOccurrences<IOccConnector>(c => c.Name == "cn_00001" || c.Name == "cn_00002");
    IEnumerable<IOccConstraint> css = designer.CreateConstraints(part, conectors);
    
    // Save changes and close documents.
    designer.Save();
    designer.Close();
    variant.Close();
    project.Close();
    api.Close();
    See Also