iLogic convert decimal to fraction

iLogic convert decimal to fraction

Anonymous
Not applicable
3,185 Views
6 Replies
Message 1 of 7

iLogic convert decimal to fraction

Anonymous
Not applicable

Happy Monday All,

   So Neil helped me to string together part descriptions in iLogic and pass them to the description field in iProperties.

Example: 

iProperties.Value("Project", "Description") = Thickness & " " & Material & " x " & Width & " in. x " & Length & " in. Lg."

 My question now is can I have the values displayed in the "Description" field as fractions instead of decimal values and how would my code read. I found the "FormatAsFraction" function under the "String" snippets but can't seem to get the syntax right. Thanks to all for you patience and assistance. Have a great week.

 

Frank

0 Likes
Accepted solutions (2)
3,186 Views
6 Replies
Replies (6)
Message 2 of 7

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi frank,

 

Try something like this:

 

'variables/values that would come from the model
Material = "Steel"
Thickness = .125
Width = 1.5
Length = 6.25

'convert values to fraction
oT = FormatAsFraction(Thickness)
oW = FormatAsFraction(Width)
oL = FormatAsFraction(Length)

'set description
iProperties.Value("Project", "Description") = _
oT & " " & Material & " x " & oW & " in. x " & oL & " in. Lg."

'display to user
MessageBox.Show("Description: " & vbLf & _
iProperties.Value("Project", "Description"), "iLogic")

 

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 3 of 7

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Or something like this if you need to control the precision:

 

 

'variables/values that would come from the model
Material = "Steel"
Thickness = 0.103587
Width = 1.5625
Length = 6.3987

'convert values to fraction
oT = RoundToFraction(Thickness, 1/8, RoundingMethod.RoundUp)
oW = RoundToFraction(Width, 1/16, RoundingMethod.RoundUp)
oL = RoundToFraction(Length, 1/32, RoundingMethod.RoundUp)

'set description
iProperties.Value("Project", "Description") = _
oT & " " & Material & " x " & oW & " in. x " & oL & " in. Lg."

'display to user
MessageBox.Show("Description: " & vbLf & _
iProperties.Value("Project", "Description"), "iLogic")

EESignature

Message 4 of 7

Anonymous
Not applicable

Curtis,

 

Second example worked like a charm once I got the syntax correct. I really appreciate the assistance. I've watched all the tutorial videos I could on iLogic and couldn't put it together until I saw it applied to what I was doing. All of the stuff in the videos was all theoretical and kind of abstract to me. I think for myself, it all started to come together when I saw it applied to what I'm doing. Thanks again for your help.

 

Frank

Message 5 of 7

Anonymous
Not applicable

How do you do all this in VBA since if you use RoundToFraction(Variable,1/64, RoundingMethod.Round) it throws an error that the Function isn't defined.

Any insight anyone?

0 Likes
Message 6 of 7

Anonymous
Not applicable

You stick to VB.net or iLogic or create your own function in VBA?

 

https://stackoverflow.com/questions/706468/how-can-i-convert-a-decimal-to-a-fraction

 

 

 

0 Likes
Message 7 of 7

MechMachineMan
Advisor
Advisor

The other option:

 

- Set your parameters up as "Exposed" and use the Custom Property Format to set the unit display as desired.

 

- Revise your code to look like this:

 

iProperties.Value("Project", "Description") = "=" & "<Thickness> <Material> x <Width> in. x <Length> Lg."

This utilizes the iProperty expressions (which will show up beside the iProperty as "fx")


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type