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

what would I need to add to this iLogic code to make the answer show up in the parameters as a reference dimension?

chris
Advisor

what would I need to add to this iLogic code to make the answer show up in the parameters as a reference dimension?

chris
Advisor
Advisor

chris_0-1686421120178.png

 

0 Likes
Reply
356 Views
6 Replies
Replies (6)

martin_winkler
Advisor
Advisor

Why should this be a reference parameter? You can write the value in a Text type custom parameter. Or into a custom iProperty.

0 Likes

chris
Advisor
Advisor

@martin_winkler 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

0 Likes

A.Acheson
Mentor
Mentor

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. 

AAcheson_0-1686536447832.png

 

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.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes

Curtis_Waguespack
Consultant
Consultant

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

0 Likes

Frederick_Law
Mentor
Mentor

Or add it to 'User Parameter'

0 Likes

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)