Sheet metal style - material

Sheet metal style - material

Anonymous
Not applicable
1,560 Views
11 Replies
Message 1 of 12

Sheet metal style - material

Anonymous
Not applicable
How can I set the material of a sheet metal part with VB6 to "By sheet metal rule"?

On Error GoTo ErrorHandler
Dim oPartDoc As PartDocument
Set oPartDoc = objInventorApp.ActiveDocument

'selecteer sheet metal component definition.
Dim oSheetMetalCompDef As SheetMetalComponentDefinition
Set oSheetMetalCompDef = oPartDoc.ComponentDefinition

oSheetMetalCompDef.Material = ???????

Regards,

Geert
0 Likes
1,561 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable
Anybody?

See attached example!
0 Likes
Message 3 of 12

Anonymous
Not applicable

Hi Geert:

 

Please refer to my VBA code to set the existent
material of the sheet metal document:

 

Sub test()
    Dim oSM As
PartDocument
    Set oSM =
ThisApplication.ActiveDocument
   
    Dim
oSMCompDef As SheetMetalComponentDefinition
    Set oSMCompDef
= oSM.ComponentDefinition
   
    Dim
oMaterial As Material
    Set oMaterial = oSM.Materials(1)
'Get the material via Index or its
name
    
    oSMCompDef.Material =
oMaterial
End Sub

 

Also you can create a custom material via the
following VBA code extracted from the API help:

 

[Material Create Example (Visual Basic)] This
sample demonstrates how to create a new material in a part document. Before
running the sample you must have a part document open.







Public
class=keyword>Sub
CreateMaterial()
    
class=comment>' Set a reference to the part
document.

    ' This
assumes a part document is active.

    
class=keyword>Dim
oPartDoc As
PartDocument
    Set
oPartDoc =
ThisApplication.ActiveDocument

    
class=comment>' Create a new
material.

    Dim
oNewMaterial As
Material
    Set
oNewMaterial = oPartDoc.Materials.Add("My
Material"
, 11.37)

    
class=comment>' Define the other properties of the
material

    oNewMaterial.LinearExpansion =
5.73
    oNewMaterial.PoissonsRatio =
0.38
    ' Arbitrarily assigns
the first render style in the render styles
collection.

    oNewMaterial.RenderStyle =
oPartDoc.RenderStyles.Item(1)
    oNewMaterial.SpecificHeat
= 124.3
    oNewMaterial.ThermalConductivity =
310.2
    oNewMaterial.UltimateTensileStrength =
210.45
    oNewMaterial.YieldStrength =
185.5
    oNewMaterial.YoungsModulus =
76.37
End
class=keyword>Sub

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
How
can I set the material of a sheet metal part with VB6 to "By sheet metal
rule"? On Error GoTo ErrorHandler Dim oPartDoc As PartDocument Set oPartDoc =
objInventorApp.ActiveDocument 'selecteer sheet metal component definition. Dim
oSheetMetalCompDef As SheetMetalComponentDefinition Set oSheetMetalCompDef =
oPartDoc.ComponentDefinition oSheetMetalCompDef.Material = ??????? Regards,
Geert
0 Likes
Message 4 of 12

Anonymous
Not applicable

Hi Lisa,


Thanks for your reply, but when I use Set oMaterial = oSM.Materials(1) or Set oMaterial = oSM.Materials("ST37"),
the material style is exactly set to ST37 or the first one in the materials collection.
When I then change my Sheet Metal Rule to "2mm Aisi304" the material stays on ST37 and doesn't follow the rule anymore.
Therefore you have in Inventor 2009 the option "{color:#ff0000}By Sheet Metal Rule ( ....)"{color} (.... is material name)

My problem is that I want to set the Material Style on the option "{color:#ff0000}By Sheet Metal Rule ( ST37 )"{color} by VB6 See also my attached file in my earlier reply.
Hopefully you know how to do this.

Geert

0 Likes
Message 5 of 12

Anonymous
Not applicable

Hi Geert,

 

I can't find the materials "ST37", "2mm Aisi304"
from the material library on my inventor.

I'm using Inventor 2009.

Do you create these materials by yourself?

 

Thanks,

-Lisa


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

Hi Lisa,



Thanks for your reply, but when I use Set oMaterial = oSM.Materials(1)
or Set oMaterial = oSM.Materials("ST37"),
the material style is exactly
set to ST37 or the first one in the materials collection.
When I then
change my Sheet Metal Rule to "2mm Aisi304" the material stays on ST37 and
doesn't follow the rule anymore.
Therefore you have in Inventor 2009 the
option "{color:#ff0000}By Sheet Metal Rule ( ....)"{color}
(.... is material name)

