The following snippets show two ways to remove Parts using the SystemWeaver API.


Setting Up the Example

            IswLibrary library = SWConnection.Instance.Broker.GetLibrary(SWHandleUtility.ToHandle("x13000000000DEFA0"));

            // Create a component
            string componentSid = "ARAP";
            IswItem component = library.CreateItem(componentSid, "Component");

            // Create two interfaces
            string interfaceSid = "ARSI";
            IswItem interfaceItem1 = library.CreateItem(interfaceSid, "Interface1");
            IswItem interfaceItem2 = library.CreateItem(interfaceSid, "Interface2");

            // Add the interfaces as parts to the component. This is done twice to illustrate two different ways of removing a part.
            string partSid = "ARRP";
            component.AddPart(partSid, interfaceItem1);
            component.AddPart(partSid, interfaceItem1);
            component.AddPart(partSid, interfaceItem2);
            component.AddPart(partSid, interfaceItem2);


Option 1

Remove first part of type "ARRP" found for intefaceItem1.

            IswPart partToRemove1 = component.FindDefObjPart(partSid, interfaceItem1);

            // If any part found.Try to remove it.
            if( partToRemove1 != null)
            {
                // Check if you have write access for the part. 
                // This can also be done on the Item that owns the part since their access rights are equivalent.  
                if (partToRemove1.ObjectAccess.Contains(SWAccessCodes.Write))
                {
                    // Remove the part. The part's DefObj is left in the database.
                    partToRemove1.Remove();
                }
            }


Option 2

Remove all parts of type "ARRP" found for intefaceItem2.

            foreach (IswPart partToRemove2 in component.GetParts(partSid))
            {                
                if (partToRemove2.DefObj.Equals(interfaceItem2))
                {
                    // Check if you have write access for the part. 
                    // This can also be done on the Item that owns the part since their access rights are equivalent.
                    if (partToRemove2.ObjectAccess.Contains(SWAccessCodes.Write))
                    {
                        // Remove the part. The part's DefObj is left in the database.
                        partToRemove2.Remove();
                    }
                }
            }