I have been trying to create a macro to control an assembly. The problem is that I need to access a certain parameter in a specific part in the assembly. I can get the exact parameter by using the "name" of the given parameter, ex .Item("d7") to call the parameter d7. The problem for me has been what name do I use to call out a given part, I have been using .Item(Index number), ex .Item(12), but this number can change as parts are added, deleted, or suppressed. The question is what "name" should I be using and how do I use it. I have tried "InternalName", "PrimaryDeselGUID", "DisplayName", "FullDocumentName", "FullFileName" but there is no "Name" to input like the parameter. Thanks for any help.
You can always get reference to desired parameter by its name using Item property of the Parameters collection.
Parameters.Item( Index As Variant ) As Parameter
Index |
Input Variant value that specifies the object to return. This can be either a numeric value indicating the index of the item in the collection or it can be a string indicating the parameter name.
|
You should use the name you see in the Inventor parameters editor in UI, e.g. "d7".
It is good idea to give parameters more meaningful names.
Cheers,
When you work in an assembly context access to parts parameters become slightly more complicated.
Assembly document has a collection of references to all its components. They can be parts or subassemblies.
Component is represented by ComponentOccurrence object in the Inventor API. If component is a part then property ComponentOccurrence.Definition returns PartComponentDefinition object that allows you to get references to all part parameters.
Private Sub Test_Occurrences() Dim oAssyDoc As AssemblyDocument Set oAssyDoc = ThisApplication.ActiveDocument Dim oAssyDef As AssemblyComponentDefinition Set oAssyDef = oAssyDoc.ComponentDefinition 'process all subassemblies Dim oOcc As ComponentOccurrence 'access to component by its name (as it is shown in browser) Set oOcc = oAssyDef.Occurrences.ItemByName("LD-049:1") If oOcc.Definition.Type = kPartComponentDefinitionObject Then 'reference to Component Definition Dim oDef As PartComponentDefinition Set oDef = oOcc.Definition 'reference to part document Dim oDoc As PartDocument Set oDoc = oDef.Document 'reference to parameters Dim oPars As Inventor.Parameters Set oPars = oDef.Parameters Dim oPar As Inventor.Parameter Set oPar = oPars.Item("d7") Debug.Print oPar.Expression oPar.Expression = "50 mm" 'update & save changes oDoc.Update oDoc.Save End If End Sub
See also overview "Building an Assembly" in the Inventor API Help.
Cheers,
Edit: I see you have some code now to work with (added while i was typing my reply) so therefore some of my reply is now irrelevant. I will however leave it in case any of It is of use...
Hi VS,
i am not at my computer at the moment but I will give you some code tomorrow that you can edit to get what you want.
if I understand you right then your immediate challenge is that you just need to find the property set / collection set, that the referenced file descriptor resides in, to then allocate the referenced file to your variable.
One of the biggest breakthroughs i had when staritng out was to understand that one easy way of finding a specific property set is to use the debug functions in the code window, to step one line at a time while you observe your Locals window. In there you can burrow down into the object variable, in this case your assembly document is the uppermost object, then just expand likey candidates within that object to see various types of collection sets or property sets to see what the appropriate category names are for you to transverse or choose specific items from within.
another handy tip, you may now this but if you find a function, property set or method that you wish to understand further is to type it into your code, then highlight the word then hit F1 to bring up the API supporting documentation. It's will then provide examples of the concept, that you can then work out to your own requirements.
i hope this helps.
Can't find what you're looking for? Ask the community or share your knowledge.