Пример #1
0
 // private void GetNewDrawingDocument(out DrawingDocument oDoc, out Sheet oSheet)
 private void GetNewDrawingDocument(out DrawingDocument oDoc)
 {
     //new drawing document.
     oDoc = mApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,
                               mApp.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject, SystemOfMeasureEnum.kDefaultSystemOfMeasure,
                                                                DraftingStandardEnum.kDefault_DraftingStandard, null), false) as DrawingDocument;
 }
        public static bool saveDwg(string pathToSave, DrawingDocument oDoc)
        {
            TranslatorAddIn DWGAddIn = (TranslatorAddIn)iApp.ApplicationAddIns.ItemById["{C24E3AC2-122E-11D5-8E91-0010B541CD80}"];

            TranslationContext oContext = iApp.TransientObjects.CreateTranslationContext();

            oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism;

            NameValueMap oOptions = iApp.TransientObjects.CreateNameValueMap();

            DataMedium oDataMedium = iApp.TransientObjects.CreateDataMedium();

            if (DWGAddIn.HasSaveCopyAsOptions[oDoc, oContext, oOptions])
            {
                string strIniFile = "C:\\Users\\edgesuser\\Desktop\\DWG-DXF\\test.ini";
                oOptions.Value["Export_Acad_IniFile"] = strIniFile;
                oOptions.Value["Sheet_Range"]         = PrintRangeEnum.kPrintAllSheets;
            }

            string[] oldName = System.Text.RegularExpressions.Regex.Split(oDoc.DisplayName, "\\.");


            oDataMedium.FileName = "C:\\Users\\edgesuser\\Desktop\\DWG-DXF\\" + oldName[0] + ".dwg";


            DWGAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium);

            return(true);
        }
Пример #3
0
 /// <summary>
 /// Returns an IEnumerable{Document} of referencing documents in a DrawingDocument object.
 /// </summary>
 /// <param name="document"></param>
 /// <returns></returns>
 public static IEnumerable <Document> EnumerateReferencingDocuments(this DrawingDocument document)
 {
     foreach (Document doc in document.ReferencingDocuments)
     {
         yield return(doc);
     }
 }
        // ! Converte IDW to DWG
        public static void saveAllAsDwg(string path)
        {
            // ! Istanza inventor
            getIstance();

            // ! Tutti gli ipt dentro la folder
            // ? oDoc = (PartDocument) iApp.ActiveDocument;
            string[] listFiles = System.IO.Directory.GetFiles(@path, "*.idw");

            int counter = 0;

            // ! Ciclo la lista ipt dentro la folder
            foreach (string file in listFiles)
            {
                counter++;

                if (System.IO.Path.GetExtension(file) == ".idw")
                {
                    // ! Apro il documento
                    DrawingDocument oDoc = (DrawingDocument)iApp.Documents.Open(@file);

                    bool dxfStatus = saveDwg(path, oDoc);

                    if (!dxfStatus)
                    {
                        Console.WriteLine("dasdsadsdas");
                    }

                    oDoc.Close(true);
                }
            }
        }
