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 Extents

87 REPLIES 87
Reply
Message 1 of 88
Anonymous
2689 Views, 87 Replies

Sheet Metal Extents

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
87 REPLIES 87
Message 2 of 88
Anonymous
in reply to: Anonymous

Also what do I have to change with the code to allow me to run it on parts
that are in an assembly? (It runs into errors unless I explicitly open the
part in a separate window.)

Thanks,

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"RobV" wrote in message
news:5480176@discussion.autodesk.com...
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
Message 3 of 88
Anonymous
in reply to: Anonymous

The reason it fails for parts in an assembly is that the program is getting
the active document. Even though you've in-place activated a part, the
assembly is still the active document. Instead of using the ActiveDocument,
you should use the ActiveEditObject property instead. This will return
whatever object the end-user is currently editing. This can be a document,
sketch, or sheet. In the case where a part is in-place activated, the part
document is the active edit object since any edits made will take place
within the part.
--
Brian Ekins
Autodesk Inventor API

"RobV" wrote in message
news:5480280@discussion.autodesk.com...
Also what do I have to change with the code to allow me to run it on parts
that are in an assembly? (It runs into errors unless I explicitly open the
part in a separate window.)

Thanks,

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"RobV" wrote in message
news:5480176@discussion.autodesk.com...
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
Message 4 of 88
Anonymous
in reply to: Anonymous

Hi Brian,

I remember you saying at AU that most VBA should be put in an external
project and not in a part file but for this program where would you put it
and what needs to be changed in the code to allow it to be run upon a save
(or update)?

I guess what I am after is the VBA code that will save the two extent
variables as length and width, be always up to date, and without any
messagebox. I would guess the code would have to be placed in the sheet
metal template file to do this. Am I correct?

Thanks for your help,

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"Brian Ekins (Autodesk)" wrote in message
news:5483813@discussion.autodesk.com...
The reason it fails for parts in an assembly is that the program is getting
the active document. Even though you've in-place activated a part, the
assembly is still the active document. Instead of using the ActiveDocument,
you should use the ActiveEditObject property instead. This will return
whatever object the end-user is currently editing. This can be a document,
sketch, or sheet. In the case where a part is in-place activated, the part
document is the active edit object since any edits made will take place
within the part.
--
Brian Ekins
Autodesk Inventor API

"RobV" wrote in message
news:5480280@discussion.autodesk.com...
Also what do I have to change with the code to allow me to run it on parts
that are in an assembly? (It runs into errors unless I explicitly open the
part in a separate window.)

Thanks,

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"RobV" wrote in message
news:5480176@discussion.autodesk.com...
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
Message 5 of 88
Anonymous
in reply to: Anonymous

Rob

IMO Best Option 1 is to make a Addin. Best Option 2 is to use the
VBAAutoMacros program found in the SDK folder

Either way you are going to have to set up a OnSave event to fire your code.

--
___________________
Kent Keller
www.kwikmcad.com


"RobV" wrote in message
news:5485284@discussion.autodesk.com...
Hi Brian,

I remember you saying at AU that most VBA should be put in an external
project and not in a part file but for this program where would you put it
and what needs to be changed in the code to allow it to be run upon a save
(or update)?

I guess what I am after is the VBA code that will save the two extent
variables as length and width, be always up to date, and without any
messagebox. I would guess the code would have to be placed in the sheet
metal template file to do this. Am I correct?

Thanks for your help,

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"Brian Ekins (Autodesk)" wrote in message
news:5483813@discussion.autodesk.com...
The reason it fails for parts in an assembly is that the program is getting
the active document. Even though you've in-place activated a part, the
assembly is still the active document. Instead of using the ActiveDocument,
you should use the ActiveEditObject property instead. This will return
whatever object the end-user is currently editing. This can be a document,
sketch, or sheet. In the case where a part is in-place activated, the part
document is the active edit object since any edits made will take place
within the part.
--
Brian Ekins
Autodesk Inventor API

