Hi Lisa, Brain,
These code you suggested I already had, but this sets the material style on "Default" and not on "By Sheet Metal Rule"
(see also my attached file)
Here is my complete code to make several SM styles and make one of them active.
In INV 2008 it works fine, but then there wasn't the option "By sheet metal rule" in INV 2008
(e.g. "- St 37" is a custom made Material)
I hope you can help me with this.
Geert
Sub Create_All_SM_Styles()
CreateSheetMetalStyle "1.5 mm", "- St 37", 15, "0.407", False, False, True
CreateSheetMetalStyle "2 mm", "- St 37", 20, "0.321", True, False, True
CreateSheetMetalStyle "3 mm", "- St 37", 30, "0.246", False, False, True
CreateSheetMetalStyle "4 mm", "- St 37", 40, "0.201", False, False, False
CreateSheetMetalStyle "5 mm", "- St 37", 50, "0.198", False, False, False
CreateSheetMetalStyle "6 mm", "- St 37", 60, "0.175", False, False, False
CreateSheetMetalStyle "8 mm", "- St 37", 80, "0.152", False, False, False
CreateSheetMetalStyle "10 mm", "- St 37", 100, "0.143", False, False, False
End Sub
Public Sub CreateSheetMetalStyle(strStyleNaam As String, strMateriaal As String, dPlaatdikte As Double, strKFactor As String, bolActivate As Boolean, bolLast As Boolean, bRadius_2mm As Boolean)
' On Error GoTo ErrorHandler
Dim oPartDoc As PartDocument
Set oPartDoc = objInventorApp.ActiveDocument
Dim oSheetMetalCompDef As SheetMetalComponentDefinition
Set oSheetMetalCompDef = oPartDoc.ComponentDefinition
Dim oStyle As SheetMetalStyle
On Error Resume Next
Set oStyle = oSheetMetalCompDef.SheetMetalStyles.Copy(oSheetMetalCompDef.SheetMetalStyles.It em(1), strStyleNaam)
Dim oMaterial As Inventor.Material
Set oMaterial = oPartDoc.Materials.Item(strMateriaal)
oStyle.Material = oMaterial
Dim okFactorUnfoldMethod As UnfoldMethod
Set okFactorUnfoldMethod = oSheetMetalCompDef.UnfoldMethods.AddLinearUnfoldMethod(strStyleNaam & "_KFactor", strKFactor) oStyle.UnfoldMethod = okFactorUnfoldMethod
oStyle.Thickness = dPlaatdikte / 10
Dim sThicknessName As String
sThicknessName = oSheetMetalCompDef.Thickness.Name
oStyle.BendReliefShape = ""
oStyle.BendReliefWidth = sThicknessName
oStyle.BendReliefDepth = sThicknessName & " * 0.5"
oStyle.MinimumRemnant = sThicknessName & " * 2.0"
If bRadius_2mm = True Then
oStyle.BendRadius = "2 mm"
Else
oStyle.BendRadius = sThicknessName
End If
oStyle.BendTransition = kIntersectionBendTransition
oStyle.CornerReliefShape = kTearCornerReliefShape
oStyle.CornerReliefSize = sThicknessName & " * 4.0"
' Activate this style and set Material Syle -> {color:#ff0000}By Sheet Metal Rule (- St 37)
{color}If bolActivate = True Then
oStyle.Activate
oSheetMetalCompDef.ActiveSheetMetalStyle.Material = oMaterial
End If
If bolLast = True Then
' Set oStyle = oSheetMetalCompDef.ActiveSheetMetalStyle 'Use the current SheetMetalStyle
' Set oMaterial = oPartDoc.Materials.Item("- St 37")
' oStyle.Material = oMaterial
End If
oPartDoc.Update
End Sub