Harness proD API Help
EPLAN.Harness.API.Projects.Documents Namespace / GraphicDocument Class / GetAllOccurrences Method / GetAllOccurrences() Method
Example
In This Topic
    GetAllOccurrences() Method
    In This Topic
    Get all occurrences in this document.
    Syntax
    public abstract IEnumerable<BaseOccurrence> GetAllOccurrences()

    Return Value

    Returns list of all occurrences in this document.
    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 operation was denied because of your license.
    This file is not opened.
    Remarks
    For environment occurrences call GetEnvironmentOccurrences.
    Example
    This example shows how to get list of all occurences in this document.
    // API is a singleton.
    HpdApi api = HpdApi.GetInstance();
    
    // Initialize API and load HpD.
    api.Init();
    
    // Open a Harness proD project.
    Project project = api.OpenProject(@"Path to the project");
    
    // Select the desired variant.
    Variant variant = project.GetVariants().FirstOrDefault(v => v.Name == "variant name");
    
    // Select and open the desired document (for example workspace).
    Workspace workspace = variant.GetWorkspaces().FirstOrDefault(w => w.Name == "workspace name");
    workspace.Open(false, false);
    
    // List of all occurrences in this document.
    List<BaseOccurrence> occs = workspace.GetAllOccurrences().ToList();
    
    // Close the workspace.
    workspace.Close()
    
    // Close the project.
    project.Close();
    
    // Close the API.
    api.Close();
    See Also