"RobV" wrote in message
news:5480280@discussion.autodesk.com...
Also what do I have to change with the code to allow me to run it on parts
that are in an assembly? (It runs into errors unless I explicitly open the
part in a separate window.)

Thanks,

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"RobV" wrote in message
news:5480176@discussion.autodesk.com...
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
Message 6 of 88
Anonymous
in reply to: Anonymous

I agree with Kent. Those are the two options.

Everything gets a little more complicated when you need to program some
associativity, which is what you're doing in this case. You want the
parameters or properties to be associated with the extent of the flat.
Basically, you want something to update in reaction to a change to something
else. To do this you need a program to be watching for the change and then
recompute the dependencies. In your case a slightly delayed associativity
may be ok and you can listen to the event that notifies you when the
document is saved and update the data then. The alternative is to watch for
whenever the model changes and update with each change.

Add-Ins are much better suited for this than VBA macros, but it is possible
using VBA.
--
Brian Ekins
Autodesk Inventor API

"Kent Keller" wrote in message
news:5485372@discussion.autodesk.com...
Rob

IMO Best Option 1 is to make a Addin. Best Option 2 is to use the
VBAAutoMacros program found in the SDK folder

Either way you are going to have to set up a OnSave event to fire your code.

--
___________________
Kent Keller
www.kwikmcad.com


"RobV" wrote in message
news:5485284@discussion.autodesk.com...
Hi Brian,

I remember you saying at AU that most VBA should be put in an external
project and not in a part file but for this program where would you put it
and what needs to be changed in the code to allow it to be run upon a save
(or update)?

I guess what I am after is the VBA code that will save the two extent
variables as length and width, be always up to date, and without any
messagebox. I would guess the code would have to be placed in the sheet
metal template file to do this. Am I correct?

Thanks for your help,

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"Brian Ekins (Autodesk)" wrote in message
news:5483813@discussion.autodesk.com...
The reason it fails for parts in an assembly is that the program is getting
the active document. Even though you've in-place activated a part, the
assembly is still the active document. Instead of using the ActiveDocument,
you should use the ActiveEditObject property instead. This will return
whatever object the end-user is currently editing. This can be a document,
sketch, or sheet. In the case where a part is in-place activated, the part
document is the active edit object since any edits made will take place
within the part.
--
Brian Ekins
Autodesk Inventor API

"RobV" wrote in message
news:5480280@discussion.autodesk.com...
Also what do I have to change with the code to allow me to run it on parts
that are in an assembly? (It runs into errors unless I explicitly open the
part in a separate window.)

Thanks,

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"RobV" wrote in message
news:5480176@discussion.autodesk.com...
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
Message 7 of 88
Anonymous
in reply to: Anonymous

Hi Brian,

I did not realize that I can search for older posts on the web side of the
newsgroup - duhhh. I found a reply from you in 2002 that has exactly what I
am looking for.
http://discussion1.autodesk.com/thread.jspa?messageID=1071518 It seems to
work perfectly fine on Inventor 11. I have placed it in my sheet metal
template. Is there any reason I should not be doing it this way?

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"Brian Ekins (Autodesk)" wrote in message
news:5485402@discussion.autodesk.com...
I agree with Kent. Those are the two options.

Everything gets a little more complicated when you need to program some
associativity, which is what you're doing in this case. You want the
parameters or properties to be associated with the extent of the flat.
Basically, you want something to update in reaction to a change to something
else. To do this you need a program to be watching for the change and then
recompute the dependencies. In your case a slightly delayed associativity
may be ok and you can listen to the event that notifies you when the
document is saved and update the data then. The alternative is to watch for
whenever the model changes and update with each change.

Add-Ins are much better suited for this than VBA macros, but it is possible
using VBA.
--
Brian Ekins
Autodesk Inventor API

"Kent Keller" wrote in message
news:5485372@discussion.autodesk.com...
Rob

