Why should this be a reference parameter? You can write the value in a Text type custom parameter. Or into a custom iProperty.
Martin Winkler
CAD Developer
Did you find this post helpful? Feel free to like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
@Martin-Winkler-Consulting Okay, I was just trying to get it as something I could then reference in parameters. this code, in its current form, only gives me a message answer I just wanted to be able to use the answer in formulas
Hi @chris
You would need to have a dimension in a sketch and have it set to driven. Or have a parameter derived from another part.
If this is just a calculation you could just leave it in the code or make a comment to say what the user needs to do E.G do not touch. Unfortunately there is no way to make it read only if I understand your intention.
Hi @chris
edit: see @WCrihfield's post below to add a reference parameter
To make it a reference dimension, I think you would need to have or add a sketch dimension and set it to be driven.
To pass the result to a user parameter, you could use something like this to look for the parameter and create it if not found.
Dim num1 As Double = 7 Dim num2 As Double = 9 Dim oResult As Double = Math.Sqrt(num1 + num2) oName = "My_SQRT_Result" Dim oUserParams As UserParameters If ThisDoc.Document.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then oUserParams = ThisDoc.Document.Parameters.UserParameters Else oUserParams = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters End If Dim oTest As String = "" Try : Parameter(oName) = oResult : Catch : oTest = "not found" : End Try If oTest = "not found" Then oUserParams.AddByValue(oName, oResult, UnitsTypeEnum.kUnitlessUnits) 'oUserParams.AddByValue(oName, oResult, UnitsTypeEnum.kInchLengthUnits) End If 'assumes Length is an inch based parameter 'use * 1 in to convert untiless to inches Parameter.Param("Length").Expression = oName & "* 1 in" InventorVb.DocumentUpdate()
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Or add it to 'User Parameter'
If a reference parameter is wanted, why not just create one directly, using the ReferencedParameters.AddByValue or ReferenceParameters.AddByExpression methods? This seems like the simplest, and most direct way of doing what was asked for in the original post.
Dim oPDoc As PartDocument = ThisDoc.Document
Dim RParams As ReferenceParameters = oPDoc.ComponentDefinition.Parameters.ReferenceParameters
RParams.AddByExpression("123.456 in", "in", "MyRefParam")
Wesley Crihfield
(Not an Autodesk Employee)