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