Sheet Metal Read only

Sheet Metal Read only

h.w.landGE4MY
Participant Participant
532 Views
4 Replies
Message 1 of 5

Sheet Metal Read only

h.w.landGE4MY
Participant
Participant

Hi,

 

Since the new installation of inventor 2025 we get an error in our code. The first time we use the complete ilogic code on a part from an assembly it works fine, but when we use it again for the same part the Thickness parameter is "Read only". Does anyone have an idea?

 

oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDoc.ComponentDefinition
			
If oCompDef.UseSheetMetalStyleThickness = True Then 
oCompDef.UseSheetMetalStyleThickness = False
Else
oCompDef.UseSheetMetalStyleThickness = False
End If

			
Dim oThicknessParam As Parameter = oCompDef.Thickness
Distance = Distance / 10
oCompDef.Thickness.Value = Distance

 

0 Likes
Accepted solutions (1)
533 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @h.w.landGE4MY.  Is this the whole code, or just part of the code?  The first line looks out of place, because the 'oPartDoc' variable does not have any meaning yet, because then the 'oDoc' variable is being used to obtain a reference to the document in the lines of code after that point.  If that was the whole code, I would guess that the first line is throwing an error.  I see you are capturing the Parameter object for the 'Thickness' to a variable named 'oThicknessParam', but then you do not use that variable for anything after that point.  Also, what is 'Distance' in that next to last line?  Is this code within an internal (saved within the part document) iLogic rule, and that is the unquoted, blue name of some other a parameter?  I would imagine that if you ran this rule twice in a row, it would set a pretty small value as the thickness, since the 'Distance' value is being reset to 1/10 its value each time, before being used to set the thickness.  There are usually several other aspects of the design that reference the 'Thickness' parameter, so it is most likely that some thicknesses may not work with certain features, if those features are sized a certain way.  That may be a reason for errors being raised also.  It would help to see what the error is saying also.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

h.w.landGE4MY
Participant
Participant

Hi @WCrihfield .

Its just part of the code. Below the entire code. It's not completely clean, but it worked fine untill now.

The error is (part of the code):

hwlandGE4MY_0-1718718185656.png

But it happens on:

oCompDef.Thickness.Value = Distance

 

I think it's because the parameter "thickness" below is read only:

hwlandGE4MY_1-1718718227020.png

 

 

Dim oADoc As AssemblyDocument
oADoc = ThisApplication.ActiveDocument

Dim comp As Object

While True
	

	EnterStartValue:	
			Dim Face1 As FaceProxy = ThisApplication.CommandManager.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 = ThisApplication.CommandManager.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

			Distance = Plane1.DistanceTo(Plane2.RootPoint)
			Distance = Math.Abs(Distance * 10)
			'Distance = ThisApplication.MeasureTools.GetMinimumDistance(Face1.PointOnFace, Face2.PointOnFace)
			question = MessageBox.Show ("Klopt " & Round(Distance, 1) & " mm " & "als plaatdikte?",Round(Distance, 1) & " mm", MessageBoxButtons.YesNo )	
			
			If question = vbNo Then 
				GoTo EnterStartValue
			Else
			End If
			
			
			
	'prompt user to select an occurrence
	comp = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter,"Select a component") 
			If comp Is Nothing Then
				MessageBox.Show ("Selection was cancelled","ilogic")
				Beep
				Exit While
			End If
			
	oPartDoc = comp.Definition.Document
	Dim oCurFile As Document = ThisApplication.Documents.Open(oPartDoc.FullFileName, True)


	Try
		
		oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
		    Dim oDoc As PartDocument
		    oDoc = ThisApplication.ActiveDocument
		    
		    Dim oCompDef As SheetMetalComponentDefinition
		    oCompDef = oDoc.ComponentDefinition
			
			oCompDef.UseSheetMetalStyleThickness = False
		'	MsgBox(Distance & " mm")
	
				Dim oThicknessParam As Parameter
				oThicknessParam = oCompDef.Thickness
				Distance = Distance / 10
				oThicknessParam.Value = Distance
				oThicknessParam.ExposedAsProperty = True
				oThicknessParam.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision 
				oThicknessParam.CustomPropertyFormat.ShowTrailingZeros = True
				oThicknessParam.CustomPropertyFormat.ShowUnitsString = False



			If oCompDef.HasFlatPattern = False Then
			oCompDef.Unfold
    		Else
        	oCompDef.FlatPattern.Edit
    		End If
			
				Distance = Distance * 10
				
				Dim fp As FlatPattern = oCompDef.FlatPattern
				X = Round(fp.Length * 10,0)
				'MsgBox(X & " mm")
				
				Y = Round(fp.Width * 10,0)
				'MsgBox(Y & " mm")

				Dim Omschrijving As String
				Omschrijving = "Plaat " & Round(Distance, 1)

				iProperties.Value(oDoc.DisplayName,"Custom", "DIKTE") = Round(Distance, 1)
				iProperties.Value(oDoc.DisplayName,"Custom", "LENGTE") = X
				iProperties.Value(oDoc.DisplayName,"Custom", "BREEDTE") = Y
				iProperties.Value(oDoc.DisplayName,"Custom", "OMSCHRIJVING") = Omschrijving
			
			
			oCompDef.FlatPattern.ExitEdit
			

		
		
	Catch
		MessageBox.Show("Some Error occurred, make sure it's not read-only or library item", "error")'	
		End Try
		oCurFile.Close()
End While

 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

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

EESignature

(Not an Autodesk Employee)

Message 5 of 5

h.w.landGE4MY
Participant
Participant

Many thanks @WCrihfield! I don't know why but now the Thickness parameter not read only anymore!

hwlandGE4MY_0-1718776543036.png

0 Likes