// Init API
HpdApi api = HpdApi.GetInstance();
// Open project and variant and document.
Project project = api.OpenProject(@"d:\MyProject.hxproj");
Variant variant = project.GetVariants()[0];
Designer designer = variant.GetWorkdesks().FirstOrDefault(w => w.Name == "Workdesk_2");
designer.Open(false, false);
// Obtain the occurrence.
ILibraryOccurrence connector = designer.GetAllOccurrences().OfType<ILibraryOccurrence>().FirstOrDefault(o => o.Name == "cn_00002");
if (connector == null)
{
// Resolve this issue.
}
// Get all available manufacturers and their part numbers.
IEnumerable<LibraryPartNumber> manufacturers = connector.LibraryPart.PartNumbers.Where(p => p.Type == ApiPartNumberType.Manufacturer);
// Find the desired manufacturer.
LibraryPartNumber desiredManufacturer = manufacturers?.FirstOrDefault(m => m.Company == "PXC");
if (desiredManufacturer == null)
{
// Resolve this issue.
}
// Set the desired manufacturer on the current occurrence.
connector.Manufacturer = desiredManufacturer;
// Save changes and close documents.
designer.Save();
designer.Close();
project.Close();