IMO Best Option 1 is to make a Addin. Best Option 2 is to use the
VBAAutoMacros program found in the SDK folder

Either way you are going to have to set up a OnSave event to fire your code.

--
___________________
Kent Keller
www.kwikmcad.com


"RobV" wrote in message
news:5485284@discussion.autodesk.com...
Hi Brian,

I remember you saying at AU that most VBA should be put in an external
project and not in a part file but for this program where would you put it
and what needs to be changed in the code to allow it to be run upon a save
(or update)?

I guess what I am after is the VBA code that will save the two extent
variables as length and width, be always up to date, and without any
messagebox. I would guess the code would have to be placed in the sheet
metal template file to do this. Am I correct?

Thanks for your help,

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"Brian Ekins (Autodesk)" wrote in message
news:5483813@discussion.autodesk.com...
The reason it fails for parts in an assembly is that the program is getting
the active document. Even though you've in-place activated a part, the
assembly is still the active document. Instead of using the ActiveDocument,
you should use the ActiveEditObject property instead. This will return
whatever object the end-user is currently editing. This can be a document,
sketch, or sheet. In the case where a part is in-place activated, the part
document is the active edit object since any edits made will take place
within the part.
--
Brian Ekins
Autodesk Inventor API

"RobV" wrote in message
news:5480280@discussion.autodesk.com...
Also what do I have to change with the code to allow me to run it on parts
that are in an assembly? (It runs into errors unless I explicitly open the
part in a separate window.)

Thanks,

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"RobV" wrote in message
news:5480176@discussion.autodesk.com...
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
Message 8 of 88
Anonymous
in reply to: Anonymous

This does work but I wouldn't recommend this approach anymore. VBA projects
that live in the Inventor documents have caused some problems in the past.
Primarily when you use these parts in assemblies. If you have a lot of
parts open that contain VBA macros you can exceed some VBA resources.

There are two other approaches. One is to write an Add-In that does the
equivalent. The second is to use an existing Add-In that will execute a
macro in your application VBA project. I've attached an Add-In and a sample
macro that demonstrates this. It currently writes out some mass property
information to an iProperty when a document is saved, but it could easily be
modifed to write out the sheet metal extents. If you have trouble figuring
it out, let me know and I can make the changes to do this.
--
Brian Ekins
Autodesk Inventor API
Message 9 of 88
Anonymous
in reply to: Anonymous

Hi Brian,

I would very much appreciate if you could make the changes to do this for
me.

Thanks,

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"Brian Ekins (Autodesk)" wrote in message
news:5488877@discussion.autodesk.com...
This does work but I wouldn't recommend this approach anymore. VBA projects
that live in the Inventor documents have caused some problems in the past.
Primarily when you use these parts in assemblies. If you have a lot of
parts open that contain VBA macros you can exceed some VBA resources.

There are two other approaches. One is to write an Add-In that does the
equivalent. The second is to use an existing Add-In that will execute a
macro in your application VBA project. I
've attached an Add-In and a sample
macro that demonstrates this. It currently writes out some mass property
information to an iProperty when a document is saved, but it could easily be
modifed to write out the sheet metal extents. If you have trouble figuring
it out, let me know and I can make the changes to do this.
--
Brian Ekins
Autodesk Inventor API
Message 10 of 88
Anonymous
in reply to: Anonymous

Hi Brian,

I have tried to do some more investigation into this and have installed the
automacros but do not see or understand where the program is located that
writes out the mass property - is this included?

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"Brian Ekins (Autodesk)" wrote in message
news:5488877@discussion.autodesk.com...
This does work but I wouldn't recommend this approach anymore. VBA projects
that live in the Inventor documents have caused some problems in the past.
Primarily when you use these parts in assemblies. If you have a lot of
parts open that contain VBA macros you can exceed some VBA resources.