Пример #5
0
        public bool InitCATIADrawing(bool bNewDrawing, string strDarwins)
        {
            if (bNewDrawing)
            {
                //初始化
                docCATIA    = CATIA.Documents;
                oDrawingDoc = (DrawingDocument)docCATIA.Add("Drawing");
            }
            else
            {
                if (strDarwins.Trim() == "")
                {
                    oDrawingDoc = (DrawingDocument)CATIA.ActiveDocument;
                    if (oDrawingDoc == null)
                    {
                        docCATIA    = CATIA.Documents;
                        oDrawingDoc = (DrawingDocument)docCATIA.Add("Drawing");
                    }
                }
                else
                {
                    if (System.IO.File.Exists(strDarwins)) //有文件
                    {
                        oDrawingDoc = (DrawingDocument)CATIA.Documents.Open(strDarwins);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #6
0
 internal CDrawingDocument(
     DrawingDocument document,
     InventorServer server)
 {
     m_Document             = document;
     m_InventorServerObject = server;
 }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Deletes all graphics created by ClientGraphicsManager
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        public static void DeleteManagerGraphics()
        {
            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            Document document = InvApp.ActiveDocument;

            AdnClientGraphicsManager clientGraphicsMng = new AdnClientGraphicsManager(
                InvApp,
                AdnInventorUtilities.AddInGuid);

            switch (document.DocumentType)
            {
            case DocumentTypeEnum.kAssemblyDocumentObject:
            case DocumentTypeEnum.kPartDocumentObject:

                clientGraphicsMng.DeleteGraphics(document, true);
                break;

            case DocumentTypeEnum.kDrawingDocumentObject:

                DrawingDocument drawing = document as DrawingDocument;
                clientGraphicsMng.DeleteGraphics(drawing.ActiveSheet, true);
                break;

            default:
                break;
            }

            clientGraphicsMng.UpdateView();
        }
        //=============================================================================
        public DrawingDocument CreateNewDocument()
        {
            DrawingDocument newDocument = null;

            if (m_DocumentTemplate != null)
            {
                //newDocument = Utils.DeepClone<DrawingDocument>(m_DocumentTemplate);
                newDocument = m_DocumentTemplate.Clone() as DrawingDocument;
                newDocument.DisplayDialog = this;

                // Make new DrawingSheet.GUID for all sheets in the template.
                if (newDocument != null && newDocument.Sheets != null)
                {
                    foreach (DrawingSheet sheet in newDocument.Sheets)
                    {
                        if (sheet == null)
                        {
                            continue;
                        }

                        sheet.CreateNewGUID();
                    }
                }
            }

            return(newDocument);
        }
Пример #9
0
        /// <summary>
        /// Performs the auto-breaking
        /// </summary>
        public void AutoBreak()
        {
            DrawingDocument drawing = invInstance.ActiveDocument as DrawingDocument;
            DrawingView     biggest = getBiggest(drawing.ActiveSheet);

            //if no usable view or view is too small to be broken
            if ((biggest == null) || (!canBeBroken(biggest, isHorizontal(biggest))))
            {
                MessageBox.Show("There are no usable views!", "Cannot apply auto-break");
                return;
            }
            if (biggest.BreakOperations.Count > 0)
            {
                MessageBox.Show("There already is a break operation applied!", "Cannot apply auto-break");
                return;
            }

            Point2d start;
            Point2d end;

            if (isHorizontal(biggest))
            {
                horizontalPoints(biggest, (int)settings.Range, out start, out end);
            }
            else
            {
                verticalPoints(biggest, (int)settings.Range, out start, out end);
            }

            biggest.BreakOperations.Add(boolBreakOrientationConvert(isHorizontal(biggest)), start, end, intToBreakStyleConverter(settings.Style), 5, settings.Gap, settings.Symbols, true);
        }
Пример #10
0
 public SheetParameters(ComponentDefinition cdef, DrawingDocument drawDoc)
 {
     Model       = cdef.Document as _Document;
     DrawDoc     = drawDoc;
     TitleBlocks = DrawDoc.TitleBlockDefinitions;
     TitleBlock  = null;
 }
Пример #11
0
        /// <summary>
        ///  creation of a parts list. The parts list is placed at the
        ///  top right corner of the border if one exists, else it is placed
        ///  at the top right corner of the sheet.
        /// To run this sample, have a drawing document open.
        /// The active sheet in the drawing should have at least
        /// one drawing view and the first drawing view on the sheet
        /// should not be a draft view.
        /// </summary>
        /// <remarks></remarks>

        public void CreatePartsList()
        {
            // Set a reference to the drawing document.
            // This assumes a drawing document is active.
            DrawingDocument oDrawDoc = (DrawingDocument)_InvApplication.ActiveDocument;

            //Set a reference to the active sheet.
            Sheet oSheet = oDrawDoc.ActiveSheet;

            // Set a reference to the first drawing view on
            // the sheet. This assumes the first drawing
            // view on the sheet is not a draft view.
            DrawingView oDrawingView = oSheet.DrawingViews[1];

            // Set a reference to th sheet's border
            Inventor.Border oBorder = oSheet.Border;

            Point2d oPlacementPoint = null;

            if ((oBorder != null))
            {
                // A border exists. The placement point
                // is the top-right corner of the border.
                oPlacementPoint = oBorder.RangeBox.MaxPoint;
            }
            else
            {
                // There is no border. The placement point
                // is the top-right corner of the sheet.
                oPlacementPoint = _InvApplication.TransientGeometry.CreatePoint2d(oSheet.Width, oSheet.Height);
            }

            // Create the parts list.
            PartsList oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint);
        }
Пример #12
0
        /// <summary>
        /// Opens the drawing file
        /// </summary>
        public void openDrawingFile()
        {
            invApp.Documents.Open(location + "\\" + partNumber + ".dwg", true);
            DrawingDocument oDrawing = (DrawingDocument)invApp.ActiveDocument;

            replaceDrawingRef(oDrawing);    // Update drawing references

            PropertySet oDrawingPropSet;
            Property    oDrawingProperty;

            // Set Drawing part number
            oDrawingPropSet        = oDrawing.PropertySets["Inventor Summary Information"];
            oDrawingProperty       = oDrawingPropSet["Title"];
            oDrawingProperty.Value = partNumber;

            // Set Part Number
            oDrawingPropSet        = oDrawing.PropertySets["Design Tracking Properties"];
            oDrawingProperty       = oDrawingPropSet["Part Number"];
            oDrawingProperty.Value = partNumber;

            // Set Drawing description
            oDrawingProperty       = oDrawingPropSet["Description"];
            oDrawingProperty.Value = description;

            // Update Drawing
            oDrawing.Update2();
            oDrawing.Save2();

            // Release Objects
            oDrawingProperty = null;
            oDrawingPropSet  = null;
            oDrawing         = null;
        }
Пример #13
0
        /// <summary>
        /// Replace drawing references
        /// </summary>
        /// <param name="drawingDocument">Drawing with dirty references</param>
        public void replaceDrawingRef(DrawingDocument drawingDocument)
        {
            File drawingFile = drawingDocument.File;
            FileDescriptorsEnumerator fileDescriptors = drawingFile.ReferencedFileDescriptors;

            //using (System.IO.StreamWriter refList = System.IO.File.CreateText(@"\\msw-fp1\user$\wchan\Documents\References.txt"))
            //{
            //    foreach (FileDescriptor f in fileDescriptors)
            //    {
            //        refList.WriteLine(f.FullFileName);
            //    }
            //}

            Dictionary <string, string> referencedFiles = new Dictionary <string, string>();

            foreach (FileDescriptor f in fileDescriptors)
            {
                int idx = f.FullFileName.LastIndexOf('\\');
                referencedFiles.Add(f.FullFileName.Substring(idx + 1), f.FullFileName.Substring(0, idx));
            }

            #region "Replace Drawing References"
            fileDescriptors[referencedFiles["Crosswire Basket.iam"] + "\\Crosswire Basket.iam"].ReplaceReference(location + "\\" + partNumber + ".iam");
            fileDescriptors[referencedFiles["Crosswire X.ipt"] + "\\Crosswire X.ipt"].ReplaceReference(location + "\\Crosswire X.ipt");
            fileDescriptors[referencedFiles["Crosswire Z.ipt"] + "\\Crosswire Z.ipt"].ReplaceReference(location + "\\Crosswire Z.ipt");
            fileDescriptors[referencedFiles["Mid Frame.ipt"] + "\\Mid Frame.ipt"].ReplaceReference(location + "\\Mid Frame.ipt");
            fileDescriptors[referencedFiles["Top Frame.ipt"] + "\\Top Frame.ipt"].ReplaceReference(location + "\\Top Frame.ipt");
            #endregion
        }
Пример #14
0
 public RecoverOp(Inventor.Document newDoc)
 {
     try
     {
         invApp   = (Inventor.Application)newDoc.Parent;
         pathFile = newDoc.FullFileName.ToString();
         pathFile = pathFile.Substring(0, pathFile.LastIndexOf('\\'));
         foreach (Document doc in invApp.Documents.VisibleDocuments)
         {
             XMLDoc xdoc = new XMLDoc(@"C:\ProgramData\Autodesk\Inventor Addins\rename.xml", "head");
             recoverReference(doc, xdoc);
         }
         if (newDoc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
         {
             m_AsmDoc = (AssemblyDocument)newDoc;
             recoverAssembly();
             tr.End();
         }
         if (newDoc.DocumentType == DocumentTypeEnum.kDrawingDocumentObject)
         {
             m_DrwDoc = newDoc as DrawingDocument;
             recoverDrawing();
         }
     }
     catch
     {
     }
     finally
     {
         tr.End();
     }
 }
Пример #15
0
        /// <summary>
        /// Replace drawing references
        /// </summary>
        /// <param name="drawingDocument">Drawing with dirty references</param>
        public void replaceDrawingRef(DrawingDocument drawingDocument)
        {
            File drawingFile = drawingDocument.File;
            FileDescriptorsEnumerator fileDescriptors = drawingFile.ReferencedFileDescriptors;

            Dictionary <string, string> referencedFiles = new Dictionary <string, string>();

            foreach (FileDescriptor f in fileDescriptors)
            {
                int idx = f.FullFileName.LastIndexOf('\\');
                referencedFiles.Add(f.FullFileName.Substring(idx + 1), f.FullFileName.Substring(0, idx));
            }

            #region "Replace Drawing References"
            fileDescriptors[referencedFiles["MESH BASKET.iam"] + "\\MESH BASKET.iam"].ReplaceReference(location + "\\" + partNumber + ".iam");
            fileDescriptors[referencedFiles["FRAME.ipt"] + "\\FRAME.ipt"].ReplaceReference(location + "\\FRAME.ipt");
            fileDescriptors[referencedFiles["BOTTOM T BAR.ipt"] + "\\BOTTOM T BAR.ipt"].ReplaceReference(location + "\\BOTTOM T BAR.ipt");
            fileDescriptors[referencedFiles["HANDLE.ipt"] + "\\HANDLE.ipt"].ReplaceReference(location + "\\HANDLE.ipt");
            fileDescriptors[referencedFiles["MESH.ipt"] + "\\MESH.ipt"].ReplaceReference(location + "\\MESH.ipt");
            fileDescriptors[referencedFiles["SM CORNER.ipt"] + "\\SM CORNER.ipt"].ReplaceReference(location + "\\SM CORNER.ipt");
            fileDescriptors[referencedFiles["SM LENGTH EDGE.ipt"] + "\\SM LENGTH EDGE.ipt"].ReplaceReference(location + "\\SM LENGTH EDGE.ipt");
            fileDescriptors[referencedFiles["VERTICAL T BAR.ipt"] + "\\VERTICAL T BAR.ipt"].ReplaceReference(location + "\\VERTICAL T BAR.ipt");
            fileDescriptors[referencedFiles["MESH DETAIL.ipt"] + "\\MESH DETAIL.ipt"].ReplaceReference(location + "\\MESH DETAIL.ipt");
            #endregion
        }
Пример #16
0
        /// <summary>
        ///  how to create a custom table
        /// </summary>
        /// <remarks></remarks>
        public void CreateCustomTable()
        {
            // Set a reference to the drawing document.
            // This assumes a drawing document is active.
            DrawingDocument oDrawDoc = (DrawingDocument)_InvApplication.ActiveDocument;

            // Set a reference to the active sheet.
            Sheet oSheet = default(Sheet);

            oSheet = oDrawDoc.ActiveSheet;

            // Set the column titles
            string[] oTitles = new string[] {
                "Part Number",
                "Quantity",
                "Material"
            };



            // Set the contents of the custom table (contents are set row-wise)
            string[] oContents = new string[] {
                "1",
                "1",
                "Brass",
                "2",
                "2",
                "Aluminium",
                "3",
                "1",
                "Steel"
            };

            // Set the column widths (defaults to the column title width if not specified)
            double[] oColumnWidths = new double[] {
                2.5,
                2.5,
                4
            };

            // Create the custom table
            CustomTable oCustomTable = default(CustomTable);

            oCustomTable = oSheet.CustomTables.Add("My Table", _InvApplication.TransientGeometry.CreatePoint2d(15, 15), 3, 3, oTitles, oContents, oColumnWidths);

            // Change the 3rd column to be left justified.
            oCustomTable.Columns[3].ValueHorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft;

            // Create a table format object
            TableFormat oFormat = oSheet.CustomTables.CreateTableFormat();

            // Set inside line color to red.
            oFormat.InsideLineColor = _InvApplication.TransientObjects.CreateColor(255, 0, 0);

            // Set outside line weight.
            oFormat.OutsideLineWeight = 0.1;

            // Modify the table formats
            oCustomTable.OverrideFormat = oFormat;
        }
Пример #17
0
        /// <summary>
        /// insert a sketched symbol by the definition above
        /// </summary>
        /// <remarks></remarks>
        public void InsertSketchedSymbolOnSheet()
        {
            // Set a reference to the drawing document.
            // This assumes a drawing document is active.
            DrawingDocument oDrawDoc = (DrawingDocument)_InvApplication.ActiveDocument;

            // Obtain a reference to the desired sketched symbol definition.
            SketchedSymbolDefinition oSketchedSymbolDef = default(SketchedSymbolDefinition);

            oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions["Circular Callout"];

            Sheet oSheet = oDrawDoc.ActiveSheet;

            // This sketched symbol definition contains one prompted string input. An array
            // must be input that contains the strings for the prompted strings.
            string[] sPromptStrings = new string[1];
            sPromptStrings[0] = "A";

            TransientGeometry oTG = _InvApplication.TransientGeometry;

            // Add an instance of the sketched symbol definition to the sheet.
            // Rotate the instance by 45 degrees and scale by .75 when adding.
            // The symbol will be inserted at (0,0) on the sheet. Since the
            // start point of the line was marked as the insertion point, the
            // start point should end up at (0,0).
            SketchedSymbol oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oTG.CreatePoint2d(0, 0), (3.14159 / 4), 0.75, sPromptStrings);
        }
Пример #18
0
        public override void AddViews(
            Part part,
            int quantity,
            DrawingDocument drawingDocument,
            DrawingViewStyle viewStyle,
            double scale,
            double perspectiveScale
            )
        {
            Part            = part ?? throw new ArgumentNullException(nameof(part));
            DrawingDocument = drawingDocument ?? throw new ArgumentNullException(nameof(drawingDocument));

            if (viewStyle == null)
            {
                throw new ArgumentNullException(nameof(viewStyle));
            }

            var baseViewPosition = DrawingDocument.ActiveSheet.CenterPoint();

            AddFlatPatternBaseView(viewStyle, scale, baseViewPosition);
            var partsList       = AddPartsList(quantity);
            var perspectiveView = AddPerspectiveView(viewStyle, perspectiveScale);

            if (partsList != null)
            {
                perspectiveView.Position =
                    AddIn.CreatePoint2D(
                        x: perspectiveView.Position.X,
                        y: perspectiveView.Position.Y - partsList.RangeBox.Height()
                        );
            }

            // Next operation not necessary for GenerateSheetMetalDrawingsBehaviorType.BaseViewWithLeftThenThreeTopProjectedViews
            AddTopView(viewStyle, perspectiveScale);
        }
Пример #19
0
        //Constructor
        public SheetSettings(Inventor.Application inventorApp, Document drawingDoc)
        {
            try
            {
                InventorApp = inventorApp;
                drawDoc     = drawingDoc as DrawingDocument;
                if (drawDoc == null)
                {
                    throw new Exception("The Sheet Manager can only be used inside of a Drawing file.");
                }

                currentlyActiveSheet = drawDoc.ActiveSheet;

                sheetSizesList      = new List <string>();
                sheetFormatsList    = new List <string>();
                borders             = new List <string>();
                titleBlocks         = new List <string>();
                titleBlockPlacement = new List <string>();

                titleBlockPlacement.Add("Lower Left");
                titleBlockPlacement.Add("Lower Right");
                titleBlockPlacement.Add("Upper Right");
                titleBlockPlacement.Add("Upper Left");

                SheetName = currentlyActiveSheet.Name;
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #20
0
        /// <summary>
        /// Sets up the drawing document and gets the sheets
        /// </summary>
        /// <param name="doc"></param>
        public InventorDrawingDocument(Document doc) : base(doc)
        {
            _drawing = (DrawingDocument)doc;
            Sheets   = new List <InventorSheet>();

            GetSheets();
        }
Пример #21
0
 public sheet()
 {
     drw        = (DrawingDocument)Macros.StandardAddInServer.m_inventorApplication.ActiveDocument;
     invDoc     = new InvDoc.InvDocument <Document>((Document)drw);
     invDoc.doc = (Document)drw;
     InitializeComponent();
     if (System.IO.File.Exists(@"C:\ProgramData\Autodesk\Inventor Addins\sheet.xml"))
     {
         xmlDoc = new XMLDoc(@"C:\ProgramData\Autodesk\Inventor Addins\sheet.xml", "head");
         foreach (var item in xmlDoc.Doc.Descendants("w"))
         {
             comboBox1.Items.Add(item.Value);
         }
         if (comboBox1.Items.Count != 0)
         {
             comboBox1.Text = comboBox1.Items[0].ToString();
         }
         foreach (var item in xmlDoc.Doc.Descendants("h"))
         {
             comboBox2.Items.Add(item.Value);
         }
         if (comboBox2.Items.Count != 0)
         {
             comboBox2.Text = comboBox2.Items[0].ToString();
         }
     }
 }
Пример #22
0
        private void CreateDrawing(Document doc)
        {
            double viewScale = 0.05;

            // Update this for your drawing path, could add this to the web UI
            // Change file name and update all IDW files and WorkItem args to support DWG
            string templateLoc = "<your drawing path here>"; // "/Drawings/Drawing.idw"

            // This gets the working directory of the Assembly
            DirectoryInfo parentDir = Directory.GetParent(Path.GetFullPath(doc.FullFileName));

            // Need one more directory up to get to the templates
            DirectoryInfo baseDir = Directory.GetParent(parentDir.FullName);

            string templateFile = baseDir.FullName + templateLoc;

            LogTrace("Adding Drawing template: " + templateFile);
            DrawingDocument drawingDoc = (DrawingDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, templateFile);

            LogTrace("Getting the first sheet");
            Sheet sheet = drawingDoc.Sheets[1];

            Point2d point1 = inventorApplication.TransientGeometry.CreatePoint2d(80, 40); // front view
            Point2d point2 = inventorApplication.TransientGeometry.CreatePoint2d(21, 29); // top view

            LogTrace("Adding Drawing Views...");
            DrawingView baseView      = sheet.DrawingViews.AddBaseView((_Document)doc, point1, viewScale, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "My View");
            DrawingView projectedView = sheet.DrawingViews.AddProjectedView(baseView, point2, DrawingViewStyleEnum.kShadedDrawingViewStyle, viewScale);
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Deletes all graphics (valid for parts and assembly documents only, and which doesn't
        // contain ClientFeatures with graphics elements)
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        public static void DeleteAllGraphics()
        {
            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            Document document = InvApp.ActiveDocument;

            ClientGraphicsCollection   cgCol       = null;
            GraphicsDataSetsCollection dataSetsCol = null;

            switch (document.DocumentType)
            {
            case DocumentTypeEnum.kAssemblyDocumentObject:
            case DocumentTypeEnum.kPartDocumentObject:

                ComponentDefinition compDef =
                    AdnInventorUtilities.GetCompDefinition(document);

                //Not a Part or Assembly, return
                if (compDef == null)
                {
                    return;
                }

                cgCol       = compDef.ClientGraphicsCollection;
                dataSetsCol = document.GraphicsDataSetsCollection;

                break;

            case DocumentTypeEnum.kDrawingDocumentObject:

                DrawingDocument drawing = document as DrawingDocument;

                cgCol       = drawing.ActiveSheet.ClientGraphicsCollection;
                dataSetsCol = drawing.ActiveSheet.GraphicsDataSetsCollection;

                break;

            default:
                return;
            }

            if (cgCol.Count != 0)
            {
                foreach (ClientGraphics cg in cgCol)
                {
                    cg.Delete();
                }
            }

            if (dataSetsCol.Count != 0)
            {
                foreach (GraphicsDataSets dataSets in dataSetsCol)
                {
                    dataSets.Delete();
                }
            }

            InvApp.ActiveView.Update();
        }
Пример #24
0
 public void Dispose()
 {
     if (m_Document != null)
     {
         Marshal.ReleaseComObject(m_Document);
         m_Document = null;
     }
 }
Пример #25
0
 public abstract void AddViews(
     Part part,
     int quantity,
     DrawingDocument drawingDocument,
     DrawingViewStyle viewStyle,
     double scale,
     double perspectiveScale
     );
Пример #26
0
        /// <summary>
        /// Enumerate all parameter objects in a provided DrawingDocument object as IEnumerable{Parameter}
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        public static IEnumerable <Parameter> EnumerateParameters(this DrawingDocument document)
        {
            Parameters parameters = document.GetParameters();

            foreach (Parameter parameter in parameters)
            {
                yield return(parameter);
            }
        }
Пример #27
0
        public static SheetParameters CreateA32Views(ComponentDefinition cdef, DrawingDocument drawDoc)
        {
            var parameters = new SheetParameters(cdef, drawDoc);

            parameters.SheetFormat = drawDoc.SheetFormats["А3"];
            parameters.AddBaseView(point: CAddIn.App.TransientGeometry.CreatePoint2d(11.5, 22.5));
            parameters.AddProjectedView(point: CAddIn.App.TransientGeometry.CreatePoint2d(11.5, 15.5));
            return(parameters);
        }
        /// <summary>
        /// Generate drawing document with input model document
        /// </summary>
        /// <param name="filePath">File path for the generated drawing document</param>
        /// <param name="doc">The Inventor document.</param>
        private void SaveAsIDW(string filePath, Document doc)
        {
            LogTrace("Create a new drawing document");
            DrawingDocument drawDoc = (DrawingDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject);

            Inventor.Sheet sheet;

            LogTrace("Get or create a new drawing sheet");
            try
            {
                if (drawDoc.Sheets.Count > 0)
                {
                    sheet      = drawDoc.Sheets[1];
                    sheet.Size = DrawingSheetSizeEnum.kA2DrawingSheetSize;
                }
                else
                {
                    sheet = drawDoc.Sheets.Add(DrawingSheetSizeEnum.kA2DrawingSheetSize);
                }

                TransientGeometry oTG = inventorApplication.TransientGeometry;
                Inventor.Point2d  pt  = oTG.CreatePoint2d(10, 10);

                LogTrace("Create a base view");
                Inventor.DrawingView dv = sheet.DrawingViews.AddBaseView((_Document)doc, pt, 1, ViewOrientationTypeEnum.kIsoTopLeftViewOrientation, DrawingViewStyleEnum.kShadedDrawingViewStyle, "", null, null);
                LogTrace("Change scale of base drawing view");
                dv.Scale = CalculateViewSize(sheet, dv);

                LogTrace("Create projected view");
                Inventor.Point2d     pt2      = oTG.CreatePoint2d(dv.Position.X, dv.Position.Y + dv.Height * 1.2);
                Inventor.DrawingView projView = sheet.DrawingViews.AddProjectedView(dv, pt2, DrawingViewStyleEnum.kShadedDrawingViewStyle);

                Inventor.Point2d pt3 = oTG.CreatePoint2d(sheet.Width - 5, sheet.Height / 3);
                LogTrace("Create part list");
                Inventor.PartsList pl = sheet.PartsLists.Add(dv, pt3, PartsListLevelEnum.kPartsOnly);

                Inventor.Point2d pt4 = oTG.CreatePoint2d(sheet.Width / 2, sheet.Height / 4);
                LogTrace("Create Revision table");
                Inventor.RevisionTable rtable = sheet.RevisionTables.Add(pt4);
                rtable.ShowTitle = true;
                rtable.Title     = "Revision Table Test";
                rtable.RevisionTableRows[1][1].Text = "Inventor IO";
                rtable.RevisionTableRows[1][3].Text = "Test revision table in drawing";
                rtable.RevisionTableRows[1][4].Text = "Autodesk";
                LogTrace("Done:Create Revision table");

                LogTrace($"Saving IDW {filePath}");
                drawDoc.SaveAs(filePath, false);
                drawDoc.Close();
                LogTrace($"Saved IDW as {filePath}");
            }
            catch (Exception e)
            {
                drawDoc.Close();
                LogError($"Generate IDW fails: {e.Message}");
            }
        }
        /// <summary>
        /// Gets the active linear <see cref="DimensionStyle"/>.
        /// </summary>
        /// <param name="drawingDocument">
        /// The <see cref="DrawingDocument"/> instance that this extension method affects.</param>
        /// <returns>The active linear <see cref="DimensionStyle"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="drawingDocument"/> is <c>null</c>.</exception>
        public static DimensionStyle ActiveLinearDimensionStyle(this DrawingDocument drawingDocument)
        {
            if (drawingDocument == null)
            {
                throw new ArgumentNullException(nameof(drawingDocument));
            }

            return(drawingDocument.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.LinearDimensionStyle);
        }
Пример #30
0
        //get bitmap with force background
        private Bitmap getBmpByForceBGColor(System.Drawing.Color forceColor)
        {
            Bitmap tempgetBmpByForceBGColor = null;

            if (m_inventorApplication.ActiveDocument == null)
            {
                return(null);
            }

            Document oDoc = m_inventorApplication.ActiveDocument;

            //in drawing document, change the sheet color and snapshot
            if ((oDoc) is DrawingDocument)
            {
                //change back color and snapshot, and set the color to the original value

                DrawingDocument oDrawDoc       = (DrawingDocument)oDoc;
                Inventor.Color  oSheetOldColor = oDrawDoc.SheetSettings.SheetColor;

                Inventor.Color oInvForceColor = m_inventorApplication.TransientObjects.CreateColor(forceColor.R, forceColor.G, forceColor.B);

                //change color and snapshot the bitmap
                oDrawDoc.SheetSettings.SheetColor = oInvForceColor;
                m_inventorApplication.ActiveView.Update();
                tempgetBmpByForceBGColor = createRawBitmap(oSize, oCornerPt);
                //set color back
                oDrawDoc.SheetSettings.SheetColor = oSheetOldColor;
            }
            else     //other type of document, set color info of color skema
            {
                Inventor.BackgroundTypeEnum oOldBGType = m_inventorApplication.ColorSchemes.BackgroundType;
                string oOldBGImage = "";
                if (oOldBGType == BackgroundTypeEnum.kImageBackgroundType)
                {
                    oOldBGImage = m_inventorApplication.ActiveColorScheme.ImageFullFileName;
                }

                //change background color
                m_inventorApplication.ColorSchemes.BackgroundType = BackgroundTypeEnum.kImageBackgroundType;

                if (forceColor == System.Drawing.Color.White)
                {
                    m_inventorApplication.ActiveColorScheme.ImageFullFileName = System.IO.Path.GetDirectoryName(this.GetType().Assembly.Location) + "\\Resources\\white.bmp";
                }

                m_inventorApplication.ActiveView.Update();
                tempgetBmpByForceBGColor = createRawBitmap(oSize, oCornerPt);

                //set the color back
                m_inventorApplication.ColorSchemes.BackgroundType = oOldBGType;
                if (oOldBGType == BackgroundTypeEnum.kImageBackgroundType)
                {
                    m_inventorApplication.ActiveColorScheme.ImageFullFileName = oOldBGImage;
                }
            }
            return(tempgetBmpByForceBGColor);
        }