Harness proD API Help
EPLAN.Harness.API.Occurrences.Workspace Namespace / OccWsConstraintSimple Class / Toggle Method
Example
In This Topic
    Toggle Method (OccWsConstraintSimple)
    In This Topic
    Toggle (exchange) master and slave occurrences of a constraint.
    Syntax
    public void Toggle()
    Exceptions
    ExceptionDescription
    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.
    Argument is null.
    The exception that is thrown when you trying to access to already deleted occurrence.
    You can not perform this action on a document opened as read only.
    Example
    The example shows how to toggle master and slave occurrences of a constraint.
    // Initialize API
    Studio api = Studio.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];
    Designer designer = variant.GetWorkdesks().FirstOrDefault(w => w.Name == "Workdesk_1");
    designer.Open(false, false);
    
    // Select a constraint and togle its master and slave.
    IOccConstraintSimple constraint = workdesk.GetAllOccurrences<IOccConstraintSimple>().FirstOrDefault(c => c.Name == "cp_00026 :: cn_00001");
    constraint.Toggle();
    
    // Save changes and close documents.
    designer.Save();
    designer.Close();
    project.Close();
    See Also