There are two other approaches. One is to write an Add-In that does the
equivalent. The second is to use an existing Add-In that will execute a
macro in your application VBA project. I
've attached an Add-In and a sample
macro that demonstrates this. It currently writes out some mass property
information to an iProperty when a document is saved, but it could easily be
modifed to write out the sheet metal extents. If you have trouble figuring
it out, let me know and I can make the changes to do this.
--
Brian Ekins
Autodesk Inventor API
Message 11 of 88
Anonymous
in reply to: Anonymous

This request has come up several times so I decided it was probably best to
just go ahead and write and Add-In that does this. The attached zip file
contains the Add-In and the VB 6 source code. I've done some testing but
I'll be happy to fix any problems that you find. Here are the contents of
the readme file that describes the Add-In.

** Description
This is an Add-In that when installed will automatically create and update
three custom iProperties. It should work for Inventor version 10 and later.
The iProperties created are:

SheetMetalLength - The length of the sheet metal flat pattern.
SheetMetalWidth - The width of the sheet metal flat pattern.
SheetMetalStyle - The active sheet metal style.


** Installation
Unzip the files anywhere on your computer, make sure Inventor is not running
and run the Register.bat file. When you run Inventor you should now see
"Sheet Metal Extents" listed as a loaded Add-In. To uninstall, run
UnRegister.bat.
--
Brian Ekins
Autodesk Inventor API


"RobV" wrote in message
news:5529514@discussion.autodesk.com...
Hi Brian,

I have tried to do some more investigation into this and have installed the
automacros but do not see or understand where the program is located that
writes out the mass property - is this included?

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"Brian Ekins (Autodesk)" wrote in message
news:5488877@discussion.autodesk.com...
This does work but I wouldn't recommend this approach anymore. VBA projects
that live in the Inventor documents have caused some problems in the past.
Primarily when you use these parts in assemblies. If you have a lot of
parts open that contain VBA macros you can exceed some VBA resources.

There are two other approaches. One is to write an Add-In that does the
equivalent. The second is to use an existing Add-In that will execute a
macro in your application VBA project. I
've attached an Add-In and a sample
macro that demonstrates this. It currently writes out some mass property
information to an iProperty when a document is saved, but it could easily be
modifed to write out the sheet metal extents. If you have trouble figuring
it out, let me know and I can make the changes to do this.
--
Brian Ekins
Autodesk Inventor API
Message 12 of 88
Anonymous
in reply to: Anonymous

Thanks Brian - look forward to using it!!!! I'll let you know if I come up
against any issues.

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"Brian Ekins (Autodesk)" wrote in message
news:5531286@discussion.autodesk.com...
This request has come up several times so I decided it was probably best to
just go ahead and write and Add-In that does this. The attached zip file
contains the Add-In and the VB 6 source code. I've done some testing but
I'll be happy to fix any problems that you find. Here are the contents of
the readme file that describes the Add-In.

** Description
This is an Add-In that when installed will automatically create and update
three custom iProperties. It should wo
rk for Inventor version 10 and later
The iProperties created are:

SheetMetalLength - The length of the sheet metal flat pattern.
SheetMetalWidth - The width of the sheet metal flat pattern.
SheetMetalStyle - The active sheet metal style.


** Installation
Unzip the files anywhere on your computer, make sure Inventor is not running
and run the Register.bat file. When you run Inventor you should now see
"Sheet Metal Extents" listed as a loaded Add-In. To uninstall, run
UnRe
gister.bat.
--
Brian Ekins
Autodesk Inventor API


"RobV" wrote in message
news:5529514@discussion.autodesk.com...
Hi Brian,

I have tried to do some more investigation into this and have installed the
automacros but do not see or understand where the program is located that
writes out the mass property - is this included?

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"Brian Ekins (Autodesk)" wrote in messag
e
news:5488877@discussion.autodesk.com...
This does work but I wouldn't recommend this approach anymore. VBA projects
that live in the Inventor documents have caused some problems in the past.
Primarily when you use these parts in assemblies. If you have a lot of
parts open that contain VBA macros you can exceed some VBA resources.

