Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sheet Metal Active Style

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
241 Views, 2 Replies

Sheet Metal Active Style

Most of the parts I work with are sheet metal design. I would like to make
a cut list that has the following in it

Sheetmetal Style

Flat Sheetmetal Length (As a fraction not decimal)

Flat Sheetmetal Width (As a fraction not decimal)

How can I put these inputs in to the custom parameters for that part? From
their I would be able to make a cut list. Any help would be appreciated.

Thanks

Mark
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

Here's a prototype that I believe solves your problem. It's a VBA auto
macro. If you copy it into the sheet metal document's VBA project taht you
want these properties in, it will create the properties and update them
every time you save the document. I quickly put this together and didn't do
a lot of testing, so you'll want to do some verification that the numbers
are correct.

Public Sub AutoSave()
Dim oFlatPattern As FlatPattern
Set oFlatPattern = ThisDocument.ComponentDefinition.FlatPattern

' Get the custom property set.
Dim oCustomPropSet As PropertySet
Set oCustomPropSet =
ThisDocument.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")

' Check to see if the flat exists.
If Not oFlatPattern Is Nothing Then
' Get the extent of the face.
Dim oExtent As Box
Set oExtent = oFlatPattern.Body.RangeBox

' Extract the width and length from the range.
Dim dLength As Double
Dim dWidth As Double
dLength = oExtent.MaxPoint.X - oExtent.MinPoint.X
dWidth = oExtent.MaxPoint.Y - oExtent.MinPoint.Y

' Conversion factor. This assumes inches.
Dim dConversionFactor As Double
dConversionFactor = 1 / 2.54
' Convert these values to inches and then construct
' strings in fractional form.
dLength = dLength * dConversionFactor
dWidth = dWidth * dConversionFactor
Dim strWidth As String
Dim strLength As String
Dim Nominator As Long
Dim Denominator As Long
Dim Whole As Long
Call ConvertToFraction(dLength, 16, Whole, Nominator, Denominator)
strLength = Whole & " " & Nominator & "/" & Denominator
Call ConvertToFraction(dWidth, 16, Whole, Nominator, Denominator)
strWidth = Whole & " " & Nominator & "/" & Denominator

' Write these string as custom properties. If the properties
already
' exist, then just update them.
On Error Resume Next
oCustomPropSet.Item("SheetMetal Width").Value = strWidth
If Err Then
Err.Clear
Call oCustomPropSet.Add(strWidth, "SheetMetal Width")
End If

oCustomPropSet.Item("SheetMetal Length").Value = strLength
If Err Then
Err.Clear
Call oCustomPropSet.Add(strLength, "SheetMetal Length")
End If
On Error GoTo 0
Else
' The flat doesn't exist so delete the properties, if they exist.
On Error Resume Next
oCustomPropSet.Item("SheetMetal Width").Delete
oCustomPropSet.Item("SheetMetal Length").Delete
On Error GoTo 0
End If

' Create or update the property containing the sheet metal style.
Dim strStyleName As String
strStyleName =
ThisDocument.ComponentDefinition.ActiveSheetMetalStyle.Name

On Error Resume Next
oCustomPropSet.Item("SheetMetal Style").Value = strStyleName
If Err Then
Err.Clear
Call oCustomPropSet.Add(strStyleName, "SheetMetal Style")
End If
On Error GoTo 0
End Sub

' Routine to convert a double value into a useful fraction.
' Value - The input decimal value.
' Tolerance - The input tolerance for the fraction. For example,
' if you input 16 then the fraction will be in 1/16ths
' unless it can be simplified further.
' Whole - The output whole number portion.
' Num - The output numerator of the fraction.
' Den - The output denominator of the fraction.
Private Sub ConvertToFraction(Value As Double, Tolerance As Long, Whole As
Long, Num As Long, Den As Long)
' Get the whole and remainder portion of the input value.
Whole = Int(Value)
Value = Value - Whole

' Find the closest fractional number.
Dim iFractionIndex As Long
iFractionIndex = Int(Value * Tolerance)
If Value - (iFractionIndex / Tolerance) < ((iFractionIndex + 1) /
Tolerance) - Value Then
Num = iFractionIndex
Else
Num = iFractionIndex + 1
End If
Den = Tolerance

' Simplify the result.
If Num <> 0 Then
Do While Num Mod 2 = 0
Num = Num / 2
Den = Den / 2
Loop
End If
End Sub

--
Brian Ekins
Autodesk Inventor API Product Designer

"Mark" wrote in message
news:D3C2568FC5B0C9FADCE79CDCEA154CB9@in.WebX.maYIadrTaRb...
> Most of the parts I work with are sheet metal design. I would like to
make
> a cut list that has the following in it
>
> Sheetmetal Style
>
> Flat Sheetmetal Length (As a fraction not decimal)
>
> Flat Sheetmetal Width (As a fraction not decimal)
>
> How can I put these inputs in to the custom parameters for that part?
From
> their I would be able to make a cut list. Any help would be appreciated.
>
> Thanks
>
> Mark
>
>
Message 3 of 3
Anonymous
in reply to: Anonymous

Thanks

It works great.

Mark


