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

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
403 Views
6 Replies
Message 1 of 7

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
404 Views
6 Replies
Replies (6)
Message 2 of 7

Martin-Winkler-Consulting
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.

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.


EESignature

0 Likes
Message 3 of 7

chris
Advisor
Advisor

@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

0 Likes
Message 4 of 7

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
Message 5 of 7

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

EESignature

0 Likes
Message 6 of 7

Frederick_Law
Mentor
Mentor

Or add it to 'User Parameter'

0 Likes
Message 7 of 7

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)