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: 

Inherit Parameters from Factory iParts into Assemblies

1 REPLY 1
Reply
Message 1 of 2
kenY58U9
338 Views, 1 Reply

Inherit Parameters from Factory iParts into Assemblies

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:

 

  1. Factory Part must have a static name assigned to it (this means, rename it to something meaningful to you)
  2. This same name must be put in the iLogic rule code (there is a variable near the beginning)

  3. Because the Rule has the name hard-coded to match the particular Factory Part:
    • If you rename that part, you must also update the Rule
    • If you have multiple Factory Parts from which you want to inherit, you need an iLogic rule for each one
  4. Parameters which should be Inherited from the Factory Component into the Assembly must be Exported from the Factory Part
    • In the Parameters Table in Inventor, add a "Checkmark" in the "Export" column for each Parameter you wish to be Inherited
    • You can check to see if the Parameters you want are being exported by looking in the iProperties of the Factory Part. You should see the parameter and its expression (value & units) as "Text" properties in the "Custom" tab.
  5. If you see an inconsistent list when comparing between the Part and your Assembly, (See #4 above), the generated Factory instance is "stale". 
    • "Inconsistent" can mean: a. newly "checked" Parameters are not present; b. "unchecked" Parameters are present.
    • To fix this, you must delete the currently generated Factory instance, and let a new one be generated by Inventor.
    • Look for documentation on Factory Parts to figure out where these "generated instances" are stored.
    • The Rule does not delete "formerly Inherited but no longer Inherited" Parameters, it's up to the User to "clean up" unused Parameters.
  6. If you have other "Custom" iProperties in your Factory Part, then the Rule will try to "Inherit" those too
    • It's likely you will either get some Parameters which have a value of "1" or will get an Error. 
    • There is no code in the Rule to deal with this, but it would be great if some iLogic jock helped make things more robust to this!
  7. There are a couple ways to retrieve the parameter values from the Part.
    • There is code in the rule which has two methods, one of which is selected with the "SetByValue" variable at the top of the Rule code
    • Feel free to experiment with this to get the behavior you prefer in terms of how the inherited Parameters appear in the Parameters table.
    • In many cases you will see no difference between the two methods. The "safest" is SetByValue = True.
  8. A small amount of diagnostic information is included.
    • A configuration variable which enables "Verbose" mode.
    • If enabled, Verbose generates a dialog box summarizing the new Parameters and their values. 
    • Depending on how you trigger the Rule, you could get multiple of these dialogs for a part change. Just extra clicking.
    • Once you are satisfied that it's working for you, set "Verbose" to False and no more dialogs.
  9. Inherited parameters are prefixed with "i" when they are created in the Assembly.
    • The purpose of this little tweak to the name is to distinguish (and allow sorting for) these inherited Parameters
    • If you have a deeper inheritance hierarchy, you will get Parameters with 2 or 3 "i"s. Helps you see where a Parameter comes from.
    • Inherited Parameters also are given a short comment so you can easily see from what Part a Parameter is inherited. 
  10. Once you create the Rule, you will have to configure which "Event Triggers" will fire the Rule
    • I'm using the following: "After Document Open", "Any Model Parameter Change", "iPart or iAssembly Change Component"
    • Select triggers which make sense for your use, or just use the rule when you want to manually update Parameters

 

 

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

 

1 REPLY 1
Message 2 of 2

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,

 

Capture.JPG

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

Post to forums  

Autodesk Design & Make Report