This article describes how to get a part type from one item and add it to another item.


Example

static void Main()
{
    SWConnection.Instance.ServerMachineName = "localhost";
    SWConnection.Instance.ServerPort = 1768;
    SWConnection.Instance.LoginName = "admin";
    SWConnection.Instance.Password = "supersecretpassword";
    SWConnection.Instance.Login();
 
    //Get an item to work with. This example item has exactly one part of the type ISSS to be duplicated.

    var item = SWConnection.Instance.Broker.GetItem(SWHandleUtility.ToHandle("x04000000000010BC"));
 
    //Get the first ISSS part of the item
    var partToDuplicate = item.GetParts("ISSS").FirstOrDefault() as IswPart;
 
    //Add a similar part to the item (this does not include part attributes)
    var newPart = item.AddPart(partToDuplicate.swPartType, partToDuplicate.DefObj, partToDuplicate.RefObj);
 
    //If you also want to copy the part attributes you can do so explicitly
    foreach (var attribute in partToDuplicate.Attributes)
    {
        newPart.SetAttributeDataOfType(attribute.AttributeType, attribute.ValueData);
    }
}