"Brian Ekins" wrote in message
news:31A1B3C3764D7F74889C335ED0AD74BF@in.WebX.maYIadrTaRb...
> Here's a prototype that I believe solves your problem. It's a VBA auto
> macro. If you copy it into the sheet metal document's VBA project taht
you
> want these properties in, it will create the properties and update them
> every time you save the document. I quickly put this together and didn't
do
> a lot of testing, so you'll want to do some verification that the numbers
> are correct.
>
> Public Sub AutoSave()
> Dim oFlatPattern As FlatPattern
> Set oFlatPattern = ThisDocument.ComponentDefinition.FlatPattern
>
> ' Get the custom property set.
> Dim oCustomPropSet As PropertySet
> Set oCustomPropSet =
> ThisDocument.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
>
> ' Check to see if the flat exists.
> If Not oFlatPattern Is Nothing Then
> ' Get the extent of the face.
> Dim oExtent As Box
> Set oExtent = oFlatPattern.Body.RangeBox
>
> ' Extract the width and length from the range.
> Dim dLength As Double
> Dim dWidth As Double
> dLength = oExtent.MaxPoint.X - oExtent.MinPoint.X
> dWidth = oExtent.MaxPoint.Y - oExtent.MinPoint.Y
>
> ' Conversion factor. This assumes inches.
> Dim dConversionFactor As Double
> dConversionFactor = 1 / 2.54
> ' Convert these values to inches and then construct
> ' strings in fractional form.
> dLength = dLength * dConversionFactor
> dWidth = dWidth * dConversionFactor
> Dim strWidth As String
> Dim strLength As String
> Dim Nominator As Long
> Dim Denominator As Long
> Dim Whole As Long
> Call ConvertToFraction(dLength, 16, Whole, Nominator, Denominator)
> strLength = Whole & " " & Nominator & "/" & Denominator
> Call ConvertToFraction(dWidth, 16, Whole, Nominator, Denominator)
> strWidth = Whole & " " & Nominator & "/" & Denominator
>
> ' Write these string as custom properties. If the properties
> already
> ' exist, then just update them.
> On Error Resume Next
> oCustomPropSet.Item("SheetMetal Width").Value = strWidth
> If Err Then
> Err.Clear
> Call oCustomPropSet.Add(strWidth, "SheetMetal Width")
> End If
>
> oCustomPropSet.Item("SheetMetal Length").Value = strLength
> If Err Then
> Err.Clear
> Call oCustomPropSet.Add(strLength, "SheetMetal Length")
> End If
> On Error GoTo 0
> Else
> ' The flat doesn't exist so delete the properties, if they exist.
> On Error Resume Next
> oCustomPropSet.Item("SheetMetal Width").Delete
> oCustomPropSet.Item("SheetMetal Length").Delete
> On Error GoTo 0
> End If
>
> ' Create or update the property containing the sheet metal style.
> Dim strStyleName As String
> strStyleName =
> ThisDocument.ComponentDefinition.ActiveSheetMetalStyle.Name
>
> On Error Resume Next
> oCustomPropSet.Item("SheetMetal Style").Value = strStyleName
> If Err Then
> Err.Clear
> Call oCustomPropSet.Add(strStyleName, "SheetMetal Style")
> End If
> On Error GoTo 0
> End Sub
>
> ' Routine to convert a double value into a useful fraction.
> ' Value - The input decimal value.
> ' Tolerance - The input tolerance for the fraction. For example,
> ' if you input 16 then the fraction will be in 1/16ths
> ' unless it can be simplified further.
> ' Whole - The output whole number portion.
> ' Num - The output numerator of the fraction.
> ' Den - The output denominator of the fraction.
> Private Sub ConvertToFraction(Value As Double, Tolerance As Long, Whole As
> Long, Num As Long, Den As Long)
> ' Get the whole and remainder portion of the input value.
> Whole = Int(Value)
> Value = Value - Whole
>
> ' Find the closest fractional number.
> Dim iFractionIndex As Long
> iFractionIndex = Int(Value * Tolerance)
> If Value - (iFractionIndex / Tolerance) < ((iFractionIndex + 1) /
> Tolerance) - Value Then
> Num = iFractionIndex
> Else
> Num = iFractionIndex + 1
> End If
> Den = Tolerance
>
> ' Simplify the result.
> If Num <> 0 Then
> Do While Num Mod 2 = 0
> Num = Num / 2
> Den = Den / 2
> Loop
> End If
> End Sub
>
> --
> Brian Ekins
> Autodesk Inventor API Product Designer
>
> "Mark" wrote in message
> news:D3C2568FC5B0C9FADCE79CDCEA154CB9@in.WebX.maYIadrTaRb...
> > Most of the parts I work with are sheet metal design. I would like to
> make
> > a cut list that has the following in it
> >
> > Sheetmetal Style
> >
> > Flat Sheetmetal Length (As a fraction not decimal)
> >
> > Flat Sheetmetal Width (As a fraction not decimal)
> >
> > How can I put these inputs in to the custom parameters for that part?
> From
> > their I would be able to make a cut list. Any help would be
appreciated.
> >
> > Thanks
> >
> > Mark
> >
> >
>
>

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums