コード例 #1
0
ファイル: DwgExporter.cs プロジェクト: nannerdw/InventorShims
        ///<summary>Export to DWG file with the specified full file path.</summary>
        public void Export(string OutputFile)
        {
            TranslatorData oTranslatorData = new TranslatorData(addinGUID: "{C24E3AC2-122E-11D5-8E91-0010B541CD80}", fullFileName: OutputFile, doc: this.Document);

            oTranslatorData.oOptions.Value["Export_Acad_IniFile"] = ConfigurationFile;

            //Create output directory if it does not exist
            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(OutputFile));

            TranslatorAddIn oTranslatorAddIn = (TranslatorAddIn)oTranslatorData.oAppAddIn;

            oTranslatorAddIn.SaveCopyAs(this.Document, oTranslatorData.oContext, oTranslatorData.oOptions, oTranslatorData.oDataMedium);
        }
コード例 #2
0
        ///<summary>Export to STP file with the specified full file path.</summary>
        public void Export(string OutputFile)
        {
            TranslatorData oTranslatorData = new TranslatorData(addinGUID: "{90AF7F40-0C01-11D5-8E83-0010B541CD80}", fullFileName: OutputFile, doc: _document);

            NameValueMap op = oTranslatorData.oOptions;

            op.Value["IncludeSketches"]         = IncludeSketches;
            op.Value["ApplicationProtocolType"] = ApplicationProtocol;
            op.Value["Author"]               = Author;
            op.Value["Organization"]         = Organization;
            op.Value["Authorization"]        = Authorization;
            op.Value["Description"]          = Description;
            op.Value["export_fit_tolerance"] = SplineFitAccuracy;

            TranslatorAddIn oTranslatorAddIn = (TranslatorAddIn)oTranslatorData.oAppAddIn;

            oTranslatorAddIn.SaveCopyAs(this.Document, oTranslatorData.oContext, oTranslatorData.oOptions, oTranslatorData.oDataMedium);
        }
コード例 #3
0
ファイル: StlExporter.cs プロジェクト: nannerdw/InventorShims
        ///<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);
        }
コード例 #4
0
ファイル: PdfExporter.cs プロジェクト: nannerdw/InventorShims
        ///<summary>Export to a single PDF file</summary>
        private void Export(
            string OutputFile,
            PrintRangeEnum SheetRangeType,
            int StartSheet = 0,
            int EndSheet   = 0,
            IEnumerable <Sheet> IncludedSheets  = null,
            IEnumerable <int> IncludedSheetNums = null
            )
        {
            TranslatorData oTranslatorData = new TranslatorData(addinGUID: "{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}", fullFileName: OutputFile, doc: this.Document);

            NameValueMap op = oTranslatorData.oOptions;

            op.Value["All_Color_AS_Black"]  = Convert.ToInt32(AllColorsAsBlack);
            op.Value["Remove_Line_Weights"] = Convert.ToInt32(RemoveLineWeights);
            op.Value["Vector_Resolution"]   = Convert.ToInt32(VectorResolution);
            op.Value["Sheet_Range"]         = SheetRangeType;
            if (StartSheet != 0)
            {
                op.Value["Custom_Begin_Sheet"] = StartSheet;
            }
            if (EndSheet != 0)
            {
                op.Value["Custom_End_Sheet"] = EndSheet;
            }
            //op.Value["Launch_Viewer"] = Convert.ToInt32(OpenWhenDone);  //Does not work.  Workaround is at the bottom of this function.

            Transaction tempTransaction = null;

            //This is wrapped in a try/catch block to ensure the transaction gets aborted
            try
            {
                Inventor.Application app = (Inventor.Application) this.Document.Parent;

                DrawingDocument dwgDoc = (DrawingDocument)this.Document;

                tempTransaction = app.TransactionManager.StartTransaction((Inventor._Document) this.Document, "Temporary Transaction");

                if (PrintExcludedSheets)
                {
                    //Temporarily include all sheets.
                    List <Sheet> excludedSheets = dwgDoc.Sheets.OfType <Sheet>().Where(x => x.ExcludeFromPrinting).ToList();

                    if (excludedSheets.Count > 0)
                    {
                        excludedSheets.ForEach(x => x.ExcludeFromPrinting = false);
                    }
                }

                //Temporarily exclude sheets that were not passed in to this function.
                if (IncludedSheets != null)
                {
                    List <Sheet> temporarilyExcludedSheets = dwgDoc.Sheets.OfType <Sheet>().Except(IncludedSheets).ToList();

                    temporarilyExcludedSheets.ForEach(x => x.ExcludeFromPrinting = true);
                }

                //Temporarily exclude sheet numbers that were not passed in to this function.
                if (IncludedSheetNums != null)
                {
                    List <Sheet> includedSheets = new List <Sheet>();

                    for (int i = 1; i <= dwgDoc.Sheets.Count; i++)
                    {
                        if (IncludedSheetNums.Contains(i))
                        {
                            includedSheets.Add(dwgDoc.Sheets[i]);
                        }
                    }

                    List <Sheet> temporarilyExcludedSheets = dwgDoc.Sheets.OfType <Sheet>().Except(includedSheets).ToList();

                    temporarilyExcludedSheets.ForEach(x => x.ExcludeFromPrinting = true);
                }

                //Create output directory if it does not exist
                System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(OutputFile));

                TranslatorAddIn oTranslatorAddIn = (TranslatorAddIn)oTranslatorData.oAppAddIn;

                oTranslatorAddIn.SaveCopyAs(this.Document, oTranslatorData.oContext, oTranslatorData.oOptions, oTranslatorData.oDataMedium);

                if (tempTransaction != null)
                {
                    tempTransaction.Abort();
                }
            }
            catch
            {
                if (tempTransaction != null)
                {
                    tempTransaction.Abort();
                }

                throw;
            }

            //Workaround for the PDF exporter's "Launch_Viewer" option, which does not work.
            if (OpenWhenDone && System.IO.File.Exists(OutputFile))
            {
                //Open pdf file in its default application
                System.Diagnostics.Process.Start(OutputFile);
            }
        }
コード例 #5
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);
        }