Export Assembly Parts to Individual Drawings
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I've scoured these forums for an iLogic code to suit my needs and what I've come across seems to be getting close to what I am chasing.
The following code exports all files in my assembly to my own drawing template - Great! The problem being is that all the parts are inside the one drawing and on the same sheet. In an ideal world they'd be all exported to their own drawings with the suffix _drawing (or something easily distinguishable from their part file name), saved in the part file location, with the flat pattern view, if it exists (if not the drawing wont need to be created) and the folded model. I don't care about the scale or views I'm looking at yet, I'll update that as I go through each drawing. It's just a huge time suck creating each of these.
Is anyone able to support here? I'd also be able to compensate anyone for their time in setting up working code. (Setting up each view, scale and adding bend details to the sheet metal parts could be additional compensated work $)
PS: I know nothing, and I mean diddly squat, about coding...
The code is as follows:
Sub Main Dim asmDoc As Document = ThisApplication.ActiveDocument If asmDoc Is Nothing Then Exit Sub If asmDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then MsgBox("This iLogic rule is intended to run only for assembly documents.", vbExclamation) Exit Sub End If Dim asmDocument As AssemblyDocument = TryCast(asmDoc, AssemblyDocument) If asmDocument Is Nothing Then MsgBox("Failed to cast the active document to AssemblyDocument.", vbExclamation) Exit Sub End If Dim drawingDoc As DrawingDocument = CreateDrawingDocument() If drawingDoc Is Nothing Then Exit Sub For Each occurrence As ComponentOccurrence In asmDocument.ComponentDefinition.Occurrences Dim partDoc As Document = occurrence.Definition.Document If partDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then AddPartViewToDrawing(partDoc, drawingDoc) End If Next Dim drawingFileName As String = System.IO.Path.ChangeExtension(asmDocument.FullFileName, ".idw") drawingDoc.SaveAs(drawingFileName, False) MsgBox("Drawing created successfully: " & drawingFileName, vbInformation) End Sub Function CreateDrawingDocument() As DrawingDocument Dim templatePath As String = "C:\Users\Public\Documents\Autodesk\Inventor 2023\Templates" Dim templateName As String = "DWG Template.idw" Dim templateFullFileName As String = System.IO.Path.Combine(templatePath, templateName) If Not System.IO.File.Exists(templateFullFileName) Then MsgBox("Template Drawing '" & templateName & "' could not be found in '" & templatePath & "'.", vbCritical) Return Nothing End If Dim drawingDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, templateFullFileName, True) If drawingDoc Is Nothing Then MsgBox("Failed to create the drawing document.", vbCritical) Return Nothing End If Return drawingDoc End Function Sub AddPartViewToDrawing(partDoc As Document, drawingDoc As DrawingDocument) Dim baseView As DrawingView = drawingDoc.ActiveSheet.DrawingViews.AddBaseView(partDoc, ThisApplication.TransientGeometry.CreatePoint2d(5, 5), 1.0, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle) ' Additional settings for the view if needed baseView.Position = ThisApplication.TransientGeometry.CreatePoint2d(5, 5) ' Set other properties of the view as needed End Sub