Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Is there a unit convert in iLogic?

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
chris
3286 Views, 12 Replies

Is there a unit convert in iLogic?

So we have some simply iLogic code that generates descriptions for some of our parts, but there are a few that  we need to show in another "unit". I tried to leave the description generic and then to "check" the export parameter in Parameters and to then format those specific one to their units of choice, but we can't make it work.... IV 2015 doesn't seem to like mixing the format parameter and illogic working together?

 

Other than actually doing the math within the iLogic code, is there not a snipet that allows a unit convert?

12 REPLIES 12
Message 2 of 13
jtylerbc
in reply to: chris

What problem are you having with it specifically?  I have at least 15 different template files that use iLogic to take measurements of the part extents, write them to a parameter in inches, and then use the Custom Property Format settings to ft-in format.  We've been using some version of this same setup since at least Inventor 2013.  We've never really had any trouble out of it.

Message 3 of 13
chris
in reply to: jtylerbc

okay, there is a dude here who has existing templates set up that have all descriptions written in iLogic, for what we do those dimensions have to be shown in (ft / in). I then showed him how to do the same thing with the <> in the description field and even how to "format" the outcome ... (how I've been doing it for years as well), but instead of redoing all the descriptions in the iproperties using the "pacman symbols" we used his iLogic code for the descriptions and then checked the "export" box for the parameters we needed to format.... problem is the units are not re-formatting...

Message 4 of 13
jtylerbc
in reply to: chris

Either I'm completely misunderstanding your explanation, or you're somewhat misunderstanding the way the Custom Property Format actually works.  My explanation here assumes the second - if it doesn't make sense, then maybe the first was true Smiley Wink.

 

When you Export a Parameter and use Custom Property Format, it creates a Custom iProperty with the same value as the Parameter, formatted according to the Custom Property Format settings. 

 

When you use the "pacman symbols" brackets in your Description, such as "SHAFT-<DIA> X <LENGTH>", what you are actually telling it to do is embed those Custom iProperty values into the Description.

 

If Dude's iLogic code just programmatically writes a string of text to the Description property that includes the Parameter values, then your Custom Property Format settings aren't even being used.  Not because something in Inventor isn't working properly, but because the code just isn't telling it to look in the right place to see the format.  The name "Custom Property Format" is literal - you're formatting the Custom iProperty, not the Parameter itself.

 

There are two ways I can see to make this work:

  1. Get rid of the iLogic code controlling the Description (or trim it down if it has other functions).  Use Embedded iProperties (pacman) instead.  In most cases this would be my preference, but I'm saying that without knowing the specifics of your situation. 
  2. Continue to use the iLogic code, but rewrite it so it pulls the value of the Custom iProperty into the Description instead of the Parameter.  It will be text, so you can't really use it for math purposes, but it will have the desired unit formatting.
Message 5 of 13
chris
in reply to: jtylerbc

Description1.PNGDescription2.PNGDescription3.PNGDescription4.PNGDescription5.PNG

Message 6 of 13
MechMachineMan
in reply to: chris

The iLogic code WILL NOT pull the "formatted" version from the parameter window. That formatting is exclusive to the "pacmans".

 

 

Take an example of a parameter named 'someparam' with an input "value" of "1 + .25 in", exposed, formatted to fraction WITH unit string.

 

Parameter.Param("someparam").Value pulls the decimal value in database units (the value converted to cms).

    - In this case, "3.175" is the return value.

 

Parameter.Param("someparam").Expression pulls 'expression' as it appears in the input box.

    - In this case, "1 in + 0.25 in" is the return value.

 

 

What you need to do for an "easy" fix for formatting is to get him to change his code from

 

 

iProperties.Value("Project", "Part Number") = "Size " & Parameter.Param("someparam").Value

to an expression form (with an "=" sign at the front, and using the pacman parameter name):

 

iProperties.Value("Project", "Part Number") = "=" & "Size " & "<someparam>"

OR

iProperties.Value("Project", "Part Number") = "=" & "Size <someparam>"

OR

iProperties.Value("Project", "Part Number") = "=Size <someparam>"

 

so then it will utilize the formatting as done in the parameter window..

 

 

Otherwise, he can custom format the value in the code and just assign it as a static value, but that's more complicated.


--------------------------------------
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
Message 7 of 13
Curtis_Waguespack
in reply to: chris

Hi @chris,

 

Here is one method of doing this:

https://forums.autodesk.com/t5/inventor-customization/ilogic-convert-decimal-to-fraction/m-p/6369069...

 

Note too that there is a forum dedicated to programming questions of this type:

 

Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

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

Message 8 of 13
chris
in reply to: Curtis_Waguespack

so I am /have been doing the parameters method < >, but now I can't seem to get everything typed in... is there a way to "over-ride" the default text length (256 characters) within the iproperties?

Message 9 of 13
jtylerbc
in reply to: chris

@chris, your pictures confirm that you're doing exactly what I thought you were.  Either of the proposed fixes from my previous post can potentially work for you.

 

The key thing you need to understand, as mentioned in my previous post, is that the Custom Property Format settings don't get applied to the Parameter at all.  They get applied to the Custom iProperty that is created by exporting the Parameter.  As written, your code and format settings are doing exactly what you are telling them to do.  The problem is that they're being told to do the wrong thing.

 

@MechMachineMan's proposed fix is a third option whose logic falls somewhere between my two suggestions.  It uses embedded property expressions, but uses iLogic code to write them for you. 

 

In my opinion, by using iLogic you're somewhat overcomplicating this.  If what you show in your post is the real code, and not just a simplified example, then the iLogic isn't doing anything for you that a simple iProperty expression wouldn't do.  Your code can be fixed, as mentioned, in multiple possible ways.  But the easiest fix may be to not use it at all.

Message 10 of 13
chris
in reply to: jtylerbc

the fix was it was allowing us to write out the description past 256 characters... because doing the iproperties method, (again, which I've always done), won't let me write everything out.... it's stops typing before I am finished typing.

 

=BEND, 5D, 90 DEG., <Elbow_OD>" x OD x <Elbow_WT>" WT, W/ <Elbow_Tangent_01>" x <Elbow_Tangent_02>" TAN, <Elbow_Radius>" RAD., (STOPS HERE)

 

what I need to type

 

=BEND, 5D, 90 DEG., <Elbow_OD>" x OD x <Elbow_WT>" WT, W/ <Elbow_Tangent_01>" x <Elbow_Tangent_02>" TAN, <Elbow_Radius>" RAD., API 5l X70

 

 

Message 11 of 13
jtylerbc
in reply to: chris

Without the iLogic you're actually only getting 126 characters.

 

In this more complex situation, using iLogic does make a lot of sense.  However, you might want to consider stepping back to my #2 proposed option from earlier.

 

The expression that is being written here is longer than its results would be.  For example, in the expression <Elbow_OD> takes up considerably more characters than the result, which may be as little as two characters (ex. 1").  So if the code pulls the text string from the Custom iProperty instead of writing the entire expression, the result that gets fed back to the Description field will be shorter.

 

For simplicity, going back to your bar example from earlier, the code could be something like:

 

ODProp = iProperties.Value("Custom", "OD")
LENGTHProp = iProperties.Value("Custom", "LENGTH")


iProperties.Value("Project", "Description") = "BAR, ROUND, " & ODProp & " x " & LENGTHProp & " LG."

 

In this example, the iProperty Expression would be the following, which includes 32 characters:

=BAR, ROUND, <OD> X <LENGTH> LG.

 

The Description pushed out from the iLogic code would be the following, which includes 28 characters:

BAR, ROUND, 1” X 3 1/16” LG.

 

 

This example only shaves off 4 characters.  However, your more realistic elbow example has both longer parameter names and more of them, so the reduction in length would probably be more noticeable.

Message 12 of 13
chris
in reply to: jtylerbc

is this a default limitation that can be changed in the registry.... like the default number of iPart rows? For now I can make my parameter names much shorter, lol

 

Message 13 of 13
aniketpunwatkar
in reply to: chris

Hello worked on it and found the answer to your query,works smoothly and solves your problem:

 

Dim doc As PartDocument
doc = ThisApplication.ActiveDocument
Dim unitsOfMeasure As UnitsOfMeasure
unitsOfMeasure = doc.UnitsOfMeasure

Dim lengthUnits As UnitsTypeEnum

lengthUnits = UnitsTypeEnum.kMillimeterLengthUnits

unitsOfMeasure.LengthUnits=lengthUnits


You can change the highlighted unit as per your requirement.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report