Hi All
I'm trying to transfer multible reference parameters from a derived part to into User Parameters of a new part, and I have run into several issues.
1: How do I get the parameters from the derived part? I've tried this:
Dim Doc As Document
Set Doc = ThisApplication.ActiveDocument
Dim Params As Parameters
Set Params = Doc.ComponentDefinition.Parameters
Dim DerivedParamTbl As DerivedParameterTable
Set DerivedParamTbl = Params.DerivedParameterTables.Item("Path of the derived part") ' I geuss this is very bad practice, since I hoping to use this marco for any derived part I want in th future.
Dim DerivedParam As DerivedParameter
Set DerivedParam = DerivedParamTbl.DerivedParameters.Item("Length")
2: When I get the value of a numeric parameter, the value is scaled down by a factor 10 (the decimal jogs to the left - 100 becomes 10, 200 becomes 20 and so on). I'm having a message box write out the values, and it seems that the scaling talks place, when the value is retreived ( Please note, that the value in this case simply comes from another User Parameter. Since I'm not yet able to get the values from the derived parts referenced parameters, I'm just testing with User Parameters. See the attachements. I'm trying to transfer the values named CopyXXX to the ones called PasteXXX.). Another indication that the scaling takes place when the value is retrieved is that I can simply set the value in the "target parameter" by using a predefined interger variable. Please see the test code:
Sub MakeAbox()
Dim Doc As Document
Set Doc = ThisApplication.ActiveDocument
Dim Params As Parameters
Set Params = Doc.ComponentDefinition.Parameters
Dim UserParams As UserParameters
Set UserParams = Params.UserParameters
Dim PasteDimParam As Parameter
Set PasteDimParam = UserParams.Item("PasteDim")
Dim CopyDimParam As Parameter
Set CopyDimParam = UserParams.Item("CopyDim")
Dim PasteTxtParam As Parameter
Set PasteTxtParam = UserParams.Item("PasteTxt")
Dim CopyTxtParam As Parameter
Set CopyTxtParam = UserParams.Item("CopyTxt")
Dim PasteBoolParam As Parameter
Set PasteBoolParam = UserParams.Item("PasteBool")
Dim CopyBoolParam As Parameter
Set CopyBoolParam = UserParams.Item("CopyBool")
MsgBox CopyDimParam.Value & vbNewLine & CopyTxtParam.Value & vbNewLine & CopyBoolParam.Value
Dim SomeNumber As Integer
SomeNumber = 1523
'PasteDimParam.Expression = CopyDimParam.Value ' When using this line the Target parameter gets the scaled value
PasteDimParam.Expression = CopyDimParam.Value & " cm" ' When using this line the Target parameter gets the scaled value in the equation column, but gets "cheated" to set the right norminal value.
PasteDimParam.Expression = SomeNumber ' When using this line the Target parameter gets the variable "SomeNumber" holds.
'PasteTxtParam.Expression = CopyTxtParam.Value ' Gives me Run time error 5
PasteBoolParam.Expression = CopyBoolParam.Value
Doc.Update
End Sub
3: I can get a text parameter (check what the messages box says) , but I get a Run Time Error 5 when trying to "paste it" to the target parameter.
The purpose of making this is to quickly make a box design, with lid and bottom, with flat patterns for both depending on the bounding box of the derived part.
Any help will be appreciated.
Cheers - Anders
Solved! Go to Solution.
Solved by BrianEkins. Go to Solution.
In the part file with the parameters you want to share, open the parameter list. There is a column "Export Parameter". Check the parameter you want to share. They will show up in the derived parts and they will update when changed.
@Frederick_Lawwrote:In the part file with the parameters you want to share, open the parameter list. There is a column "Export Parameter". Check the parameter you want to share. They will show up in the derived parts and they will update when changed.
Thanks for the answer, but getting the parameter from the derived part into the new parts parameters list is not the issue. How do I get it's object in the macro?
Adding info:
Regarding issue no. 2. I have tested some other macros where I get the coordinates of different points in a part. When the values are displayed in a messagebox, the comma has moved one digit to the left. Say the point is at X 123, Y 456 and Z -789, the messagebox displays X 12,3, Y 45,6 and Z -78,9.
So, it seems that whenever I retreive a value from a dimension or parameter, this scaling occures.
Any idea why?
I believe API return all values in mm which is used internally with Inventor.
Torbjorn is correct about the internal units being why you are seeing the scaling. It appears you are using "mm" as your units, but the values returned from internal API calls are in database units ("cm" in this case).
As for trying to get derived part parameters: The link is only 1 way; the parent part doesn't know it has a derived part made from it, but the derived part knows about it's parent.
Here's a little VBA macro that demonstrates getting what you want. You'll also need the units when creating the new parameters, otherwise you might have a parameter that represents an angle and you create it as a length.
Public Sub GetDerivedParams() Dim partDoc As PartDocument Set partDoc = ThisApplication.ActiveDocument Dim derivedTable As DerivedParameterTable For Each derivedTable In partDoc.ComponentDefinition.Parameters.DerivedParameterTables Debug.Print "Parameters derived from: " & derivedTable.ReferencedDocumentDescriptor.DisplayName Dim param As DerivedParameter For Each param In derivedTable.DerivedParameters Debug.Print " " & param.Name & ", " & param.Value & ", " & param.Units Next Next End Sub
Hi Brian
Sorry for my late reply. I've been away from the office for a while, but finally had the time to try this out. Exactly what I need. Thanks alot.
Cheers - Anders
Hi Brian,
thank you for your solution. Would it be possible to somehow get the original derived parameter name (like name of parameter to which is derived parameter linked to)?
Sometimes you have different names of derived parameter and "original parameter".
Thank you in advance
Can't find what you're looking for? Ask the community or share your knowledge.