Message 1 of 1
ILOGIC RULE - TO CREATE A FRONT VIEW BELOW THE FLAT PATTERN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I LIKE TO GET THE FRONT VIEW OF ALL THE PARTS IN THE ASSEMBLY BRLOW THE OF ITS FLATPATTERN
"
Sub Main 'Check that the active document is an assembly file If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then MessageBox.Show("This rule can only run from an Assembly file", "IDW-creator", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If 'Dim the active document as AssemblyDocument Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument 'Make sure the assembly is saved If oDoc.FullFileName = "" MessageBox.Show("Please save the Assembly before running this rule.", "IDW-creator", MessageBoxButtons.OK, MessageBoxIcon.Information) Exit Sub End If 'Get the assembly filename without extension Dim oAsmName As String = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName) 'Get the assembly filepath Dim oPath As String = System.IO.Path.GetDirectoryName(oDoc.FullFileName) 'Get the parts only BOM. Dim oBOM As BOM = oDoc.ComponentDefinition.BOM 'Make sure Parts Only is activated oBOM.PartsOnlyViewEnabled = True 'Parts only will be last BomView (difficult to get by name since it's different depending on your language) Dim oBOMview As BOMView = oBOM.BOMViews.Item(oBOM.BOMViews.Count) 'Set a reference to the TransientGeometry object Dim oTG As TransientGeometry = ThisApplication.TransientGeometry 'oX and oY will be used to create points for view placement Dim oX As Double = 0 Dim oY As Double = 0 'Create the Baseview options to place flatpattern-views Dim oBaseViewOptions As NameValueMap oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap oBaseViewOptions.Add("SheetMetalFoldedModel", False) 'Set a variable for the drawing document Dim oDrawing As DrawingDocument 'Create a String to return a message if any SM-parts are not saved Dim unsavedSmParts As String = "" Dim i As Integer = 1 Dim oInfo As String = "" 'Traverse Parts Only BOM For Each oRow As BOMRow In oBOMview.BOMRows Try 'Get the component definition for the part Dim oDef As ComponentDefinition = oRow.ComponentDefinitions(1) 'Check if the part is SheetMetal If TypeOf (oDef) Is SheetMetalComponentDefinition 'Set a reference to the partdocument Dim smPartDoc As PartDocument = oDef.Document 'Check if the part is saved If smPartDoc.FullFileName = "" Then If unsavedSmParts = "" Then unsavedSmParts = "The following SM-documents were not saved and therefore " & _ "no drawingviews were created:" & vbCrLf unsavedSmParts = unsavedSmParts & vbCrLf & oDef.Document.DisplayName Continue For End If 'Create flatpattern if it doesn't already exist If Not oDef.HasFlatPattern oDef.Unfold() oDef.FlatPattern.ExitEdit() End If 'Create the drawing if it doesn't already exist If oDrawing Is Nothing Dim templatePath As String = "C:\Users\Public\Documents\Autodesk\Inventor 2024\Templates\en-US\Standard.idw" oDrawing = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, templatePath, False) 'Set the drawings length units to the same as the assemblys length units oDrawing.UnitsOfMeasure.LengthUnits = oDoc.UnitsOfMeasure.LengthUnits End If 'Set a reference to the drawing sheet Dim oSheet As Sheet = oDrawing.ActiveSheet 'Create the flatpattern view Dim oView As DrawingView = oSheet.DrawingViews.AddBaseView(smPartDoc, oTG.CreatePoint2d(oX, oY), 1 _ , ViewOrientationTypeEnum.kDefaultViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, _ "FlatPattern", , oBaseViewOptions) Dim sPartNumber As String sPartNumber = iProperties.Value("Project", "Part Number") oView.Name = smPartDoc.DisplayName oView.ShowLabel = True 'If you don`t want to be visible, put False 'Set the position with our oX and oY oView.Position = oTG.CreatePoint2d(oView.Position.X + oView.Width / 2, oView.Position.Y) 'Move oX to place the next view to the right of this one oX = oView.Left + oView.Width + 50 'Remove the bend lines of the view 'RemoveBendLines(oView, oDef.FlatPattern) 'You could comment out this line to keep bend lines oInfo = oInfo & If (i = 1, "", vbCrLf) & i & ". " & smPartDoc.PropertySets.Item("Design Tracking Properties"). _ Item("Part Number").Value Dim smPartNumber As String smPartNumber = iProperties.Value("Project", "Part Number") i += 1 'Close the part smPartDoc.Close(True) End If Catch Ex As Exception MsgBox(Ex.Message) End Try Next 'Save as IDW If oDrawing IsNot Nothing 'Create the save location string for the IDW Dim oIDWName As String = oPath & "\" & oAsmName & "_FlatPatterns.idw" 'Save the IDW oDrawing.SaveAs(oIDWName, True) MessageBox.Show("IDW saved to: " & oIDWName, "IDW SAVED", MessageBoxButtons.OK, MessageBoxIcon.Information) 'Create the save location string for the information txt Dim oInfoName As String = oPath & "\" & oAsmName & "_FlatPatterns.txt" 'Create the txt CreateTXT(oInfo, oInfoName) End If 'Close the drawing oDrawing.Close 'return information about any unsaved parts If unsavedSmParts <> "" Then _ MessageBox.Show(unsavedSmParts, "Some parts were not saved", _ MessageBoxButtons.OK, MessageBoxIcon.Information) 'Update the assembly (could be dirty if any flatpatterns were created) oDoc.Update End Sub Sub RemoveBendLines(oView As DrawingView, oFlattPattern As FlatPattern) 'Get all the bend edges from the FlatPattern Dim oBendEdgesUp As Edges = oFlattPattern.GetEdgesOfType(FlatPatternEdgeTypeEnum.kBendUpFlatPatternEdge) Dim oBendEdgesDown As Edges = oFlattPattern.GetEdgesOfType(FlatPatternEdgeTypeEnum.kBendDownFlatPatternEdge) For Each oEdge As Edge In oBendEdgesUp 'Get the curves representing these edges in the drawing view For Each oCurve As DrawingCurve In oView.DrawingCurves(oEdge) For Each oSegment As DrawingCurveSegment In oCurve.Segments 'Set visibility to false oSegment.Visible = False Next Next Next For Each oEdge As Edge In oBendEdgesDown For Each oCurve As DrawingCurve In oView.DrawingCurves(oEdge) For Each oSegment As DrawingCurveSegment In oCurve.Segments oSegment.Visible = False Next Next Next End Sub Sub CreateTXT(oText As String, oFileName As String) Dim oTxtWriter As System.IO.StreamWriter = System.IO.File.CreateText(oFileName) oTxtWriter.WriteLine(oText) oTxtWriter.Close() End Sub
"
AND THE LABLE NEED TO SHOW THE FLATPATTERN EXTENDS ,