iLogic for inserting parentheses to parameters

iLogic for inserting parentheses to parameters

mjp.purdy
Enthusiast Enthusiast
831 Views
3 Replies
Message 1 of 4

iLogic for inserting parentheses to parameters

mjp.purdy
Enthusiast
Enthusiast

Hello!

 

I have an ilogic rule I snagged to add a ratio to every dimension in the parameters list, creating a part which is truly scaled. This changes the physical sketch dimensions, which is great in case I want to modify the actual dimension after the scaling; I found it more difficult with Inventor's organic scaling. Problem is, I did a lot of "1+1/4" improper fractions, which is an issue. For instance, when scaling the part to 1/2, it inserts the ratio at the beginning of the equation, thus what should be .5*1.25=.625 comes out as .5*1+1/4=.75. I could manually enter parentheses, but I have close to 3000 dimensions to go through, and I should probably get a handle on ilogic anyways. This is for a single part file.

 

I simply need to make a formula which inserts a forward parentheses at the beginning of each parameter and a rearward at the end. At first I was thinking it was simple, and maybe there's a simple way of doing it, but I'm having the worst luck trying to extract the parts I need from the parent equations. The end result would call up each dimension and turn 1+1/4 into (1+1/4). 

 

My head spins when I get too far into iLogic. If it's not too much trouble, I could use a push in the right direction.

 

Thanks guys. 

 

The rule I'm using for scaling was taken from here:

https://www.cadlinecommunity.co.uk/hc/en-us/articles/201893932-Inventor-2014-iLogic-Scale-Entire-Inv...

 

0 Likes
Accepted solutions (1)
832 Views
3 Replies
Replies (3)
Message 2 of 4

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, excuse me for not understanding well what you need. Here I leave an ilogic rule that will insert a parameter forward and one back in the expression of each parameter on your part.

 

Dim doc As Document= ThisDoc.Document

For Each oParam As Parameter In doc.componentdefinition.parameters
	oParam.Expression = "(" & oParam.Expression & ")"
Next

Parameter.UpdateAfterChange = True
iLogicVb.UpdateWhenDone = True

 I hope this method can give you some help. Regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 3 of 4

mjp.purdy
Enthusiast
Enthusiast

That worked perfectly! Thanks!

 

I think I understand the first and last lines; the first defining the target of what you want to change, the second to last makes the actual changes to the parameters, and the last line obviously refreshes the document so the dimensions in the parameters reflect the ones in the part file itself.

 

This part makes sense to me:

oParam.Expression = "(" & oParam.Expression & ")"

This part is a bit confusing:

For Each oParam As Parameter In doc.componentdefinition.parameters

"For Each" I assume just  makes sure the expression hits every line in the parameter table. the "doc.componentdefinition.parameters" again targets the document parameters.

 

How does the "As Parameter In" work out? I'm having a hard time searching for what the "As" expression does, seems to be a common word, haha. 

 

By all means, if I'm wrong somewhere, say so. I'd like to learn so I don't have to bug the board every time I have an iLogic problem.

0 Likes
Message 4 of 4

Sergio.D.Suárez
Mentor
Mentor

Sorry for the delay in responding. In programming in general, you always have to define the variable, I think that in ilogic you can remove the "As parameter", I recommend that you get used to using it. For example, in VBA you should always define the variable, although with some differences in the code between VBA and ilogic.
What that line does is to take all the parameters of the part and place each one in synthesis.
See the help of the inventor API, although it is focused on VBA its extension to ilogic is similar.Alli will find the different objects
I hope I was clear. Regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes