change the thickness

change the thickness

kv5053545
Advocate Advocate
256 Views
3 Replies
Message 1 of 4

change the thickness

kv5053545
Advocate
Advocate

Hi, I have been trying to change the thickness of the .ipt that are inside a sub assembly in the main assembly but as much as I try with this code it doesn't send ethickness the .ipt, I don't know if someone could guide me in my code or if you have managed to do it in another way.

 

 

 

 

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Prompt the user to input a new thickness
Dim newThickness As String
newThickness = InputBox("Enter new thickness (in mm):", "Sheet Metal Thickness", "2.0")

If newThickness = "" Then Exit Sub

' Iterate through occurrences to change the thickness of sheet metal parts
For Each oOcc As ComponentOccurrence In oAsmCompDef.Occurrences.AllLeafOccurrences
    If Not oOcc.Name.Contains("_I") Then Continue For
    If Not oOcc.Definition.Document.DocumentType = DocumentTypeEnum.kPartDocumentObject Then Continue For
    If Not oOcc.Definition.Document.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For

    Dim oDoc As PartDocument = oOcc.Definition.Document

    ' Check if the part is a sheet metal part
    Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition
    If oCompDef.Document.SubType = "{7BA0531A-93FA-11D4-8FA8-0010B541CD80}" Then ' Sheet Metal SubType
        ' Access the thickness parameter and set the new value
        Dim oThicknessParam As Parameter = oCompDef.Parameters.Item("Sheet Metal Thickness")
        oThicknessParam.Value = ThisApplication.UnitsOfMeasure.ConvertUnits(newThickness, UnitsTypeEnum.kMillimeterLengthUnits, oThicknessParam.Units)
    End If
Next

iLogicVb.UpdateWhenDone = True

 

 

 

 

 

kv5053545_0-1729008057872.png

 

0 Likes
257 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @kv5053545.  Here is a different version of code that you can try out for that task.  It iterates through referenced documents instead of component occurrences, and works with the sheet metal specific properties.

 

Sub Main
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Return
	Dim sThickness As String = InputBox("Enter new thickness (in mm):", "Sheet Metal Thickness", "2.0")
	For Each oRefPDoc As PartDocument In oADoc.AllReferencedDocuments.OfType(Of Inventor.PartDocument)
		If Not TypeOf oRefPDoc.ComponentDefinition Is SheetMetalComponentDefinition Then Continue For
		Dim oSMDef As SheetMetalComponentDefinition = oRefPDoc.ComponentDefinition
		Try
			oSMDef.UseSheetMetalStyleThickness = True
			oSMDef.ActiveSheetMetalStyle.Thickness = sThickness
			oRefPDoc.Update2(True)
		Catch
			Logger.Error("Error changing thickness of following sheet metal part:" _
			& vbCrLf & oRefPDoc.FullDocumentName)
		End Try
	Next
	oADoc.Update2(True)
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

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

kv5053545
Advocate
Advocate

hi @WCrihfield, It does not send me any error but does not change the thickness 😞

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Did you look within the iLogic Log window after you ran the rule, to see if the rule wrote any feedback to it?  If you did not have that "iLogic Log" tab visible before running the rule, then the rule would not have been able to write anything to it.

WCrihfield_1-1729014744354.png

WCrihfield_0-1729014708262.png

Try changing the value of that option on Line 10 of my code example to 'False', instead of 'True', and see if that works better for you.

I could not remember at the moment I typed that rule up, which way that setting had to be set, to be able to set the thickness.  In the image you pasted within your original post, you have the checkbox unchecked for the option named "Use Thickness From Rule".  I was not sure if that was on purpose (is how you want it) or not, but that is an important detail to how this will work.  If that option is on (checkbox checked or setting = True), then I don't think we can change the thickness of the sheet metal style itself, because the model is currently using it.  But if that option is off (checkbox unchecked or setting = False) then it will allow us to change the thickness value of that sheet metal style.  However, if your sheet metal part has any custom ModelStates in it, then the code may need to bet a bit more complicated to make it work.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes