static I() { app = Macros.StandardAddInServer.m_inventorApplication; tg = app.TransientGeometry; objs = app.TransientObjects; nvm = objs.CreateNameValueMap(); nvmDrw = objs.CreateNameValueMap(); nvm.Add("SkipAllUnresolvedFiles", true); nvmDrw.Add("SkipAllUnresolvedFiles", true); nvmDrw.Add("DeferUpdates", true); }
public string Translate(string substitutePathVal) { string strFilePath = substitutePathVal.Substring(4); string strFileName = strFilePath.Substring(strFilePath.Length - int.Parse(substitutePathVal.Substring(0, 4), System.Globalization.NumberStyles.HexNumber)); strFileName = strFileName.Substring(0, strFileName.Length - 5); System.Diagnostics.Debug.WriteLine(strFileName + "///" + strFilePath); ApplicationAddIns oAddIns = _stAddIn.m_invApp.ApplicationAddIns; TranslatorAddIn oTransAddIn = (TranslatorAddIn)oAddIns.ItemById[translatorID]; oTransAddIn.Activate(); TransientObjects transObj = _stAddIn.m_invApp.TransientObjects; DataMedium file = transObj.CreateDataMedium(); file.FileName = strFilePath; TranslationContext context = transObj.CreateTranslationContext(); context.Type = IOMechanismEnum.kFileBrowseIOMechanism; NameValueMap options = transObj.CreateNameValueMap(); bool oHasOpt = oTransAddIn.HasOpenOptions[file, context, options]; oTransAddIn.Open(file, context, options, out object oDoc); Document doc = (Document)oDoc; _stAddIn.m_invApp.SilentOperation = true; string savingDirectory = Properties.Settings.Default.projectFolder; if (savingDirectory == "") { savingDirectory = _stAddIn.m_invApp.DesignProjectManager .ActiveDesignProject.WorkspacePath + "\\MCMASTER_REPOSITORY\\"; } doc.SaveAs(savingDirectory + strFileName + ".ipt", false); if (System.IO.File.Exists(strFilePath)) { System.IO.File.Delete(strFilePath); } _stAddIn.m_invApp.SilentOperation = false; doc.Close(); return(savingDirectory + strFileName + ".ipt"); }
///<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(); }