My problem is that I want to set the Material
Style on the option "{color:#ff0000}By Sheet Metal Rule ( ST37
)"
{color} by VB6 See also my attached file in my earlier reply.

Hopefully you know how to do this.

Geert

0 Likes
Message 6 of 12

Anonymous
Not applicable
Hi Lisa,

Yes, I created these materials myself through the style library in Inventor. But that's just a example.
You may try it with your own material. For instance "Gray Iron".
You can set the desired material by VB6 to "Gray Iron" but that's not what I want.
I want to set it By Sheet Metal Rule (Gray Iron), so the material follows always the choosen sheet metal rule.
My VB6 routine converts a part to a sheet metal part, creates several sheet metal styles, Unfold metods, etc. we use in our company.
On the end I set one style active, but I can't get set the material style on {color:#ff0000}By Sheet Metal Rule ( Gray Iron )
{color}
Kind Regards,

Geert
0 Likes
Message 7 of 12

Anonymous
Not applicable

Here's some code that will change the material
associated with the active sheet metal rule.

 

Public Sub
SetSheetMetalStyleMaterial()
    Dim oDoc As
PartDocument
    Set oDoc =
ThisApplication.ActiveDocument
   
    Dim
oSMDef As SheetMetalComponentDefinition
    Set oSMDef =
oDoc.ComponentDefinition
   
   
oSMDef.ActiveSheetMetalStyle.Material = oDoc.Materials.Item("Gold")
End
Sub

--
Brian Ekins
Autodesk Inventor API

href="http://blogs.autodesk.com/modthemachine">http://blogs.autodesk.com/modthemachine
0 Likes
Message 8 of 12

Anonymous
Not applicable

I got your meaning now, in
fact you just need to set the SheetMetalStyle's Material.

When selecting a new SheetMetalStyle(In UI:Sheet
Metal Rule), there will be a Material associated with the style.


face="Courier New">
 

Please try the following code to set the
Material to "By Sheet Metal Rule (Gray Iron)":

 

Sub test()
    Dim oSM As
PartDocument
    Set oSM =
ThisApplication.ActiveDocument
   
    Dim
oSMCompDef As SheetMetalComponentDefinition
    Set oSMCompDef
= oSM.ComponentDefinition
   
    Dim
oStyle As SheetMetalStyle
    Set oStyle =
oSMCompDef.ActiveSheetMetalStyle 'Use the current
SheetMetalStyle
   
    Dim oMaterial As
Material
    Set oMaterial = oSM.Materials("Gray
Iron")
   
    oStyle.Material =
oMaterial
End Sub

Thanks,

-Lisa


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hi
Lisa,

Yes, I created these materials myself through the style library
in Inventor. But that's just a example.
You may try it with your own
material. For instance "Gray Iron".
You can set the desired material by VB6
to "Gray Iron" but that's not what I want.
I want to set it By Sheet Metal
Rule (Gray Iron), so the material follows always the choosen sheet metal
rule.
My VB6 routine converts a part to a sheet metal part, creates several
sheet metal styles, Unfold metods, etc. we use in our company.
On the end I
set one style active, but I can't get set the material style on
{color:#ff0000}By Sheet Metal Rule ( Gray Iron )
{color}
Kind
Regards,

Geert
0 Likes
Message 9 of 12

Anonymous
Not applicable
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
0 Likes
Message 10 of 12

Anonymous
Not applicable
I just saw that my code isn't complete (I had changed one line for testing your input)

If bolActivate = True Then
oStyle.Activate
oSheetMetalCompDef.ActiveSheetMetalStyle.Material = oMaterial
End If

It must be:

If bolActivate = True Then
oStyle.Activate
oSheetMetalCompDef.Material = oMaterial 'sets the parts Material, in my case, hard on "- St 37" but not on {color:#ff0000}By Sheet Metal Rule (- St 37){color} End If
0 Likes
Message 11 of 12

Anonymous
Not applicable

Sorry, I didn't understand the question
initially.  To get the sheet metal part to use the material defined by the
sheet metal rule set the
SheetMetalComponentDefinition.UseSheetMetalStyleMaterial property to True.
--

Brian Ekins
Autodesk Inventor API

href="http://blogs.autodesk.com/modthemachine">http://blogs.autodesk.com/modthemachine
Message 12 of 12

Anonymous
Not applicable
Hi Brian,

Thanks, that's it.
I just overlooked these new properties.

Kind Regards,

Geert
0 Likes