Inventor Customization

Reply
*RobV
Message 1 of 87 (1,248 Views)

Sheet Metal Extents

1248 Views, 86 Replies
02-08-2007 12:16 PM
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
*RobV
Message 2 of 87 (1,245 Views)

Re: Sheet Metal Extents

02-08-2007 01:03 PM in reply to: *RobV
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
*Brian Ekins \(Autodesk\)
Message 3 of 87 (1,245 Views)

Re: Sheet Metal Extents

02-12-2007 10:34 AM in reply to: *RobV
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
*RobV
Message 4 of 87 (1,245 Views)

Re: Sheet Metal Extents

02-13-2007 11:05 AM in reply to: *RobV
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
*Kent Keller
Message 5 of 87 (1,245 Views)

Re: Sheet Metal Extents

02-13-2007 11:58 AM in reply to: *RobV
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
*Brian Ekins \(Autodesk\)
Message 6 of 87 (1,245 Views)

Re: Sheet Metal Extents

02-13-2007 12:20 PM in reply to: *RobV
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
*RobV
Message 7 of 87 (1,245 Views)

Re: Sheet Metal Extents

02-15-2007 04:37 PM in reply to: *RobV
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
*Brian Ekins \(Autodesk\)
Message 8 of 87 (1,245 Views)

Re: Sheet Metal Extents

02-15-2007 06:13 PM in reply to: *RobV
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
*RobV
Message 9 of 87 (1,245 Views)

Re: Sheet Metal Extents

02-21-2007 12:09 PM in reply to: *RobV
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
*RobV
Message 10 of 87 (1,245 Views)

Re: Sheet Metal Extents

03-23-2007 03:39 PM in reply to: *RobV
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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube