protected override void OnExecute(NameValueMap context) { try { var assembly = AddIn.GetAssemblyDocument(); if (assembly == null) return; var subassemblies = assembly.Subassemblies(); if (subassemblies.Count == 0) { AddIn.ShowWarningMessageBox( _generateDrawingsWindow.Title, $"Assembly '{assembly.FullFileName}' doesn't contain subassemblies." ); return; } _generateDrawingsWindow.Show(subassemblies); } catch (Exception ex) { ShowWarningMessageBox(ex); } }
protected override void OnExecute(NameValueMap context) { try { var selectedView = AddIn.GetDrawingView("Select an assembly view"); if (selectedView != null) if (selectedView.ViewType == DrawingViewTypeEnum.kStandardDrawingViewType) { var transaction = AddIn.CreateTransaction(DisplayName); selectedView.AddBaseViewOfParts(drawingDistance: 4); transaction.End(); } else MessageBox.Show( messageBoxText: DisplayName + " can only be used on base views.", caption: DisplayName, button: MessageBoxButton.OK, icon: MessageBoxImage.Information ); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
protected override void OnExecute(NameValueMap context) { try { var assemblyDocument = AddIn.GetAssemblyDocument(); if (assemblyDocument == null) return; var mdfParts = assemblyDocument.MdfParts(); if (mdfParts.Count == 0) { AddIn.ShowWarningMessageBox( caption: _generateDrawingsWindow.Title, messageFormat: "Assembly '{0}' doesn't contain MDF parts." + Environment.NewLine + Environment.NewLine + "A part file name must contain 'MDF' to be recognized as a MDF part.", messageArgs: assemblyDocument.FullFileName ); return; } _generateDrawingsWindow.Show(assemblyDocument.MdfParts()); } catch (Exception ex) { ShowWarningMessageBox(ex); } }
protected override void ButtonDefinition_OnExecute(NameValueMap context) { try { //check to make sure a sketch is active if (InventorApplication.ActiveEditObject is PlanarSketch) { //if same session, combobox definitions will already exist Inventor.Application oAppTest; oAppTest = InventorApplication; string filePath; filePath = "C:\\Projects\\InventorAPI\\InventorAddIns\\SimpleAddInIronPython\\PythonTest.py"; PlanarSketch planarSketch; planarSketch = (PlanarSketch)InventorApplication.ActiveEditObject; ComboBoxDefinition slotWidthComboBoxDefinition; slotWidthComboBoxDefinition = (Inventor.ComboBoxDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:SimpleAddIn:SlotWidthCboBox"]; ComboBoxDefinition slotHeightComboBoxDefinition; slotHeightComboBoxDefinition = (Inventor.ComboBoxDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:SimpleAddIn:SlotHeightCboBox"]; //get the selected width from combo box double slotWidth; slotWidth = slotWidthComboBoxDefinition.ListIndex; //get the selected height from combo box double slotHeight; slotHeight = slotHeightComboBoxDefinition.ListIndex; Engine thisEngine = new Engine(filePath,planarSketch,oAppTest,slotHeight,slotWidth); if (slotWidth > 0 && slotHeight > 0) { bool thisRun; thisRun = thisEngine.Execute(); } else { //valid width/height was not specified MessageBox.Show("Please specify valid slot width and height"); } } else { //no sketch is active, so display an error MessageBox.Show("A sketch must be active for this command"); } } catch(Exception e) { MessageBox.Show(e.ToString()); } }
override protected void ButtonDefinition_OnExecute(NameValueMap context) { try { if (isRunning == false) { //Start Dynamo! DynamoInventor.SetupDynamoPaths(); string inventorContext = "Inventor " + PersistenceManager.InventorApplication.SoftwareVersion.DisplayVersion; //Setup base units. Need to double check what to do. The ui default for me is inches, but API always must take cm. BaseUnit.AreaUnit = AreaUnit.SquareCentimeter; BaseUnit.LengthUnit = LengthUnit.Centimeter; BaseUnit.VolumeUnit = VolumeUnit.CubicCentimeter; //Setup DocumentManager...this is all taken care of on its own. Reference to active application will happen //when first call to binder.InventorApplication happens InventorDynamoModel inventorDynamoModel = InventorDynamoModel.Start(); DynamoViewModel dynamoViewModel = DynamoViewModel.Start( new DynamoViewModel.StartConfiguration() { DynamoModel = inventorDynamoModel }); IntPtr mwHandle = Process.GetCurrentProcess().MainWindowHandle; var dynamoView = new DynamoView(dynamoViewModel); new WindowInteropHelper(dynamoView).Owner = mwHandle; handledCrash = false; dynamoView.Show(); isRunning = true; } else if (isRunning == true) { System.Windows.Forms.MessageBox.Show("Dynamo is already running."); } else { System.Windows.Forms.MessageBox.Show("Something terrible happened."); } } catch(Exception e) { System.Windows.Forms.MessageBox.Show(e.ToString()); } }
protected override void ButtonDefinition_OnExecute(NameValueMap context) { try { //C:\Users\PC\AppData\Roaming\Autodesk\Inventor 2015\Addins\Shaft\ //bin\Debug\ Form_ShaftPparts Form_ShaftDesigner1 = new Form_ShaftPparts(); Form_ShaftDesigner1.Show(); } catch(Exception e) { MessageBox.Show(e.ToString()); } }
protected override void ButtonDefinition_OnExecute(NameValueMap context) { try { //if same session, button definition will already exist ButtonDefinition drawSlotButtonDefinition; drawSlotButtonDefinition = (Inventor.ButtonDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:SimpleAddIn:DrawSlotCmdBtn"]; if (drawSlotButtonDefinition.Enabled == true) drawSlotButtonDefinition.Enabled = false; else drawSlotButtonDefinition.Enabled = true; } catch(Exception e) { MessageBox.Show(e.ToString()); } }
protected override void ButtonDefinition_OnExecute(NameValueMap context) { try { //if same session, combobox definitions will already exist ComboBoxDefinition slotWidthComboBoxDefinition; slotWidthComboBoxDefinition = (Inventor.ComboBoxDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:SimpleAddIn:SlotWidthCboBox"]; ComboBoxDefinition slotHeightComboBoxDefinition; slotHeightComboBoxDefinition = (Inventor.ComboBoxDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:SimpleAddIn:SlotHeightCboBox"]; //add new item to combo boxes slotWidthComboBoxDefinition.AddItem(Convert.ToString(slotWidthComboBoxDefinition.ListCount + 1) + " cm", 0); slotHeightComboBoxDefinition.AddItem(Convert.ToString(slotHeightComboBoxDefinition.ListCount + 1) + " cm", 0); } catch(Exception e) { MessageBox.Show(e.ToString()); } }
public static IEnumerable <T> GetValueAsCollection <T>(this NameValueMap nameValueMap, string index) { if (!nameValueMap.TryGetValueAs(index, out string outString)) { throw new InvalidValueTypeException("Value cannot be used as a collection because it is not a string"); } return(outString .Split(Separators, StringSplitOptions.RemoveEmptyEntries) .Select(item => { if (!dataConverter.TryGetValueFromObjectAs(item, out T outValue)) { throw new InvalidValueTypeException("Value cannot be used as a collection"); } return outValue; }) .ToList()); }
override protected void ButtonDefinition_OnExecute(NameValueMap context) { try { //if same session, combobox definitions will already exist ComboBoxDefinition slotWidthComboBoxDefinition; slotWidthComboBoxDefinition = (Inventor.ComboBoxDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:URDFConverter:SlotWidthCboBox"]; ComboBoxDefinition slotHeightComboBoxDefinition; slotHeightComboBoxDefinition = (Inventor.ComboBoxDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:URDFConverter:SlotHeightCboBox"]; //add new item to combo boxes slotWidthComboBoxDefinition.AddItem(Convert.ToString(slotWidthComboBoxDefinition.ListCount + 1) + " cm", 0); slotHeightComboBoxDefinition.AddItem(Convert.ToString(slotHeightComboBoxDefinition.ListCount + 1) + " cm", 0); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
protected override void ButtonDefinition_OnExecute(NameValueMap context) { //make sure that the current environment is "Part Environment" Inventor.Environment currEnvironment = m_inventorApplication.UserInterfaceManager.ActiveEnvironment; if (currEnvironment.InternalName != "PMxPartEnvironment") { System.Windows.Forms.MessageBox.Show("该命令必须在零件环境中运行!"); return; } //if command was already started, stop it first if (m_commandIsRunning) { StopCommand(); } //start new command StartCommand(); EnableInteraction(); }
private void OnResetCommandBars(ObjectsEnumerator commandBars, NameValueMap context) { try { foreach (CommandBar commandBar in commandBars) { if (commandBar.InternalName == "PMxPartFeatureCmdBar") { _createTopAndLeftProjectedViewsButton.AddTo(commandBar); _createLeftThenThreeTopProjectedViewsButton.AddTo(commandBar); _createPartViewsFromAssemblyButton.AddTo(commandBar); return; } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
void DockableWindowsEvents_OnShow( DockableWindow DockableWindow, EventTimingEnum BeforeOrAfter, NameValueMap Context, out HandlingCodeEnum HandlingCode) { HandlingCode = HandlingCodeEnum.kEventNotHandled; if (DockableWindow == dockableWindow) { OnVisibilityChangedEventArgs arg = new OnVisibilityChangedEventArgs( BeforeOrAfter, true); _form.OnVisibilityChanged(arg); HandlingCode = arg.HandlingCode; } }
private void UserInterfaceEvents_OnResetRibbonInterface(NameValueMap context) { try { UserInterfaceManager userInterfaceManager; userInterfaceManager = m_inventorApplication.UserInterfaceManager; //get the ribbon associated with part document Inventor.Ribbons ribbons; ribbons = userInterfaceManager.Ribbons; Inventor.Ribbon partRibbon; partRibbon = ribbons["Part"]; //get the tabls associated with part ribbon RibbonTabs ribbonTabs; ribbonTabs = partRibbon.RibbonTabs; RibbonTab partSketchRibbonTab; partSketchRibbonTab = ribbonTabs["id_TabSketch"]; //create a new panel with the tab RibbonPanels ribbonPanels; ribbonPanels = partSketchRibbonTab.RibbonPanels; partSketchMasterRibbonPanel = ribbonPanels.Add("MasterModel", "MasterModel:StandardAddInServer:BenjaminBUTTONRibbonPanel", "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "", false); //add controls to the MasterModel panel CommandControls partSketchMasterMoRiPaCtrl; partSketchMasterMoRiPaCtrl = partSketchMasterRibbonPanel.CommandControls; //add the buttons to the ribbon panel CommandControl MasterCommander; MasterCommander = partSketchMasterMoRiPaCtrl.AddButton(ButtON.ButtonDefinition, false, true, "", false); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
private void UserInterfaceEvents_OnResetRibbonInterface(NameValueMap context) { try { UserInterfaceManager userInterfaceManager; userInterfaceManager = m_inventorApplication.UserInterfaceManager; //get the ribbon associated with part document Inventor.Ribbons ribbons; ribbons = userInterfaceManager.Ribbons; Inventor.Ribbon partRibbon; partRibbon = ribbons["Part"]; //get the tabls associated with part ribbon RibbonTabs ribbonTabs; ribbonTabs = partRibbon.RibbonTabs; RibbonTab partSketchRibbonTab; partSketchRibbonTab = ribbonTabs["id_TabTools"]; //create a new panel with the tab RibbonPanels ribbonPanels; ribbonPanels = partSketchRibbonTab.RibbonPanels; m_partSketchSlotRibbonPanel = ribbonPanels.Add("Anisotropy", "Autodesk:Mugen:AnysotropyRibbonPanel", "{cc527b4d-c28d-40fb-a46a-4978db960594}", "", false); //add controls to the slot panel CommandControls partSketchSlotRibbonPanelCtrls; partSketchSlotRibbonPanelCtrls = m_partSketchSlotRibbonPanel.CommandControls; //add the buttons to the ribbon panel CommandControl drawSlotCmdBtnCmdCtrl; drawSlotCmdBtnCmdCtrl = partSketchSlotRibbonPanelCtrls.AddButton(m_addSlotOptionButton.ButtonDefinition, false, true, "", false); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
public void RunWithArguments(Document doc, NameValueMap map) { LogTrace("Processing " + doc.FullFileName); try { using (new HeartBeat()) { string currentDir = System.IO.Directory.GetCurrentDirectory(); string resultDir = System.IO.Path.Combine(currentDir, "result"); var reader = new iLogicFormsReader(doc, resultDir); string json = reader.ToJsonString(); string jsonPath = System.IO.Path.Combine(resultDir, "result.json"); System.IO.File.WriteAllText(jsonPath, json); } } catch (Exception e) { LogError("Processing failed. " + e.ToString()); } }
private void ButtonOnExecute(NameValueMap context) { var document = _application.ActiveDocument; var connection = VaultConnection.GetVaultConnection(_application); if (connection != null) { var assemblyLoader = new AssemblyLoader(); var vaultFunctions = assemblyLoader.LoadLateBindingAssemblies(); vaultFunctions.Initialize(connection); var name = vaultFunctions.GetCustomEntityValue("Class"); if (name != null) { SetInventorProperty(document, "User Defined Properties", "Class", name); MessageBox.Show( string.Format("iProperty 'Class' has been set to '{0}'", name), @"Assign Class"); } } }
private void RunBtnDef_OnExecute(NameValueMap context) { //Do license check here //After installing the Massif.Licensing nuget package, add "using Massif.Licensing;" at the top of this file //Create a license connector Connector licenseConnector = new Connector(); //Get the asset info from the Massif licensing engine Connector.IAssetInfo assetInfo = licenseConnector.GetAssetInfo("cps-jobber"); //Check that license is valid, if not then return if (!assetInfo.LicenseActive) { MessageBox.Show("The addin could not load, as a valid license could not be found. Please ensure that the Massif Desktop App is running, and that you have a valid license, then restart the addin."); return; } MessageBox.Show("The addin runs, which means you have a valid license! Massif achievement, well done!"); }
public void ExportRFA(Document doc, string filePath) { LogTrace("Exporting RFA file."); BIMComponent bimComponent = getBIMComponent(doc); if (bimComponent == null) { LogTrace("Could not export RFA file."); return; } NameValueMap nvm = inventorApplication.TransientObjects.CreateNameValueMap(); string currentDir = System.IO.Directory.GetCurrentDirectory(); var reportFileName = System.IO.Path.Combine(currentDir, "Report.html"); nvm.Add("ReportFileName", reportFileName); bimComponent.ExportBuildingComponentWithOptions(filePath, nvm); LogTrace("Exported RFA file."); }
///<summary>Export to STL file with the specified full file path.</summary> public void Export(string OutputFile) { TranslatorData oTranslatorData = new TranslatorData(addinGUID: "{533E9A98-FC3B-11D4-8E7E-0010B541CD80}", fullFileName: OutputFile, doc: this.Document); NameValueMap op = oTranslatorData.oOptions; op.Value["ExportUnits"] = (int)Units - 110080; //Convert ImportUnitsTypeEnum to the integer values expected by the STL exporter op.Value["Resolution"] = Resolution; op.Value["AllowMoveMeshNode"] = AllowMoveMeshNodes; op.Value["SurfaceDeviation"] = SurfaceDeviation; op.Value["NormalDeviation"] = NormalDeviation; op.Value["MaxEdgeLength"] = MaxEdgeLength; op.Value["AspectRatio"] = MaxAspectRatio; op.Value["ExportFileStructure"] = Convert.ToInt32(OneFilePerPartInstance); op.Value["OutputFileType"] = Convert.ToInt32(!Binary); op.Value["ExportColor"] = ExportColors; TranslatorAddIn oTranslatorAddIn = (TranslatorAddIn)oTranslatorData.oAppAddIn; oTranslatorAddIn.SaveCopyAs(this.Document, oTranslatorData.oContext, oTranslatorData.oOptions, oTranslatorData.oDataMedium); }
protected override void ButtonDefinition_OnExecute(NameValueMap context) { //System.Windows.Forms.Application.Run(m_Break = new BreakOp(Inventor.Document oDoc)); try { Macros.StandardAddInServer.forms.Add(m_spike); PlanarSketch sketch = (PlanarSketch)InventorApplication.ActiveEditObject; if (Macros.StandardAddInServer.activeteForm()) { System.Windows.Forms.Application.Run(m_spike = new InvAddIn.spike(InventorApplication, sketch)); } } catch (Exception) { Macros.StandardAddInServer.forms.Add(m_Offset); if (Macros.StandardAddInServer.activeteForm()) { System.Windows.Forms.Application.Run(m_Offset = new Offset(InventorApplication.ActiveDocument)); } } }
protected override void OnExecute(NameValueMap context) { try { var drawingDocuments = AddIn.Documents.OfType <DrawingDocument>().ToList(); if (drawingDocuments.Count == 0) { ShowWarningMessageBox("There are no drawing documents loaded. " + "Open one or more drawing documents before using this command."); return; } _targetDirectoryPath = ((Document)drawingDocuments.First()).DirectoryPath(); using (var dialog = new System.Windows.Forms.FolderBrowserDialog()) { dialog.Description = "Select a target directory."; dialog.SelectedPath = _targetDirectoryPath; dialog.ShowNewFolderButton = true; if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } _targetDirectoryPath = dialog.SelectedPath + "\\"; } foreach (Document document in drawingDocuments) { document.SaveAsPDF(_targetDirectoryPath + document.DisplayName + ".pdf"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void ProcessArguments(NameValueMap args) { string zipPath; SetStatus("Processing Folder Structure and Zip File Data"); zipPath = (string)args.Value["_1"]; if (string.IsNullOrWhiteSpace(zipPath)) { throw new Exception("INPUT ZIP FILE PARAMETER NOT FOUND"); } if (System.IO.File.Exists(zipPath) == false) { throw new Exception("INPUT ZIP FILE DOES NOT EXIST"); } m_InputsPath = System.IO.Path.Combine( System.IO.Path.GetDirectoryName(zipPath), "INPUTS"); if (System.IO.Directory.Exists(m_InputsPath) == false) { System.IO.Directory.CreateDirectory(m_InputsPath); } m_OutputsPath = System.IO.Path.Combine( System.IO.Path.GetDirectoryName(zipPath), "OUTPUTS"); if (System.IO.Directory.Exists(m_OutputsPath) == false) { System.IO.Directory.CreateDirectory(m_OutputsPath); } System.IO.Compression.ZipFile.ExtractToDirectory( zipPath, m_InputsPath); }
private static void importaFromAutocad(string v) { TranslatorAddIn oDWGTranslator = (TranslatorAddIn)iApp.ApplicationAddIns.ItemById["{C24E3AC2-122E-11D5-8E91-0010B541CD80}"]; DataMedium oDataMedium = iApp.TransientObjects.CreateDataMedium(); oDataMedium.FileName = @"X:\Commesse\Focchi\200000 40L\99 Service\Matrici full\" + v + "_def.dwg"; TranslationContext oTranslationContext = iApp.TransientObjects.CreateTranslationContext(); oTranslationContext.Type = Inventor.IOMechanismEnum.kFileBrowseIOMechanism; PartDocument oDoc = (PartDocument)iApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject); PartComponentDefinition oPartCompDef = oDoc.ComponentDefinition; PlanarSketch oSketchC = oPartCompDef.Sketches.Add(oPartCompDef.WorkPlanes[2], true); oSketchC.Name = "testtttttt"; Sketch oSketch = (Sketch)oPartCompDef.Sketches["testtttttt"]; oSketch.Edit(); oTranslationContext.OpenIntoExisting = oSketch; NameValueMap oOptions = iApp.TransientObjects.CreateNameValueMap(); oOptions.Add("SelectedLayers", "0"); oOptions.Add("InvertLayersSelection", false); oOptions.Add("ConstrainEndPoints", true); object boh; oDWGTranslator.Open(oDataMedium, oTranslationContext, oOptions, out boh); oSketch.ExitEdit(); // RegisterAutoCADDefault() }
//private void TriggerDrawingRules(Document doc) //{ // Parameters parameters = ((DrawingDocument)doc).Parameters; // try // { // dynamic trigger = parameters["iTrigger0"]; // // Just inccrement the trigger value, right now only supporting numeric triggers // trigger.Value++; // LogTrace("Fired trigger for drawing rules"); // } // catch (Exception) // { // LogTrace("No drawing rules to trigger"); // } // } // Export Drawing file to PDF format // In case that the Drawing has more sheets -> it will export PDF with pages // Each PDF page represet one Drawing sheet public void ExportIDWToPDF(Document doc, string exportFileName) { if (doc == null) { LogError("Document is null!"); return; } LogTrace("PDF file full path : " + exportFileName); LogTrace("Create PDF Translator Addin"); TranslatorAddIn PDFAddIn = (TranslatorAddIn)inventorApplication.ApplicationAddIns.ItemById["{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}"]; if (PDFAddIn == null) { LogError("Error: PDF Translator Addin is null!"); return; } TranslationContext context = inventorApplication.TransientObjects.CreateTranslationContext(); NameValueMap options = inventorApplication.TransientObjects.CreateNameValueMap(); if (PDFAddIn.HasSaveCopyAsOptions[doc, context, options]) { context.Type = IOMechanismEnum.kFileBrowseIOMechanism; DataMedium dataMedium = inventorApplication.TransientObjects.CreateDataMedium(); options.Value["Sheet_Range"] = PrintRangeEnum.kPrintAllSheets; options.Value["Vector_Resolution"] = 300; options.Value["All_Color_AS_Black"] = false; options.Value["Sheets"] = GetSheetOptions(doc); dataMedium.FileName = exportFileName; LogTrace("Processing PDF export ..."); PDFAddIn.SaveCopyAs(doc, context, options, dataMedium); LogTrace("Finish processing PDF export ..."); } }
private void DockableWindowsEvents_OnShow(DockableWindow DockableWindow, EventTimingEnum BeforeOrAfter, NameValueMap Context, out HandlingCodeEnum HandlingCode) { if (DockableWindow == _myVaultBrowser && BeforeOrAfter == EventTimingEnum.kBefore) { if (_vaultAddin.Activated) { var doc = _inventorApplication.ActiveDocument; if (doc != null && _hwndDic.ContainsKey(doc)) { UpdateMyVaultBrowser(doc); } _userInputEvents.OnLinearMarkingMenu += UserInputEvents_OnLinearMarkingMenu; } else { UnSubscribeEvents(); } } HandlingCode = HandlingCodeEnum.kEventNotHandled; }
/// <summary> /// Write info on input data to log. /// </summary> private static void LogInputData(Document doc, NameValueMap map) { // dump doc name var traceInfo = new StringBuilder("RunWithArguments called with '"); traceInfo.Append(doc.DisplayName); traceInfo.Append("'. Parameters: "); // dump input parameters // values in map are keyed on _1, _2, etc string[] parameterValues = Enumerable .Range(1, map.Count) .Select(i => (string)map.Value["_" + i]) .ToArray(); string values = string.Join(", ", parameterValues); traceInfo.Append(values); traceInfo.Append("."); LogTrace(traceInfo.ToString()); }
override protected void ButtonDefinition_OnExecute(NameValueMap context) { try { //if same session, button definition will already exist ButtonDefinition drawSlotButtonDefinition; drawSlotButtonDefinition = (Inventor.ButtonDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:URDFConverter:DrawSlotCmdBtn"]; if (drawSlotButtonDefinition.Enabled == true) { drawSlotButtonDefinition.Enabled = false; } else { drawSlotButtonDefinition.Enabled = true; } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
public void Open(DataMedium SourceData, TranslationContext Context, NameValueMap Options, ref object TargetObject) { InvAddIn.InventorSol S = new InvAddIn.InventorSol(); using (var reader = new Pdf3DReaderService()) { List <Element3D> allElements = null; List <string> Olist = new List <string>(); reader.ReadPdf3D(SourceData.FileName, out allElements); S.Draw3D((Part)allElements[0], "test"); } //// InvAddIn.InventorSol.Start(Pdf_File); //InvAddIn.InventorSol S = new InvAddIn.InventorSol(); //S.Start(SourceData.FileName); ////InvAddIn.InventorSol.StandartTest(); }
///<summary>Initializes a new instance of <see cref="TranslatorData"/></summary> internal TranslatorData(string addinGUID, string fullFileName, Document doc = null, Inventor.Application app = null) { if (app == null) { app = (Application)doc.Parent; } oAppAddIn = app.ApplicationAddIns.ItemById[addinGUID]; TransientObjects oTo = app.TransientObjects; if (oAppAddIn is TranslatorAddIn) { oContext = oTo.CreateTranslationContext(); oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism; oDataMedium = oTo.CreateDataMedium(); oDataMedium.FileName = fullFileName; } oOptions = oTo.CreateNameValueMap(); }
protected override void ButtonDefinition_OnExecute(NameValueMap context) { try { PartDocument wholeDocument = Button.InventorApplication.ActiveDocument as PartDocument; var transGeo = Button.InventorApplication.TransientGeometry; if (IsHelp) { MessageBox.Show("-Nur eine Ebenen benutzen\r\n" + "-2D Skizze ohne Splines erstellen\r\n" + "-Nur ein Profil pro Skizze nutzen\r\n" + "-Profile nur für Extrusion oder Drehung nutzen\r\n" + "-Für Drehungen ausschließlich die Z-Achse als Rotationsachse nutzen\r\n" + "-Parameter die auch später genutzt werden sollen müssen unter Verwalten => Parameter als Benutzerparameter angelegt werden und als Exportparameter makiert sein"); } else { Sherlock sherlockReader = new Sherlock(wholeDocument, transGeo); // Displays a SaveFileDialog so the user can save the File SaveFileDialog saveFileDialog = new SaveFileDialog() { Filter = "OpenJSCAD / JavaScript|*.js", Title = "Save as MasterModel", CheckPathExists = true }; if (saveFileDialog.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(saveFileDialog.FileName)) { sherlockReader.ShowShakespeare(saveFileDialog.FileName); } } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
public bool GetTranslatorSaveAsOptions(string TranslatorClsId, ref NameValueMap options) { bool functionReturnValue = false; TranslatorAddIn oTranslator = (TranslatorAddIn)mApp.ApplicationAddIns.ItemById[TranslatorClsId]; if (oTranslator == null) { functionReturnValue = false; return(functionReturnValue); } oTranslator.Activate(); if ((oTranslator.AddInType != ApplicationAddInTypeEnum.kTranslationApplicationAddIn)) { //Not a translator addin... functionReturnValue = false; return(functionReturnValue); } //Gets application translation context and set type to UnspecifiedIOMechanism TranslationContext Context = mApp.TransientObjects.CreateTranslationContext(); Context.Type = IOMechanismEnum.kUnspecifiedIOMechanism; options = mApp.TransientObjects.CreateNameValueMap(); object SourceObject = mApp.ActiveDocument; //Checks whether the translator has 'SaveCopyAs' options try { functionReturnValue = oTranslator.get_HasSaveCopyAsOptions(SourceObject, Context, options); } catch { functionReturnValue = false; } return(functionReturnValue); }
public void RunWithArguments(Document doc, NameValueMap map) { using (new HeartBeat()) { var dir = System.IO.Directory.GetCurrentDirectory(); if (doc == null) { ActivateDefaultProject(dir); doc = inventorApplication.Documents.Open(map.Item["_1"]); } var fullFileName = doc.FullFileName; var path = System.IO.Path.GetFullPath(fullFileName); var fileName = System.IO.Path.GetFileNameWithoutExtension(fullFileName); var drawing = inventorApplication.DesignProjectManager.ResolveFile(path, fileName + ".idw"); LogTrace("Looking for drawing: " + fileName + ".idw " + "inside: " + path + " with result: " + drawing); if (drawing == null) { drawing = inventorApplication.DesignProjectManager.ResolveFile(path, fileName + ".dwg"); LogTrace("Looking for drawing: " + fileName + ".dwg " + "inside: " + path + " with result: " + drawing); } if (drawing != null) { LogTrace("Found drawing to export at: " + drawing); var drawingDocument = inventorApplication.Documents.Open(drawing); LogTrace("Drawing opened"); drawingDocument.Update2(true); LogTrace("Drawing updated"); drawingDocument.Save2(true); LogTrace("Drawing saved"); var pdfPath = System.IO.Path.Combine(dir, "Drawing.pdf"); LogTrace("Exporting drawing to: " + pdfPath); ExportIDWToPDF(drawingDocument, pdfPath); //drawingDocument.SaveAs(pdfPath, true); LogTrace("Drawing exported"); } } }
override protected void OnExecute(NameValueMap context) { var transaction = AddIn.CreateTransaction(DisplayName); try { // TODO Add extension method that finds a row based on part number. //var partsLists = DrawingDocument.ActiveSheet.PartsLists; foreach (var drawingView in AddIn.GetDrawingViews("Select a view")) { drawingView.AddTopAndLeftProjectedViews(addDimensions: true, drawingDistance: 0.5); AddPartNameNote(drawingView); } transaction.End(); } catch (Exception ex) { transaction.Abort(); MessageBox.Show(ex.ToString()); } }
protected override void OnExecute(NameValueMap context) { var transaction = AddIn.CreateTransaction(DisplayName); try { foreach (var drawingView in AddIn.GetDrawingViews("Select a view")) { drawingView.AddLeftThenTopProjectedViews( numberOfTopViews: 3, addDimensions: true, drawingDistance: 2.5 ); } transaction.End(); } catch (Exception ex) { transaction.Abort(); MessageBox.Show(ex.ToString()); } }
public void RunWithArguments( Document doc, NameValueMap args) { DateTime start = DateTime.Now; using (CHeartBeat heartBeat = new CHeartBeat()) { try { m_Outputs = new Outputs.COutputs(); m_ServerInstance.CloseAllDocuments(); ProcessArguments(args); LoadInputs(); SetParameters(); ProcessPartModel(); ProcessPartDrawing(); UpdateForge(); m_Outputs.Reference = m_Inputs.Reference; m_Outputs.PartNumber = m_Inputs.PartNumber; m_Outputs.RunDuration = DateTime.Now - start; System.IO.File.WriteAllText( System.IO.Path.Combine(m_OutputsPath, CConstants.OUTPUT_FILE_NAME), JsonConvert.SerializeObject(m_Outputs)); } catch (Exception e) { // TODO: Log This - For Now Just Rethrow throw e; } } }
public bool GetTranslatorOpenOptions(string TranslatorClsId, ref NameValueMap options) { bool functionReturnValue = false; TranslatorAddIn oTranslator = (TranslatorAddIn)mApp.ApplicationAddIns.ItemById[TranslatorClsId]; if (oTranslator == null) { functionReturnValue = false; return(functionReturnValue); } oTranslator.Activate(); if ((oTranslator.AddInType != ApplicationAddInTypeEnum.kTranslationApplicationAddIn)) { //Not a translator addin... functionReturnValue = false; return(functionReturnValue); } DataMedium Medium = mApp.TransientObjects.CreateDataMedium(); Medium.FileName = "C:\\Temp\\File.xxx"; Medium.MediumType = MediumTypeEnum.kFileNameMedium; TranslationContext Context = mApp.TransientObjects.CreateTranslationContext(); options = mApp.TransientObjects.CreateNameValueMap(); try { functionReturnValue = oTranslator.get_HasOpenOptions(Medium, Context, options); } catch { functionReturnValue = false; } return(functionReturnValue); }
protected override void OnExecute(NameValueMap context) { try { var drawingDocuments = AddIn.Documents.OfType<DrawingDocument>().ToList(); if (drawingDocuments.Count == 0) { ShowWarningMessageBox("There are no drawing documents loaded. " + "Open one or more drawing documents before using this command."); return; } _targetDirectoryPath = ((Document)drawingDocuments.First()).DirectoryPath(); using (var dialog = new System.Windows.Forms.FolderBrowserDialog()) { dialog.Description = "Select a target directory."; dialog.SelectedPath = _targetDirectoryPath; dialog.ShowNewFolderButton = true; if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; _targetDirectoryPath = dialog.SelectedPath + "\\"; } foreach (Document document in drawingDocuments) document.SaveAsPDF(_targetDirectoryPath + document.DisplayName + ".pdf"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
protected override void OnExecute(NameValueMap context) { try { var assembly = AddIn.GetAssemblyDocument(); if (assembly == null) return; var sheetMetalParts = assembly.SheetMetalParts(); if (sheetMetalParts.Count == 0) { ShowWarningMessageBox($"Assembly {assembly.FullFileName} doesn't contain any sheet metal parts."); return; } _generateSheetMetalDrawingsWindow.Show(assembly, sheetMetalParts); } catch (Exception ex) { ShowWarningMessageBox(ex); } }
public void WriteSTLFiles(string outputfolder) { Inventor.Application _invApp = Links[0].Application; TranslatorAddIn stptrans = (TranslatorAddIn)_invApp.ApplicationAddIns.ItemById["{533E9A98-FC3B-11D4-8E7E-0010B541CD80}"]; TranslationContext stpcontext = _invApp.TransientObjects.CreateTranslationContext(); NameValueMap stpoptions = _invApp.TransientObjects.CreateNameValueMap(); foreach (Link oAsmComp in Links.Skip(1)) { dynamic test = oAsmComp.ReferencedDocumentDescriptor.ReferencedDocument; if (stptrans.HasSaveCopyAsOptions[test, stpcontext, stpoptions]) { stpoptions.Value["ExportUnits"] = 6; stpoptions.Value["Resolution"] = 2; stpcontext.Type = IOMechanismEnum.kFileBrowseIOMechanism; DataMedium stpdata = _invApp.TransientObjects.CreateDataMedium(); stpdata.FileName = outputfolder + "\\" + oAsmComp.Name + ".stl"; stptrans.SaveCopyAs(test, stpcontext, stpoptions, stpdata); } } }
/// <summary> /// Event handling method for the Reset Ribbon event /// </summary> /// <param name="context"></param> private void UserInterfaceEvents_OnResetRibbonInterface(NameValueMap context) { InitializeUserInterface(); }
protected override void ButtonDefinition_OnExecute(NameValueMap context) { try { //check to make sure a sketch is active if (InventorApplication.ActiveEditObject is PlanarSketch) { //if same session, combobox definitions will already exist ComboBoxDefinition slotWidthComboBoxDefinition; slotWidthComboBoxDefinition = (Inventor.ComboBoxDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:SimpleAddIn:SlotWidthCboBox"]; ComboBoxDefinition slotHeightComboBoxDefinition; slotHeightComboBoxDefinition = (Inventor.ComboBoxDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:SimpleAddIn:SlotHeightCboBox"]; //get the selected width from combo box double slotWidth; slotWidth = slotWidthComboBoxDefinition.ListIndex; //get the selected height from combo box double slotHeight; slotHeight = slotHeightComboBoxDefinition.ListIndex; if (slotWidth > 0 && slotHeight > 0) { //draw the sketch for the slot PlanarSketch planarSketch; planarSketch = (PlanarSketch)InventorApplication.ActiveEditObject; SketchLine[] lines = new SketchLine[2]; SketchArc[] arcs = new SketchArc[2]; TransientGeometry transientGeometry; transientGeometry = InventorApplication.TransientGeometry; //start a transaction so the slot will be within a single undo step Transaction createSlotTransaction; createSlotTransaction = InventorApplication.TransactionManager.StartTransaction(InventorApplication.ActiveDocument, "Create Slot"); //draw the lines and arcs that make up the shape of the slot lines[0] = planarSketch.SketchLines.AddByTwoPoints(transientGeometry.CreatePoint2d(0, 0), transientGeometry.CreatePoint2d(slotWidth, 0)); arcs[0] = planarSketch.SketchArcs.AddByCenterStartEndPoint(transientGeometry.CreatePoint2d(slotWidth, slotHeight / 2.0), lines[0].EndSketchPoint, transientGeometry.CreatePoint2d(slotWidth, slotHeight), true); lines[1] = planarSketch.SketchLines.AddByTwoPoints(arcs[0].EndSketchPoint, transientGeometry.CreatePoint2d(0, slotHeight)); arcs[1] = planarSketch.SketchArcs.AddByCenterStartEndPoint(transientGeometry.CreatePoint2d(0, slotHeight / 2.0), lines[1].EndSketchPoint, lines[0].StartSketchPoint, true); //create the tangent constraints between the lines and arcs planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[0], (SketchEntity)arcs[0], null); planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[1], (SketchEntity)arcs[0], null); planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[1], (SketchEntity)arcs[1], null); planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[0], (SketchEntity)arcs[1], null); //create a parallel constraint between the two lines planarSketch.GeometricConstraints.AddParallel((SketchEntity)lines[0], (SketchEntity)lines[1], true, true); //end the transaction createSlotTransaction.End(); } else { //valid width/height was not specified MessageBox.Show("Please specify valid slot width and height"); } } else { //no sketch is active, so display an error MessageBox.Show("A sketch must be active for this command"); } } catch(Exception e) { MessageBox.Show(e.ToString()); } }
private void UserInterfaceEvents_OnResetRibbonInterface(NameValueMap context) { try { UserInterfaceManager userInterfaceManager; userInterfaceManager = m_inventorApplication.UserInterfaceManager; //get the ribbon associated with part document Inventor.Ribbons ribbons; ribbons = userInterfaceManager.Ribbons; Inventor.Ribbon partRibbon; partRibbon = ribbons["Part"]; //get the tabls associated with part ribbon RibbonTabs ribbonTabs; ribbonTabs = partRibbon.RibbonTabs; RibbonTab partSketchRibbonTab; partSketchRibbonTab = ribbonTabs["id_TabSketch"]; //create a new panel with the tab RibbonPanels ribbonPanels; ribbonPanels = partSketchRibbonTab.RibbonPanels; m_partSketchSlotRibbonPanel = ribbonPanels.Add("Slot", "Autodesk:SimpleAddIn:SlotRibbonPanel", "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "", false); //add controls to the slot panel CommandControls partSketchSlotRibbonPanelCtrls; partSketchSlotRibbonPanelCtrls = m_partSketchSlotRibbonPanel.CommandControls; //add the combo boxes to the ribbon panel CommandControl slotWidthCmdCboBoxCmdCtrl; slotWidthCmdCboBoxCmdCtrl = partSketchSlotRibbonPanelCtrls.AddComboBox(m_slotWidthComboBoxDefinition, "", false); CommandControl slotHeightCmdCboBoxCmdCtrl; slotHeightCmdCboBoxCmdCtrl = partSketchSlotRibbonPanelCtrls.AddComboBox(m_slotHeightComboBoxDefinition, "", false); //add the buttons to the ribbon panel CommandControl drawSlotCmdBtnCmdCtrl; drawSlotCmdBtnCmdCtrl = partSketchSlotRibbonPanelCtrls.AddButton(m_drawSlotButton.ButtonDefinition, false, true, "", false); CommandControl slotOptionCmdBtnCmdCtrl; slotOptionCmdBtnCmdCtrl = partSketchSlotRibbonPanelCtrls.AddButton(m_addSlotOptionButton.ButtonDefinition, false, true, "", false); CommandControl toggleSlotStateCmdBtnCmdCtrl; toggleSlotStateCmdBtnCmdCtrl = partSketchSlotRibbonPanelCtrls.AddButton(m_toggleSlotStateButton.ButtonDefinition, false, true, "", false); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
private void UserInterfaceEvents_OnResetEnvironments(ObjectsEnumerator environments, NameValueMap context) { try { Inventor.Environment environment; for (int environmentCt = 1; environmentCt <= environments.Count; environmentCt++) { environment = (Inventor.Environment)environments[environmentCt]; if (environment.InternalName == "PMxPartSketchEnvironment") { //make this command bar accessible in the panel menu for the 2d sketch environment. environment.PanelBar.CommandBarList.Add(m_inventorApplication.UserInterfaceManager.CommandBars["Autodesk:SimpleAddIn:SlotToolbar"]); return; } } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
private void UserInterfaceEvents_OnResetCommandBars(ObjectsEnumerator commandBars, NameValueMap context) { try { CommandBar commandBar; for (int commandBarCt = 1; commandBarCt <= commandBars.Count; commandBarCt++) { commandBar = (Inventor.CommandBar)commandBars[commandBarCt]; if (commandBar.InternalName == "Autodesk:SimpleAddIn:SlotToolbar") { //add comboboxes to toolbar commandBar.Controls.AddComboBox(m_slotWidthComboBoxDefinition, 0); commandBar.Controls.AddComboBox(m_slotHeightComboBoxDefinition, 0); //add buttons to toolbar commandBar.Controls.AddButton(m_addSlotOptionButton.ButtonDefinition, 0); commandBar.Controls.AddButton(m_drawSlotButton.ButtonDefinition, 0); commandBar.Controls.AddButton(m_toggleSlotStateButton.ButtonDefinition, 0); return; } } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
protected abstract void OnExecute(NameValueMap context);
void m_ApplicationEvents_OnOpenDocument(_Document DocumentObject, string FullDocumentName, EventTimingEnum BeforeOrAfter, NameValueMap Context, out HandlingCodeEnum HandlingCode) { System.Windows.Forms.MessageBox.Show("OnOpenDocument fires!"); HandlingCode = HandlingCodeEnum.kEventHandled; }
private void m_uiEvents_OnResetRibbonInterface(NameValueMap Context) { AddToUserInterface(); }
private void UserInterfaceEvents_OnResetEnvironments(ObjectsEnumerator environments, NameValueMap context) { //TODO: Fix this try { Inventor.Environment environment; for (int i = 1; i <= environments.Count; i++) { environment = (Inventor.Environment)environments[i]; if (environment.InternalName == "AMxAssemblyEnvironment") { environment.PanelBar.CommandBarList.Add(inventorApplication.UserInterfaceManager.CommandBars[commandBarInternalName]); } } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
private void UserInterfaceEvents_OnResetCommandBars(ObjectsEnumerator commandBars, NameValueMap context) { try { CommandBar commandBar; for (int commandBarCt = 1; commandBarCt <= commandBars.Count; commandBarCt++) { commandBar = (Inventor.CommandBar)commandBars[commandBarCt]; if (commandBar.InternalName == commandBarInternalName) { commandBar.Controls.AddButton(dynamoAddinButton.ButtonDefinition, 0); return; } } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
/// <summary> /// Event handling method for the Reset Ribbon event /// </summary> /// <param name="Context"></param> private void UserInterfaceEvents_OnResetRibbonInterface(NameValueMap Context) { CreateRectangleRibbonPanel(); }
void appEvents_OnDeactivateDocument(_Document documentObject, EventTimingEnum beforeOrAfter, NameValueMap context, out HandlingCodeEnum handlingCode) { handlingCode = HandlingCodeEnum.kEventNotHandled; if (beforeOrAfter == EventTimingEnum.kBefore) { //I think it is probably not necessary to register these events as the registration will happen on its own in InventorServices. //PersistenceManager.ResetOnDocumentDeactivate(); } }
private void SlotWidthComboBox_OnSelect(NameValueMap context) { m_slotWidthComboBoxDefinition.ToolTipText = m_slotWidthComboBoxDefinition.Text; m_slotWidthComboBoxDefinition.DescriptionText = "Slot width: " + m_slotWidthComboBoxDefinition.Text; }
private void UserInterfaceEvents_OnResetRibbonInterface(NameValueMap context) { //TODO: Fix this try { //get the ribbon associated with part document Inventor.Ribbons ribbons = userInterfaceManager.Ribbons; Inventor.Ribbon assemblyRibbon = ribbons["Assembly"]; //get the tabls associated with part ribbon RibbonTabs ribbonTabs = assemblyRibbon.RibbonTabs; RibbonTab assemblyRibbonTab = ribbonTabs["id_Assembly"]; //create a new panel with the tab RibbonPanels ribbonPanels = assemblyRibbonTab.RibbonPanels; assemblyRibbonPanel = ribbonPanels.Add(ribbonPanelDisplayName, ribbonPanelInternalName, "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "", false); CommandControls assemblyRibbonPanelCtrls = assemblyRibbonPanel.CommandControls; CommandControl copyUtilCmdBtnCmdCtrl = assemblyRibbonPanelCtrls.AddButton(dynamoAddinButton.ButtonDefinition, true, true, "", false); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
private void ButtonDefinition_OnExecute(NameValueMap Context) { MessageBox.Show("Hello, Inventor!"); }
void appEvents_OnActivateDocument(_Document documentObject, EventTimingEnum beforeOrAfter, NameValueMap context, out HandlingCodeEnum handlingCode) { handlingCode = HandlingCodeEnum.kEventNotHandled; if (beforeOrAfter == EventTimingEnum.kAfter) { //PersistenceManager.ResetOnDocumentActivate(documentObject); } }
protected abstract void ButtonDefinition_OnExecute(NameValueMap context);
private void RectangleConfigButtonOnExecute(NameValueMap context) { invApplication.CommandManager.StopActiveCommand(); this.ButtonPressed = true; CommandIsRunning = true; IButtonDialogAdapter buttonDialogAdapter = new ClientDialogAdapter(); buttonDialogAdapter.LaunchConfigDialog(); }
private void m_sampleButton1_OnExecute(NameValueMap Context) { try { string userName; string userId = WebServicesUtils.GetUserId(out userName); //replace your App id here... //contact [email protected] for the App Id string appId = @"<your App id>"; bool isValid = verifyEntitlement(appId, userId); // Get the auth token. if (isValid) { System.Windows.Forms.MessageBox.Show("User is entitled to use the App"); } else { System.Windows.Forms.MessageBox.Show("User do not have entitlement to use the App"); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }