Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        private void InternalGenerateDrawings(string templateDrawingPath, string masterDrawingPath)
        {
            PersistenceManager.InventorApplication.Visible = false;
            if (_testMode)
            {
                if (ModulesList.Count < 3)
                {
                    for (int i = 0; i < ModulesList.Count; i++)
                    {
                        ModulesList[i].GenerateDrawings(templateDrawingPath);
                    }
                }
                else
                {
                    for (int i = 0; i < 3; i++)
                    {
                        ModulesList[i].GenerateDrawings(templateDrawingPath);
                    }
                }
            }
            else
            {
                for (int i = 0; i < ModulesList.Count; i++)
                {
                    ModulesList[i].GenerateDrawings(templateDrawingPath);
                }
            }


            if (masterDrawingPath != null && masterDrawingPath != "" && System.IO.File.Exists(masterDrawingPath))
            {
                //TODO: test extension is .idw
                DrawingDocument masterDrawing = (DrawingDocument)PersistenceManager.InventorApplication.Documents.Open(masterDrawingPath, true);

                for (int p = 0; p < UniqueModules.DetailDocumentPaths.Count; p++)
                {
                    //Get quantity of this module.
                    //TODO: Look at changing this.  It feels brittle.
                    int moduleQuantity = UniqueModules.InstanceGeometryMap.Where(q => q.Item2 == p).Count();

                    DrawingDocument moduleDoc = (DrawingDocument)PersistenceManager.InventorApplication.Documents.Open(UniqueModules.DetailDocumentPaths[p], true);
                    //Iterate through the collection in case the template detail contains many sheets.
                    Sheets detailSheets = moduleDoc.Sheets;
                    for (int q = 0; q < detailSheets.Count; q++)
                    {
                        Sheet currentSheet = detailSheets[q + 1];
                        currentSheet.Activate();
                        DrawingNotes notes = currentSheet.DrawingNotes;
                        foreach (DrawingNote note in notes)
                        {
                            //This is an idea.  Having 'template tags' available to the user that lets them place comments in drawing templates that Dynamo can
                            //swap out for the desired instance value.
                            if (note.Text == "<DynamoUnitNumber>")
                            {
                                int    unitNumber      = p + 1;
                                string moduleLabelNote = String.Format("<StyleOverride FontSize='.6096'>ITEM: {0}</StyleOverride>", unitNumber.ToString());
                                note.FormattedText = moduleLabelNote;
                            }
                            if (note.Text == "<DynamoModuleQuantity>")
                            {
                                string moduleCountNote = String.Format("<StyleOverride FontSize='.6096'>QUANTITY: {0}</StyleOverride>", moduleQuantity.ToString());
                                note.FormattedText = moduleCountNote;
                            }
                        }
                        currentSheet.CopyTo(masterDrawing as _DrawingDocument);
                    }
                    moduleDoc.Close(true);
                }
                masterDrawing.Save2();
                masterDrawing.Close(true);
            }
            PersistenceManager.InventorApplication.Visible = true;
        }