Hi @h.w.landGE4MY. With such a huge section of code within a single Try...Catch statement, and such a general feedback message, the feedback message was not very helpful in figuring this out. I copied your whole code into a new, local iLogic rule for review, and editing. I slightly changed a few things in a few places, where I thought it would help. One thing I did not mess with is your 'Distance' variable. I do not understand why you are multiplying its value by 10 in one place, the dividing it by 10 in another place, then multiplying it by 10 again in a third place, but I left it that way, since I do not understand your design intent there. I did eliminate 1 of the 3 different document variables involved, to avoid confusion and document reference mix-up. But the main change is that I broke that single huge Try...Catch statement down into multiple smaller ones, so that we will bet a more accurate understanding about what exact point/step it is encountering the error, and to get more accurate feedback messages, including the original/official error message, with the 'more info' part added in. At least until we better understand the issue. Then those error messages can be shortened again, if wanted. Not sure if any of these changes fixed anything or not, but it is worth a try.
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oCmdMgr As Inventor.CommandManager = ThisApplication.CommandManager
While True
EnterStartValue :
Dim Face1 As FaceProxy = oCmdMgr.Pick(Inventor.SelectionFilterEnum.kPartFaceFilter, "Select Start Face1 to measure distance:")
'oADoc.SelectSet.Select(Face1)
'MsgBox("Face area1: " & Face1.Evaluator.Area & " cm^2")
If Face1 Is Nothing Then
MessageBox.Show("Selection was cancelled", "ilogic")
Beep
Exit While
End If
Dim Face2 As FaceProxy = oCmdMgr.Pick(Inventor.SelectionFilterEnum.kPartFaceFilter, "Select End Face2 to measure distance:")
'oADoc.SelectSet.Select(Face2)
If Face2 Is Nothing Then
MessageBox.Show("Selection was cancelled", "ilogic")
Beep
Exit While
End If
Dim Plane1 As Plane = Face1.Geometry
Dim Plane2 As Plane = Face2.Geometry
Dim Distance As Double = Plane1.DistanceTo(Plane2.RootPoint)
Distance = Math.Abs(Distance * 10)
'Distance = ThisApplication.MeasureTools.GetMinimumDistance(Face1.PointOnFace, Face2.PointOnFace)
Dim question As DialogResult = MessageBox.Show("Klopt " & Round(Distance, 1) & _
" mm " & "als plaatdikte?", Round(Distance, 1) & " mm", MessageBoxButtons.YesNo)
If question = DialogResult.No Then GoTo EnterStartValue
'prompt user to select an occurrence
Dim comp As Inventor.ComponentOccurrence = Nothing
comp = oCmdMgr.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select a component")
If comp Is Nothing Then
MessageBox.Show("Selection was cancelled", "ilogic")
Beep
Exit While
End If
Dim oPartDoc As Inventor.PartDocument = comp.Definition.Document
oPartDoc = ThisApplication.Documents.Open(oPartDoc.FullDocumentName, True)
'convert it to Sheet Metal, if it is not already
If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
Try
oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
Catch ex As Exception
MessageBox.Show("Error converting regular Part to Sheet Metal Part!" & _
vbCrLf & ex.Message & vbCrLf & ex.StackTrace, "ilogic")
Exit While
End Try
End If
Dim oSMDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
oSMDef.UseSheetMetalStyleThickness = False
'MsgBox(Distance & " mm")
Dim oThicknessParam As Inventor.Parameter = oSMDef.Thickness
Distance = Distance / 10
Try
oThicknessParam.Value = Distance
oThicknessParam.ExposedAsProperty = True
oThicknessParam.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
oThicknessParam.CustomPropertyFormat.ShowTrailingZeros = True
oThicknessParam.CustomPropertyFormat.ShowUnitsString = False
Catch ex As Exception
MessageBox.Show("Error setting value of 'Thickness' Parameter, or exporting it to custom iProperty!" & _
vbCrLf & ex.Message & vbCrLf & ex.StackTrace, "ilogic")
Exit While
End Try
If oSMDef.HasFlatPattern = False Then
Try
oSMDef.Unfold
Catch ex As Exception
MessageBox.Show("Error Unfolding part to get FlatPattern!" & _
vbCrLf & ex.Message & vbCrLf & ex.StackTrace, "ilogic")
Exit While
End Try
Else
oSMDef.FlatPattern.Edit
End If
Distance = Distance * 10
Dim fp As FlatPattern = oSMDef.FlatPattern
X = Round(fp.Length * 10, 0)
'MsgBox(X & " mm")
Y = Round(fp.Width * 10, 0)
'MsgBox(Y & " mm")
Dim Omschrijving As String = "Plaat " & Round(Distance, 1)
Try
iProperties.Value(oPartDoc.DisplayName, "Custom", "DIKTE") = Round(Distance, 1)
iProperties.Value(oPartDoc.DisplayName, "Custom", "LENGTE") = X
iProperties.Value(oPartDoc.DisplayName, "Custom", "BREEDTE") = Y
iProperties.Value(oPartDoc.DisplayName, "Custom", "OMSCHRIJVING") = Omschrijving
Catch ex As Exception
MessageBox.Show("Error setting values of custom iProperties in part!" & _
vbCrLf & ex.Message & vbCrLf & ex.StackTrace, "ilogic")
End Try
oSMDef.FlatPattern.ExitEdit
oPartDoc.Close()
End While
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)