public void Create(string name) { IAutomationHook hook = null; try { hook = (IAutomationHook)Marshal.GetActiveObject("AlibreX.AutomationHook"); } catch (Exception e) { throw new Exception("Failed to connect to Alibre Design. Is it running?", e); } IADRoot root = (IADRoot)hook.Root; IADAssemblySession assembly = root.CreateEmptyAssembly(name); CreateParameters(assembly, name + "_Parameters"); if (cam.CamPair) { CreateCAM(assembly, name + "_CAM1", false); CreateCAM(assembly, name + "_CAM2", true); } else { CreateCAM(assembly, name + "_CAM", false); } CreateBase(assembly, name + "_BASE"); CreateEccentric(assembly, name + "_ECCENTRIC"); //object path = @"c:\temp\ad"; //assembly.SaveAs(ref path, name); //assembly.Close(); }
//This function gets the automation hook for the running instance of Alibre. //If there is any Assembly Session open, then the 'Insert part and Save Assembly' button gets enabled. //If there is no Assembly Session open, this button remains disabled. private static void frmPartInsert_Load() { try { hook = (IAutomationHook)Marshal.GetActiveObject("AlibreX.AutomationHook"); //Gets the automation hook for the running instance of Alibre rootObj = (IADRoot)hook.Root; insertEnabled = true; } catch { Console.WriteLine("Launch Alibre Design and restart this application"); insertEnabled = false; } }