Hi @GosponZ. Looks like a pretty long code process with a lot of separate code routines that took a lot of time to put together. I will take your word for it that it works well, but I did not test it myself, because I'm a little short on time, and have no need for it.
Hi @ToniCoelhoE8VJF. Sure. We can break away from the original code layout, and set this up in two code routines, giving the second one a few options for how it works, to make it a bit more dynamic. A 'Main' code routine that simply deal with getting & supplying the current document and its referenced documents. And a second routine for doing the unfold task, which lets us specify if we want to use the 'A-Side' definition, if one already exists, whether we want to 'prompt user to pick face, and whether we want to create a new A-SideDefinition using the manually picked face. Once again, I have not tested this, so let me know if it works OK for you. If you do not have your iLogic Log tab open, then it would probably be a good idea to show that before running this, then set your iLogic Log level to Trace (not necessarily detailed trace), that way, if it writes anything to the iLogic Log as feedback, it will be captured, and you can look in that tab after the code is done, to see if anything was written into it. If a sheet metal part did not have a flat pattern, but was not modifiable for some reason, it writes a warning about that, to let you know. Also, if an error happens while trying to unfold one of them, the error is written to that Log, instead of a MessageBox or Msg, to speed things up.
Sub Main
Dim oDoc As Inventor.Document = ThisDoc.Document
UnFoldSheetMetalPart(oDoc, True, True, True)
For Each oRefDoc In oDoc.AllReferencedDocuments
UnFoldSheetMetalPart(oRefDoc, True, True, True)
Next
oDoc.Update2(True)
End Sub
Sub UnFoldSheetMetalPart(doc As Inventor.Document, _
Optional UseASideFaceIfAvailable As Boolean = False, _
Optional PromptForFace As Boolean = False, _
Optional CreateASideDefinition As Boolean = False)
If (doc Is Nothing) OrElse (Not TypeOf doc Is PartDocument) Then Return
Dim oPDoc As PartDocument = doc
If Not TypeOf oPDoc.ComponentDefinition Is SheetMetalComponentDefinition Then Return
Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
If oSMDef.HasFlatPattern Then Return
If Not oPDoc.IsModifiable Then
Logger.Warn("Following sheet metal part with no FlatPattern was 'Not Modifiable':" _
& vbCrLf & oPDoc.DisplayName)
Return
End If
Dim oBaseFace As Face = Nothing
Dim oASideFace As Face = Nothing
Dim oNewView As Inventor.View = Nothing
Dim oASideDefs As ASideDefinitions = oSMDef.ASideDefinitions
If UseASideFaceIfAvailable = True Then
If oASideDefs.Count > 0 Then
oASideFace = oASideDefs.Item(1).ASideFace
oBaseFace = oASideFace
End If
End If
If PromptForFace = True Then
If oBaseFace Is Nothing Then
'make the part visible, and the active document
If oPDoc.Views.Count = 0 Then
oNewView = oPDoc.Views.Add()
oNewView.Activate()
Else
oPDoc.Views.Item(1).Activate()
End If
'prompt user to pick face
oBaseFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick 'A-Side Face'")
If oBaseFace Is Nothing Then Return
End If
If CreateASideDefinition = True Then
oASideFace = oBaseFace
'add an ASideDefinition for that face
oASideDefs.Add(oASideFace)
End If
End If
If oBaseFace Is Nothing Then
Try
oSMDef.Unfold()
Catch ex As Exception
Logger.Error("SheetMetalComponentDefinition.Unfold method error for:" & _
vbCrLf & oPDoc.DisplayName & vbCrLf & ex.ToString())
End Try
Else
Try
oSMDef.Unfold2(oBaseFace)
Catch ex As Exception
Logger.Error("SheetMetalComponentDefinition.Unfold2 method error for:" & _
vbCrLf & oPDoc.DisplayName & vbCrLf & ex.ToString())
End Try
End If
If oNewView IsNot Nothing Then oNewView.Close()
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)