- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
We have a model we created in Fusion containing 2000+ individual solid parts. All the parts are different shapes, but they all have the same thickness, 1.2cm. Our final build contains 8 different materials. We are going to cut all of the parts out of sheets (8 different material types), all 1.2cm thick. Our plan is to send our model into Autodesk TruNest which will efficiently nest all of the parts onto the correct material and add etching labels to each part so that we can find them for assembly.
TruNest accepts Inventor files as input, and expects them to be sheet metal flat parts (I think). We exported our Fusion file to Inventor (using Autodesk Cloud). Then the following script is meant convert each part from a solid part to a sheet metal part, ready to be nested by TruNest. It uses a naming convention on the part name to assign each part to a material (since the material is lost exporting to Inventor from Fusion).
I am still having an issue with the script. The line oSheetMetalCompDef.Unfold or perhaps the line oSheetMetalCompDef.FlatPattern.ExitEdit causes Inventor to crash. Perhaps if Inventor can't fold, then ExitEdit crashes? I am hard-coding the thickness settings, I am thinking that maybe if I calculate the thickness of the part like fredrik.carlsson did in his rule, based on the distance between planes that maybe that would be more robust against rounding errors? Is it typical for Inventor to crash doing something in the API, I guess the Try/Catch blocks don't prevent crashing…?
Any thoughts on the crashing or our workflow would be appreciated. Thanks. Andrew
' ConvertToSheetMetal ' an iLogic rule that converts parts matching a naming scheme 1w21-09a-a:1 ' to Sheet Metal, Unfolds them and prepares for layout in Autodesk TruNest or Autodesk Nesting Utility ' ' Use case: we have an assembly of 2000+ solid parts of uniform thickness created in Fusion that we actually ' want to layout and cut from sheets. So, we export from Fusion to Inventor using Autodesk Cloud. Then we ' run this script, which re-assigns a material to each part, converts it to sheet metal, then unfolds read ' to be packed onto sheets with a nesting program. ' ' This is an Inventor Rule | AKA iLogic Rule ' To run this rule, goto Manage > iLogic Browser ' double click iam main assembly (in the rule window) to expand children ' click plus icon or right click in iLogic Browser and then select add New Rule ' give the rule a name, paste this file into the window, click Save and Run ' after the rule is run you might need to double click on any part to get Inventor to display updates ' ' References: ' loop through all parts of an assembly https://www.cadlinecommunity.co.uk/hc/en-us/articles/202782862-Inventor-2016-ILogic-to-update-parameters-in-every-part-of-an-Assembly ' various ways of getting on parts of the model https://forums.autodesk.com/t5/inventor-forum/ilogic-assembly-component-occurrence-definition/td-p/3639162 ' ' ' ' ' Class ThisRule Dim updatedParts As Integer = 0 Dim updated_a As Integer = 0 Dim updated_b As Integer = 0 Dim updated_c As Integer = 0 Dim updated_d As Integer = 0 Dim updated_e As Integer = 0 Dim updated_f As Integer = 0 Dim updated_g As Integer = 0 Dim updated_h As Integer = 0 Dim errors As Integer = 0 Dim oAsmDoc As AssemblyDocument ' This thickness seems to be in cm Const SHEET_METAL_THICKNESS As Double = 1.2 Sub Main() oAsmDoc = ThisApplication.ActiveDocument Call Iterate(oAsmDoc.ComponentDefinition.Occurrences, 1) ' updated the parts, is this required? oAsmDoc.Update ' All done, give some feedback MsgBox("Updated " & updatedParts & " parts To sheet metal:" & vbLf & updated_a & " 'a' parts" & vbLf & updated_b & " 'b' parts" & vbLf & updated_c & " 'c' parts" & vbLf & updated_d & " 'd' parts" & vbLf & updated_e & " 'e' parts" & vbLf & updated_f & " 'f' parts" & vbLf & updated_g & " 'g' parts" & vbLf & updated_h & " 'h' parts" & vbLf & vbLf & errors & " Errors") End Sub Private Sub Iterate(Occurrences As ComponentOccurrences, Level As Integer) 'Iterate through Assembly Dim oOcc As ComponentOccurrence For Each oOcc In Occurrences 'Find Parts in the Assembly Dim CadlinePart As String CadlinePart = oOcc.Name Try ' Look for parts of the form: 1w21-09a-a:1 (the :1 is automatically added by Autodesk Fusion) If CadlinePart.Length = 12 Dim materialChar As Char materialChar = CadlinePart.Chars(9) ' Grab this part's document Dim invPart As Document invPart = oOcc.Definition.Document ' Assign this part a material based on the part name 'https://forums.autodesk.com/t5/Inventor-customization/material-change-Using-Inventor-api/td-p/4319281 Dim componentDefinition As ComponentDefinition componentDefinition = oOcc.Definition ' Actual materials don't matter since we'll remap them to different materials in the nesting program Select Case materialChar Case "a"c componentDefinition.Material.Name = "ABS Plastic" updated_a += 1 Case "b"c componentDefinition.Material.Name = "Acetal Resin, Black" updated_b += 1 Case "c"c componentDefinition.Material.Name = "Acetal Resin, White" updated_c += 1 Case "d"c componentDefinition.Material.Name = "Aluminum 6061" updated_d += 1 Case "e"c componentDefinition.Material.Name = "Aluminum 6061-AHC" updated_e += 1 Case "f"c componentDefinition.Material.Name = "Aluminum 6061, Welded" updated_f += 1 Case "g"c componentDefinition.Material.Name = "Brass, Soft Yellow" updated_g += 1 Case "h"c componentDefinition.Material.Name = "Brass, Soft Yellow, Welded" updated_h += 1 End Select ' Change to a Sheet Metal Subtype ' https://forums.autodesk.com/t5/inventor-forum/batch-convert-regular-parts-to-sheet-metal-parts/td-p/6477451 Try invPart.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" ' Grab ComponentDefinition as SheetMetalComponentDefinition, now that we have changed its type Dim oSheetMetalCompDef As SheetMetalComponentDefinition oSheetMetalCompDef = invPart.ComponentDefinition ' Override the thickness for the document, otherwise we can't actually set the thickness ' https://forums.autodesk.com/t5/inventor-forum/sheet-metal-controlled-through-ilogic/td-p/3795810 oSheetMetalCompDef.UseSheetMetalStyleThickness = False ' Change the thickness of this sheet metal part to match the thickness of the part ' this is so when we ask Inventor to Create a Flat Pattern / Unpack it just grabs a single face ' IE we don't want to unfold anything we are just cutting a solid part of uniform thickness out of a sheet Dim oThicknessParam As Parameter oThicknessParam = oSheetMetalCompDef.Thickness oThicknessParam.Value = SHEET_METAL_THICKNESS Trace.WriteLine("Inventor: about to unfold part=" &CadlinePart, "error") Try ' Create Flat Pattern AKA Unfold If (Not oSheetMetalCompDef.HasFlatPattern) Then ' the following commands are crashing Inventor 'oSheetMetalCompDef.Unfold 'oSheetMetalCompDef.FlatPattern.ExitEdit ' Do I need any of these? 'invPart.Save() 'invPart.Close() 'oAsmDoc.Activate() End If Catch Trace.WriteLine("Inventor: unable to unfold part for part=" &CadlinePart, "error") errors += 1 End Try updatedParts += 1 Catch Trace.WriteLine("Inventor: unable to change part to sheet metal for part=" &CadlinePart, "error") errors += 1 End Try 'Trace.WriteLine("Inventor: " & CadlinePart & " material=" & materialChar & ", " & componentDefinition.Material.Name) 'Write iProps to Parts, could be usefull to add comments to part to record what we did to it 'iProperties.Value(CadlinePart, "Summary", "Comments") = "Hello World" End If Catch Trace.WriteLine("Inventor: unknown error for part=" &CadlinePart, "error") errors += 1 End Try 'Run through the sub assemblies If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then Call Iterate(oOcc.SubOccurrences, Level + 1) End If Next End Sub End Class
Solved! Go to Solution.