コード例 #1
0
ファイル: McMasterImporter.cs プロジェクト: Marcushawley/MAFI
        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");
        }
コード例 #2
0
        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()
        }
コード例 #3
0
        /// <summary>Import STEP file</summary>
        ///
        /// <returns>Imported part or assembly document</returns>
        private Document DoImport(bool ImportAASP = false, bool AssociativeImport = false, int ImportAASPIndex = 0)
        {
            TranslatorData oTranslatorData = new TranslatorData(addinGUID: "{90AF7F40-0C01-11D5-8E83-0010B541CD80}", fullFileName: Filename, app: _application);

            NameValueMap op = oTranslatorData.oOptions;

            op.Value["SaveComponentDuringLoad"] = SaveDuringLoad;
            op.Value["SaveLocationIndex"]       = 1; //0 would import to <Project Workspace>/Imported Components. 1 is a custom save location.
            op.Value["ComponentDestFolder"]     = SaveLocation == ""? System.IO.Path.GetDirectoryName(Filename) : SaveLocation;
            op.Value["AddFilenamePrefix"]       = FilenamePrefix != "";
            op.Value["AddFilenameSuffix"]       = FilenameSuffix != "";
            op.Value["FilenamePrefix"]          = FilenamePrefix;
            op.Value["FilenameSuffix"]          = FilenameSuffix;
            op.Value["EmbedInDocument"]         = EmbedTranslationReport;
            op.Value["SaveToDisk"]                 = SaveTranslationReport;
            op.Value["ImportSolid"]                = ImportSolids;
            op.Value["ImportSurface"]              = ImportSurfaces;
            op.Value["ImportWire"]                 = ImportWires;
            op.Value["ImportPoint"]                = ImportPoints;
            op.Value["ImportMeshes"]               = ImportMeshes;
            op.Value["ImportGraphicalPMI"]         = ImportGraphicalPMI;
            op.Value["ImportValidationProperties"] = false;               //This made Inventor crash when I set it to true.
            op.Value["CreateIFO"]                 = false;                //I don't know what this is.
            op.Value["ImportAASP"]                = ImportAASP;           //Import assembly as single part
            op.Value["ImportAASPIndex"]           = ImportAASPIndex;      //Assembly Options - Structure: 0 = Multi-Body Part, 1 = Composite Part
            op.Value["CreateSurfIndex"]           = SurfaceType - 108801; //Convert ImportedSurfaceOrganizationTypeEnum into the integer values expected by the STEP importer
            op.Value["ImportUnit"]                = (int)Units - 110080;  //Convert ImportUnitsTypeEnum to the integer values expected by the STEP importer
            op.Value["CheckDuringLoad"]           = CheckDuringLoad;
            op.Value["AutoStitchAndPromote"]      = AutoStitchAndPromote;
            op.Value["AdvanceHealing"]            = AdvancedHealing;
            op.Value["EdgeSplitAndMergeDisabled"] = !EdgeSplitAndMerge;
            op.Value["FaceSplitAndMergeDisabled"] = !FaceSplitAndMerge;
            op.Value["AssociativeImport"]         = AssociativeImport;
            op.Value["Selective Import"]          = false; //I don't know if selective import works through the API.

            //Deprecated STEP Import Options:
            //op.Value["SaveAssemSeperateFolder"] = false; //Determines whether top-level assembly is saved in a separate folder
            //op.Value["AssemDestFolder"] = ""; //Separate location where top-level assembly will be saved
            //op.Value["GroupName"] = "";
            //op.Value["GroupNameIndex"] = 0;
            //op.Value["ExplodeMSB2Assm"] = false; //explode multiple solid bodies to assembly
            //op.Value["CEGroupLevel"] = 1; //Construction environment group level
            //op.Value["CEPrefixCk"] = false;
            //op.Value["CEPrefixString"] = "";

            TranslatorAddIn oTranslatorAddIn = (TranslatorAddIn)oTranslatorData.oAppAddIn;

            oTranslatorAddIn.Open(oTranslatorData.oDataMedium, oTranslatorData.oContext, oTranslatorData.oOptions, out object oNewDoc);

            Document newDoc = (Document)oNewDoc;

            if (DisplayWhenDone && !AssociativeImport)
            {
                newDoc.Views.Add();
            }                                                                  //Display the document

            if (AssociativeImport && !DisplayWhenDone)
            {
                newDoc.Views[1].Close();
            }                                                                       //Document is displayed by default when imported as a reference

            return((Document)oNewDoc);
        }