// 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 suppliers and their part numbers.
IEnumerable<LibraryPartNumber> suppliers = connector.LibraryPart.PartNumbers.Where(p => p.Type == ApiPartNumberType.Supplier);
// Find the desired supplier.
LibraryPartNumber desiredSupplier = suppliers?.FirstOrDefault(m => m.Company == "ESS");
if (desiredSupplier == null)
{
// Resolve this issue.
}
// Set the desired supplier on the current occurrence.
connector.Supplier = desiredSupplier;
// Save changes and close documents.
designer.Save();
designer.Close();
project.Close();