Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Curtis_Waguespack
in reply to: chris

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