There are two other approaches. One is to write an Add-In that does the
equivalent. The second is to use an existing Add-In that will execute a
macro in your a
pplication VBA project. I
've attached an Add-In and a sample
macro that demonstrates this. It currently writes out some mass property
information to an iProperty when a document is saved, but it could easily be
modifed to write out the sheet metal extents. If you have trouble figuring
it out, let me know and I can make the changes to do this.
--
Brian Ekins
Autodesk Inventor API
Message 13 of 88
Anonymous
in reply to: Anonymous

Been using it every day. I love it!

Have had a few crashes lately when switching between sheet metal and
modelling and then performing some additional commands but may be totally
unrelated as I cannot reproduce.

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"RobV" wrote in message
news:5531459@discussion.autodesk.com...
Thanks Brian - look forward to using it!!!! I'll let you know if I come up
against any issues.

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"Brian Ekins (Autodesk)" wrote in message
news:5531286@discussion.autodesk.com...
This request has come up several times so I decided it was probably best to
just go ahead and write and Add-In that does this. The attached zip file
contains the Add-In and the VB 6 source code. I've done some testing but
I'll be happy to fix any problems that you find. Here are the contents of
the readme file that describes the Add-In.

** Description
This is an Add-In that when installed will automatically create and update
three custom iProperties. It should wo
rk for Inventor version 10 and later
The iProperties created are:

SheetMetalLength - The length of the sheet metal flat pattern.
SheetMetalWidth - The width of the sheet metal flat pattern.
SheetMetalStyle - The active sheet metal style.


** Installation
Unzip the files anywhere on your computer, make sure Inventor is not running
and run the Register.bat file. When you run Inventor you should now see
"Sheet Metal Extents" listed as a loaded Add-In. To uninstall, run
UnRe
gister.bat.
--
Brian Ekins
Autodesk Inventor API


"RobV" wrote in message
news:5529514@discussion.autodesk.com...
Hi Brian,

I have tried to do some more investigation into this and have installed the
automacros but do not see or understand where the program is located that
writes out the mass property - is this included?

--
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0


"Brian Ekins (Autodesk)" wrote in messag
e
news:5488877@discussion.autodesk.com...
This does work but I wouldn't recommend this approach anymore. VBA projects
that live in the Inventor documents have caused some problems in the past.
Primarily when you use these parts in assemblies. If you have a lot of
parts open that contain VBA macros you can exceed some VBA resources.

There are two other approaches. One is to write an Add-In that does the
equivalent. The second is to use an existing Add-In that will execute a
macro in your a
pplication VBA project. I
've attached an Add-In and a sample
macro that demonstrates this. It currently writes out some mass property
information to an iProperty when a document is saved, but it could easily be
modifed to write out the sheet metal extents. If you have trouble figuring
it out, let me know and I can make the changes to do this.
--
Brian Ekins
Autodesk Inventor API
Message 14 of 88
Anonymous
in reply to: Anonymous

I'm glad it's working. If anyone finds any reproducable problems I'll be
happy to take a look at them and fix the program.
--
Brian Ekins
Autodesk Inventor API
Message 15 of 88
jorgen
in reply to: Anonymous

Brian, This is excellent.

But do you think you could extend your addin to also work on non-sheetmetal parts?

I would think it could be easy to add three more custom parameters with the total length of a parts bounding box. Something like TotX, TotY and TotZ.

This would be great to use in property expressions on parts like plates, beams etc. If defined in a templatefile this would give us fully automatic BOM-info.


I have previously done something like this with VBA using the following code (I think I may have gotten it from you in the first place):

--------------------------------------------------------------
'Get the RangeBox data of the primary solid body.
'Die if solid body is not defined.
On Error Resume Next
Set oBox = oDoc.ComponentDefinition.SurfaceBodies.Item(1).RangeBox
If Err Then
Exit Sub
End If
On Error GoTo 0
Call oBox.GetBoxData(MinPoint, MaxPoint)

