Harness proD API Help
EPLAN.Harness.API.LibraryParts Namespace / BaseConstructionItem Class / Accessories Property
Example
In This Topic
    Accessories Property (BaseConstructionItem)
    In This Topic
    Accessories of this item. It is IList collection. A list item can be accessed trough the numbered index. Add(), Remove(), RemoveAt(), Clear() methods are supported only.
    Syntax
    public virtual IList<AccessoryInfo> Accessories {get;}
    Exceptions
    ExceptionDescription
    Base HpD Api Exception.
    The operation was not successful.
    The exception is thrown in case of attempt to access a property or a method which is not supported on the current instance of the object.
    Remarks
    This is not a simple property. Getting this property may take a while. object is read-only. If an update of its properties is required, it must be created again.
    Example
    // Init API
    Library api = Library.GetInstance();
    api.Init();
    
    // Set library connection.
    api.AddLibraryConnection(@"c:\Users\test\Documents\Harness proD 2024\Connections\Demo.hxcn");
    BaseLibraryConnection connection = api.CurrentLibrary.Connection;
    api.ConnectToLibrary(connection);
    
    // Select a part.
    BaseConstructionItem part = api.CurrentLibrary.GetAllLibraryParts().OfType<CountableLibraryPart>().FirstOrDefault(p => p.PartNumber == "c-0206430");
    part.Open();
    
    // Select an accessory.
    AccessoryInfo accessoryToUpdate = part.Accessories[1];
    					
    // Copy properties and update them.
    CountableLibraryPart accessoryPart = accessoryToUpdate.Part as CountableLibraryPart;
    BooleanProperty isMandatory = !accessoryToUpdate.Mandatory;
    IntegerProperty quantity = accessoryToUpdate.Quantity + 3;
    TextProperty accessoryPlacement = accessoryToUpdate.AccessoryPlacement;
    					
    // Create a new accessory.
    AccessoryInfo newAccessory = AccessoryInfo.CreateInstance(accessoryPart, isMandatory, quantity, accessoryPlacement);
    					
    // Update it in collection.
    part.Accessories[1] = newAccessory;
    					
    // Save changes and close.
    part.Save();
    part.Close();
    
    api.Close();
    See Also