// Initialize API
HpdApi api = HpdApi.GetInstance();
api.Init();
// Open a project and a workdesk.
Project project = api.OpenProject(@"d:\Harness proD 2.9\Projects\Demo\Demo.hxproj");
Variant variant = project.GetVariants()[0];
variant.Open(false, false);
Designer designer = variant.GetWorkdesks().FirstOrDefault(w => w.Name == "Workdesk_1");
designer.Open(false, false);
// Create a constraint between two connectors and a part.
IOccPart part = designer.GetAllOccurrences<IOccPart>().FirstOrDefault(p => p. Name == "Part_1");
IEnumerable<IOccConnector> conectors = designer.GetAllOccurrences<IOccConnector>(c => c.Name == "cn_00001" || c.Name == "cn_00002");
IEnumerable<IOccConstraint> css = designer.CreateConstraints(part, conectors);
// Save changes and close documents.
designer.Save();
designer.Close();
variant.Close();
project.Close();
api.Close();