Message 1 of 88
Sheet Metal Extents
Not applicable
02-08-2007
12:16 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I cannot understand why Autodesk does not have the sheet metal extents and
sheet metal style as parameters so we do not have to resort to VBA or
addins. (I know of the great program Yippee etc.)
Anyways, I have included the code from someone at Autodesk for the length
and width. What I do not understand is where to put this code so that it
will be updated every time the sheet metal part is changed. Is there a way
to do this? Do I place it in my sheet metal template file? I am a little
unclear as to where I put it. Also does somebody have the code for the
style?
(I know how to put it in the template file and run the macro but it does not
update unless this is done.)
It has been a while since I have done any programming in VB and have never
done any inside Inventor so any help on this would be greatly appreciated!.
**************************************************************
Public Sub extents_to_custom_props()
Dim objpartDoc As PartDocument
Set objpartDoc = ThisApplication.ActiveDocument
Dim objCompDef As SheetMetalComponentDefinition
Set objCompDef = objpartDoc.ComponentDefinition
Dim fpBox As Variant
Set fpBox = objCompDef.FlatPattern.Body.RangeBox
Dim width As Double
Dim length As Double
length = fpBox.MaxPoint.X - fpBox.MinPoint.X
width = fpBox.MaxPoint.Y - fpBox.MinPoint.Y
Dim objUOM As UnitsOfMeasure
Set objUOM = objpartDoc.UnitsOfMeasure
Dim strLength As String
Dim strWidth As String
strLength = objUOM.GetStringFromValue(length,
UnitsTypeEnum.kDefaultDisplayLengthUnits)
strWidth = objUOM.GetStringFromValue(width,
UnitsTypeEnum.kDefaultDisplayLengthUnits)
Call MsgBox("Width = " + strWidth + vbCrLf + "Length = " + strLength,
vbOKOnly, "Sheet Metal Flat Pattern")
Call Create_ext_prop("width", strWidth)
Call Create_ext_prop("length", strLength)
End Sub
Sub Create_ext_prop(prop As String, prop_value As String)
Dim opropsets As PropertySets
Dim opropset As PropertySet
Dim oUserPropertySet As PropertySet
Set opropsets = ThisApplication.ActiveDocument.PropertySets
For Each opropset In opropsets
If opropset.Name = "Inventor User Defined Properties" Then Set
oUserPropertySet = opropset
Next opropset
' If Property does not exist then add the new Property
On Error Resume Next
Call oUserPropertySet.Add(prop_value, prop)
' Try to set the Property value if it already exists
For i = 1 To oUserPropertySet.Count
If oUserPropertySet.Item(i).Name = prop Then
oUserPropertySet.Item(i).Value = prop_value
Next i
End Sub
*******************************************************************************
--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0
--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0
sheet metal style as parameters so we do not have to resort to VBA or
addins. (I know of the great program Yippee etc.)
Anyways, I have included the code from someone at Autodesk for the length
and width. What I do not understand is where to put this code so that it
will be updated every time the sheet metal part is changed. Is there a way
to do this? Do I place it in my sheet metal template file? I am a little
unclear as to where I put it. Also does somebody have the code for the
style?
(I know how to put it in the template file and run the macro but it does not
update unless this is done.)
It has been a while since I have done any programming in VB and have never
done any inside Inventor so any help on this would be greatly appreciated!.
**************************************************************
Public Sub extents_to_custom_props()
Dim objpartDoc As PartDocument
Set objpartDoc = ThisApplication.ActiveDocument
Dim objCompDef As SheetMetalComponentDefinition
Set objCompDef = objpartDoc.ComponentDefinition
Dim fpBox As Variant
Set fpBox = objCompDef.FlatPattern.Body.RangeBox
Dim width As Double
Dim length As Double
length = fpBox.MaxPoint.X - fpBox.MinPoint.X
width = fpBox.MaxPoint.Y - fpBox.MinPoint.Y
Dim objUOM As UnitsOfMeasure
Set objUOM = objpartDoc.UnitsOfMeasure
Dim strLength As String
Dim strWidth As String
strLength = objUOM.GetStringFromValue(length,
UnitsTypeEnum.kDefaultDisplayLengthUnits)
strWidth = objUOM.GetStringFromValue(width,
UnitsTypeEnum.kDefaultDisplayLengthUnits)
Call MsgBox("Width = " + strWidth + vbCrLf + "Length = " + strLength,
vbOKOnly, "Sheet Metal Flat Pattern")
Call Create_ext_prop("width", strWidth)
Call Create_ext_prop("length", strLength)
End Sub
Sub Create_ext_prop(prop As String, prop_value As String)
Dim opropsets As PropertySets
Dim opropset As PropertySet
Dim oUserPropertySet As PropertySet
Set opropsets = ThisApplication.ActiveDocument.PropertySets
For Each opropset In opropsets
If opropset.Name = "Inventor User Defined Properties" Then Set
oUserPropertySet = opropset
Next opropset
' If Property does not exist then add the new Property
On Error Resume Next
Call oUserPropertySet.Add(prop_value, prop)
' Try to set the Property value if it already exists
For i = 1 To oUserPropertySet.Count
If oUserPropertySet.Item(i).Name = prop Then
oUserPropertySet.Item(i).Value = prop_value
Next i
End Sub
*******************************************************************************
--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0
--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0