'Calculate X,Y,Z displacement
For i = 1 To 3
dBlockSize(i) = MaxPoint(i) - MinPoint(i)
Next

' Set a reference to the UnitsOfMeasure object of the active document.
Dim oUOM As UnitsOfMeasure
Set oUOM = ThisDocument.UnitsOfMeasure

' Get the enum value that defines the current default length units.
Dim eLengthUnit As UnitsTypeEnum
eLengthUnit = oUOM.LengthUnits

' Get the equivalent string of the enum value.
Dim sLengthUnit As String
sLengthUnit = oUOM.GetStringFromType(eLengthUnit)

' Create a string array showing the X,Y,Z lengths in the current units.
Dim sBlockSize(1 To 3)
For i = 1 To 3
sBlockSize(i) = oUOM.GetStringFromValue(dBlockSize(i), sLengthUnit)
Next

'Isolate numerical values and get units suffix
For i = 1 To 3
sTemp() = Split(sBlockSize(i), " ", 2, 1)
sValues(i) = sTemp(0)
Next

sValues(4) = sTemp(1)
Message 16 of 88
jerr72
in reply to: Anonymous

This addin is exactly what I have been looking for. I downloaded it, and it works fine. However the are 3 items I do need the addin to do. They are 1 Display fractional units. 2 Work in for an assembly. 3 Length & Width to up date if the flat pattern alignment is changed. This sure would be nice if I could find such an addin.
Message 17 of 88
Anonymous
in reply to: Anonymous

1. Just format the units in your partslist to fractional - no need to have
the addin do it that I can see.
2. Not sure what you mean by "work in for an assembly".
3. Not sure why you would be changing the alignment.

The code is there - you can add to it if you need.

--
---------------
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0
ATI FireGL X2 AGP Pro
Graphics Driver: 8.223.0.0
(2 Monitors at 1280x1024)
Using Direct 3D
---------------
wrote in message news:5576388@discussion.autodesk.com...
This addin is exactly what I have been looking for. I downloaded it, and it
works fine. However the are 3 items I do need the addin to do. They are 1
Display fractional units. 2 Work in for an assembly. 3 Length & Width to
up date if the flat pattern alignment is changed. This sure would be nice
if I could find such an addin.
Message 18 of 88
jerr72
in reply to: Anonymous

Sorry, I was asking if I have an assembly and I create a parts list for the entire assembly on one parts list, does this work. I tried this on one assembly, but the addin only pick up the extents of one part. As for the alignment, we work with stainless steel which does have grain direction. The company policy is that the grain direction must be the first dimension listed, hence the alignment issue.
Message 19 of 88
Anonymous
in reply to: Anonymous

It will work on the entire assembly if you indeed have flat patterns for all
the parts and they are all checked out of the vault. You may have to look
at the code if you need specific width and length dimensions to change.

--
---------------
Rob
Inventor 11 SP2 Build 344a
Vault 5.0 Build 11.1.145.0
ATI FireGL X2 AGP Pro
Graphics Driver: 8.223.0.0
(2 Monitors at 1280x1024)
Using Direct 3D
---------------
wrote in message news:5578091@discussion.autodesk.com...
Sorry, I was asking if I have an assembly and I create a parts list for the
entire assembly on one parts list, does this work. I tried this on one
assembly, but the addin only pick up the extents of one part. As for the
alignment, we work with stainless steel which does have grain direction.
The company policy is that the grain direction must be the first dimension
listed, hence the alignment issue.
Message 20 of 88
scarmart
in reply to: Anonymous

A simple solution without VBA is to create a sketch on one side of the part & "project flat pattern". These projected edges cannot be dimensioned so draw a rectangle and constrain to the outermost edges of the projection, then dimmension the rectangle. Go to the parameters and change the name to length & width (or whatever you use in the parts list). This parameter updates with any changes but, if you add a new feature such as an additional flange you need to repeat the process.

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

Post to forums  

Autodesk Design & Make Report