Hello Community,
I posted a question earlier this week to see if I could get some help with this question. Also, after a LOT of searching, I found others had asked a similar question, but no really satisfying answers except for "do it another way" or "do something else". As neither of these really solves the question at hand, it seemed a worthy challenge to find a way to do this! Please find enclosed below something that accomplishes this (at least in one context).
Some Background:
Factory Components in Inventor are IPT instances generated from a "master" part which contains a table defining a collection of characteristics defining the instances of that part or assembly. You can read elsewhere about exactly what this means, but the upshot is that there is not a single IPT file that you can consistently link to which provides the parameters corresponding to the instance of the Factory Component which exists in your assembly. One might see this as a deficiency in the way that Links & references are handled by Inventor since the Assembly has all the information required to find the correct IPT and change file links to keep Linked Parameters synchronized with the active instance in the assembly, but Inventor (all the way to the current 2017 version) doesn't do this.
For the project I'm working on, we have a collection of base components (the Factory Parts) which might be used in higher-level assemblies. In order to calculate placement of other components in these assemblies (relative to the Factory Part(s)), the dimensions of the Factory Part instance are required. As such, a way is needed to inherit these dimensions from the particular instance included in the assembly. We are also doing some "what if" work, and seek a simple way to switch base components, and have the rest of the assembly adapt. So, that's the background.
If we were using a "static" base component, we'd be able to "link" to the IPT, and import Parameters which are exported by the IPT. However, since we are using a Factory Part, there is not a "single" IPT to link to (since Inventor generates a unique IPT file for each Factory instance).
The Good News is that through iLogic it's possible to query the currently instantiated Part for its exported parameters and populate them into the "User Parameters" table in the Assembly! This has the effect of Linking, without actually using Inventor's file link facilities.
The solution is not "perfect" as it requires a few hard-coded constants (most notably a static name for the part). But with this, the discovery and insertion of the parameters is all automatic.
Some Notes about the solution:
OK, Lots of text there... Hope you made it this far, and understand what's going on...
Here's the Code!
Enjoy,
ken
' iLogic Rule: Inherit Parameters ' Config paramters ' Controls whether paramters are Set by Value Or Expression SetByValue = True ' Controls whether Message Box is displayed with results Verbose = False ' Change the NAME of the table driven IPT instance in the assembly hierarchy view ' from the default (which follows the current included factory file name) ' to a fixed name that will remain constant each time a new instance is selected. ' This name is how we follow the part across selections. strCompName = "YOUR_PART" ' Get a handle for the document (Assembly) we are running in Dim oAssyDoc as Document = ThisDoc.Document ' Get a handle for the (table driven) component (ipt) we want to inherit from ' (Use the constant name set per above comment) Dim oComp = Component.InventorComponent(strCompName) ' Get a handle to the specific IPT document instance present in the Assembly ' This instance is an IPT generated by the Factory part Dim oPartDoc = oComp.Definition.Document ' Get the list of the "Custom" iProperties from this IPT document. ' This list consists of the exported paramters from the IPT ' This is different from the Key Values in the table which defines the Factoy IPT ' NOTE: if the set of exported paramters is changed in the master Factory IPT ' the Generated IPT files are not necessarily updated with this information. ' These generated IPT files must be deleted from the Factory directory in order to ' force regeneration of the files with the new exported paramter information. Dim PartPropSet = oPartDoc.propertySets("Inventor User Defined Properties") ' User Feedback to indicate which method was used to set Parameter values If (SetByValue = True) Then msg = "Set By Value" + vbCrLf Else msg = "Set By Expression" + vbCrLf End If Dim AssyParam AssyUOM = oAssyDoc.UnitsOfMeasure PartUOM = oPartDoc.UnitsOfMeasure ' Iterate through the list of Custom iProperties For Each prop In PartPropSet msg = msg + vbCrLf ' We look for this parameter and get a handle if present. ' If not present, we create the parameter and get a handle. ' We prefix the names of Assembly paramters we inherit with "i" propName = "i"+prop.Name
Try ' Get a handle for the Paramter referenced by prop.Name ' If this fails, we will jump to the Catch and add the Parameter AssyParam = oAssyDoc.ComponentDefinition.Parameters.UserParameters.item(propName) msg = msg + "<" + propName + ">" + " Was Found" Catch ' Create the parameter and get a handle. AssyParam = oAssyDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression(propName, "1", Inventor.UnitsTypeEnum.kDefaultDisplayLengthUnits) 'AssyParam = oAssyDoc.ComponentDefinition.Parameters.UserParameters.item(prop.Name) msg = msg + "<" + propName + ">" + " Was Added" End Try If (SetByValue = True) Then ' We use the VALUE read from the IPT using the name from the Property ' This avoids confusion regarding units, as we are working in Inventor internal units NewVal = Parameter.Param(strCompName, prop.Name).Value ' Set Paramter value in the Assembly (in "User Parameters") AssyParam.Value = NewVal NewValExpression = CStr(NewVal) Else' Setting Parameter by Expression ' Read and construct an expression (value and units) from the Factoy IPT Parameter ' This is important to be sure we don't run into problems due to differing ' units between the Factory IPT and the Assembly it's being use in. NewValExpression = Parameter.Param(strCompName, prop.Name).Expression ' This alternative extracts the "expression" from the Value field of the IPTs Custom Properties ' It *should* yield the same results... 'NewValExpression = Parameter("PCB", prop.Name) ' Set the Parameter AssyParam.Expression = NewValExpression End If ' Add comment indicating where this paramter came from AssyParam.Comment = "Inherited from Part: " + strCompName ' Add to cumulative User Message for Verbose output msg = msg + " and set to: " + NewValExpression + vbCrLf + _ " Which reads back as: " + AssyUOM.GetStringFromValue(AssyParam.Value, Inventor.UnitsTypeEnum.kDefaultDisplayLengthUnits) + vbCrLf Next ' Display Message Box if in Verbose Mode If (Verbose = True) MessageBox.Show(msg, "Inherit Parameters") End If ' Update the Assembly with the new Parameters oAssyDoc.Update
Ken-
Do you know if inheritance is possible for named geometry (Edges, faces, etc)? I'm trying to come up with an auto dimensioning workflow for my iFactory generated parts.
Thanks,