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: 

Trouble understanding = function

1 REPLY 1
SOLVED
Reply
Message 1 of 2
LF377951
115 Views, 1 Reply

Trouble understanding = function

I started learning Inventor last month and I only recently learned to write iLogic code a week ago. I am having a problem with understanding the = function because it seems to not work each time I use it. Both times I have encountered this issue I was trying to make the length of 2 objects equal to each other. I attached the form below so you can see what it looks like, as you can see there are two parts [BP and TP] and in the code I wrote:

 

BP_Length = TP_Length.

 

I then attempted to adjust BP_Length to be 100mm longer and it and the BP length immediately reverted, but the TP_Length increased to be 100mm longer. Then I reverted the length change and tried changing the TP_Length instead this time I was successful in changing BP_Length. 

 

The second time I attempted to two lengths equal I created two blocks and attempted to recreate the issue by writing the same code: Length = Length1. The same problem occurred where one dimension controlled the other but not vice versa. My solution was to write two lines of code instead. [Length = Length1] and [Length1 = Length]. I then tried to adjust the [Length] by 5mm, [Length1] increased by 5mm and [Length] reverted - the same problem as before had occurred. 

 

I showed the problem to my boss and he told me that i should create a user parameter and dimension both of the Lengths to it because "The Length's are fighting each other when they adjust". I created a new parameter Gen_Length and then dimension both Lengths to it and it worked. 

 

What I am wondering is how is this the case? I assume that the code is run in a manor in which the lines of code are executed from top to bottom and perhaps this is the issue - but I really have no clue when it comes to iLogic because I learned it from YouTube and copied code that my boss had copied. Would love any explanation you guys could give me or any pointers in the right direction for learning iLogic; if you have any questions on the code or you would like to see the code itself do not hesitate to ask.

 

Thanks,

Lewis

 

 

 

 

1 REPLY 1
Message 2 of 2
WCrihfield
in reply to: LF377951

Hi @LF377951.  I'm sure entire large, thick books could be created about all the various things there are to learn / know about automating Inventor with iLogic code.  But the specific behavior you are talking about here is essentially what you have already observed.  When you have two parameters or variables being used in one line of code, with the '=' character between them, the parameter or variable on the left will always be on the 'receiving side' of the transaction (getting its value 'set'), while the parameter or variable to the right of the '=' operator will always be on the 'sending side' of the transaction ('setting' its value to the one on the left of the '=' operator).  This is always a one way transaction, not both ways.  Just like in a sketch, if you have a vertical line in the middle of a square sketch, and you have a dimension to that line from the left edge of the square, and also have a dimension to it from the right edge of the square.  One must be 'driving' (normal, in control), while the other must be 'driven' (will usually have parenthesis around it, and be a slave, associated with a reference type parameter), because both can not be 'driving' the location of that line (when the square itself is fully constrained before hand).  The same is true in code, when using the '=' operator.  The one on the left side of the = is always receiving the value from the one on the right side of the =.  Your boss was correct about creating a UserParameter to use as a common length, that should be referenced by both size controlling dimensions, if both sizes need to always be the same.  ModelParameters will come and go when you create or delete features, or sketch dimensions, and things like that, but UserParameters will stay there when those things come and go, so they are usually more stable to use when you want more intelligent control over your designs.  Especially when iLogic rules get involved, which will be working with those values.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report