/// <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}"); } }
// ! 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); } } }
internal void GenerateDrawings(string templateDrawingPath) { TemplateDrawingPath = templateDrawingPath; if (FirstTime == true && TemplateDrawingPath != null && TemplateDrawingPath != "") { string newCopyDrawingName = System.IO.Path.GetFileName(TemplateDrawingPath); string newFullCopyDrawingName = System.IO.Path.Combine(ModulePath, newCopyDrawingName); if (!System.IO.File.Exists(newFullCopyDrawingName)) { DrawingDocument drawingDoc = (DrawingDocument)PersistenceManager.InventorApplication.Documents.Open(TemplateDrawingPath, false); DocumentDescriptorsEnumerator drawingFileDescriptors = drawingDoc.ReferencedDocumentDescriptors; //This needs to be fixed. It was written with the assumption that only the template assembly would be in //the details and be first in the collection of document descriptors. This was a safe assumption when //I was the only user of this code. Need to iterate through drawingFileDescriptors and match names //and replace correct references. Possibly can use the "filePathPair" object for name //matching/reference replacing. //drawingFileDescriptors[1].ReferencedFileDescriptor.ReplaceReference(topAssemblyNewLocation); foreach (DocumentDescriptor refDocDescriptor in drawingFileDescriptors) { foreach (Tuple <string, string> pathPair in FilePathPair) { string newFileNameLower = System.IO.Path.GetFileName(pathPair.Item2); string drawingReferenceLower = System.IO.Path.GetFileName(refDocDescriptor.FullDocumentName); string topAssemblyLower = System.IO.Path.GetFileName(ModuleAssemblyPath); if (topAssemblyLower == drawingReferenceLower) { refDocDescriptor.ReferencedFileDescriptor.ReplaceReference(ModuleAssemblyPath); } if (newFileNameLower == drawingReferenceLower) { refDocDescriptor.ReferencedFileDescriptor.ReplaceReference(pathPair.Item2); } } } drawingDoc.SaveAs(newFullCopyDrawingName, false); drawingDoc.Close(true); if (!UniqueModules.DetailDocumentPaths.Contains(newFullCopyDrawingName)) { UniqueModules.DetailDocumentPaths.Add(newFullCopyDrawingName); } } } }
private void DrawDocument(Inventor._Document Document, string TypeOfPart) { Inventor.ViewOrientationTypeEnum Orientation = Inventor.ViewOrientationTypeEnum.kDefaultViewOrientation; Inventor.DrawingDocument DrawingDocument; Inventor.Sheet Sheet; Inventor.DrawingView DrawingView; Inventor.TransientGeometry oTG = mInvApplication.TransientGeometry; CreateDrawingDocument(out DrawingDocument, out Sheet); //Inventor.DrawingStandardStyle DrawingStandardStyle; //DrawingStandardStyle = DrawingDocument.StylesManager.ActiveStandardStyle; if (TypeOfPart == "SheetMetal") { Inventor.NameValueMap BaseViewOptions = (Inventor.NameValueMap)mInvApplication.TransientObjects.CreateNameValueMap(); BaseViewOptions.Add("SheetMetalFoldedModel", false); DrawingView = AddDocumentBaseView(Document, Sheet, oTG, BaseViewOptions); } else if (TypeOfPart == "Plate") { CDrawingView CView = new CDrawingView(); Inventor.Camera Camera = null; Camera = CView.GetDocument(ref Document, ref mInvApplication); DrawingView = AddDocumentBaseView(Document, Sheet, oTG, Camera); } else { ViewOrientation(ref Orientation); DrawingView = AddDocumentBaseView(Document, Sheet, oTG, Orientation); } try { Inventor.DrawingCurve SelectedCurve = null; foreach (Inventor.DrawingCurve CurveLine in DrawingView.get_DrawingCurves(null)) { //Skip Circles if (CurveLine.StartPoint != null && CurveLine.EndPoint != null) { if (WithinTol(CurveLine.StartPoint.Y, CurveLine.EndPoint.Y, 0.001)) { if (SelectedCurve == null) { //This is the first horizontal curve found. SelectedCurve = CurveLine; } else { //Check to see if this curve is higher (smaller x value) than the current selected if (CurveLine.MidPoint.Y < SelectedCurve.MidPoint.X) { SelectedCurve = CurveLine; } } } } } //Create geometry intents point for the curve. Inventor.GeometryIntent oGeomIntent1 = Sheet.CreateGeometryIntent(SelectedCurve, Inventor.PointIntentEnum.kStartPointIntent); Inventor.GeometryIntent oGeomIntent2 = Sheet.CreateGeometryIntent(SelectedCurve, Inventor.PointIntentEnum.kEndPointIntent); Inventor.Point2d oDimPos = oTG.CreatePoint2d(SelectedCurve.MidPoint.X - 2, SelectedCurve.MidPoint.Y); Inventor.GeneralDimensions oGeneralDimensions = Sheet.DrawingDimensions.GeneralDimensions; Inventor.LinearGeneralDimension oLinearDim; oLinearDim = oGeneralDimensions.AddLinear(oDimPos, oGeomIntent1, oGeomIntent2, Inventor.DimensionTypeEnum.kAlignedDimensionType, true); } catch (Exception) { } mInvApplication.SilentOperation = true; string partURL = Document.FullFileName; int NameLength = Document.FullFileName.Length; string partURLTrimed = partURL.Remove(NameLength - 4); //DrawingDocument.Save(); DrawingDocument.SaveAs(partURLTrimed + ".idw", false); DrawingDocument.Close(true); Document.Close(false); mInvApplication.SilentOperation = false; //Sheet.RevisionTables.Add(oTG.CreatePoint2d(Sheet.Width, Sheet.Height)); //1mm div 10//1 row = 4 //Inventor.DimensionStyle dimstyle = DrawingDocument.StylesManager.DimensionStyles[cmbDimStyles.Text]; //Inventor.Layer layer = DrawingDocument.StylesManager.Layers[cmbLayers.Text]; }
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; }
public void Close() { m_Document.Close(); }