Expressions, how they really work

Integrated solution for design, manufacturing and management that provides all standard parts and procedures for wood processing.

Moderators: remi77, Daniel, jacs

quazoosl
Corporal
Corporal
Posts: 29
Joined: Thu Oct 10, 2019 12:41 pm
TopSolid Module: TopSolid'Design
TopSolid Version: 6.20

Expressions, how they really work

Unread post by quazoosl » Fri Feb 28, 2020 4:10 pm

Hi,

I didn't find the help file very useful for experssions, I've rewritten it for how they really seem work in v6.20

Code: Select all

Definitions:
	true		not 0
	false		0

Functions
	PI 		3.1415926535897932385
	COS(x)		Cosine of x degrees	
	SIN(x)		Sine of x degrees
	TAN(x)		Tangent of x degrees
	ACOS(x)		Arc cosine of x degrees
	ASIN(x)		Arc sine of x degrees
	ATAN(x)		Arc tangent of x degrees
	ATAN2(x,y)	ATAN(x/y)
	EXP(x)		e^x
	LN(x)		log_e⁡x
	LOG(x)		log_10⁡x
	SQRT(x)		√x
	ABS(x)		|x|
	MAX(x,y)	Returns largest value of x and y
	MIN(x,y)	Returns smallest value of x and y
	CEIL(x)		Rounds x off to closest higher whole number
	CEIL2(x,y)	Rounds x off to closest higher number divisible by y
	ROUND(x)	Rounds x off to closest whole number
	ROUND2(x,y)	Rounds x off to closest number divisible by y
	FLOOR(x)	Rounds x off to closest lower whole number
	FLOOR2(x,y)	Rounds x off to closest lower number divisible by y
	
Logic	(Logical functions and comparisons return 1 when true, and 0 when false)
	Functions
		AND(x,y)	x and y are true
		OR(x,y)		x or y is true
		NOT(x)		x is not true
		WHEN(x,y,z)	Returns y if x is true, z if x is false
		
	Comparison 	
		x==y		x is equal to y
		x>=y		x is larger than or equal to y
		x>y		x is larger than y
		x<=y		x is smaller than or equal to y
		x<y		x is smaller than y
		x!=y		x is not equal to y
Note: the amount of arguments is exact, so this does not work:

Code: Select all

and(x,y,z)

but this does:

Code: Select all

and(x,(and(y,z)) 

RaudMees
Master Chief
Master Chief
Posts: 138
Joined: Wed Dec 30, 2015 11:25 am
TopSolid Module: TopSolid'Wood
TopSolid Version: 6.20
Contact:

Re: Expressions, how they really work

Unread post by RaudMees » Fri Feb 28, 2020 10:27 pm

Hello

expressions in TS a bit strange for beginners. It's a mixture of several programming languages. I was in deep sh*t in the beginning, but now my expressions working well. Usually they are up to 20 characters long, but in some cases they can be more than 400 characters :)
For better understanding it's good to start with simple things. Rounding, switching components on/off etc.

RM

quazoosl
Corporal
Corporal
Posts: 29
Joined: Thu Oct 10, 2019 12:41 pm
TopSolid Module: TopSolid'Design
TopSolid Version: 6.20

Re: Expressions, how they really work

Unread post by quazoosl » Mon Mar 02, 2020 8:35 am

RaudMees wrote:
Fri Feb 28, 2020 10:27 pm
... Usually they are up to 20 characters long, but in some cases they can be more than 400 characters :) ...
I would try to avoid that. Having to figure out how a 400 character expression works is quite hard, even if you're the one that has made it. Not to mention having to figure out why it breaks. Why not cut it up into smaller pieces and refer to those?

User avatar
Derpomagix
Private First Class
Private First Class
Posts: 15
Joined: Thu Feb 14, 2019 6:10 pm
TopSolid Module: TopSolid'Wood
TopSolid Version: 6.18
Location: Toronto, Ontario, Canada, Earth, Milky Way, Universe, Multiverse
Contact:

Re: Expressions, how they really work

Unread post by Derpomagix » Mon Mar 02, 2020 1:46 pm

Personally, I have found that breaking expressions down into chunks to do specific jobs, and then calling them into a single function, works best.

Breaks a lot less and is generally more reliable.
- Derpomagix

RaudMees
Master Chief
Master Chief
Posts: 138
Joined: Wed Dec 30, 2015 11:25 am
TopSolid Module: TopSolid'Wood
TopSolid Version: 6.20
Contact:

Re: Expressions, how they really work

Unread post by RaudMees » Wed Mar 04, 2020 10:43 pm

In some cases its easier to read and handle when expressions is in one long line.
2 examples here:

when(num_9==1,pos_9+s_f_m,when(num_8==1,pos_8+s_f_m,when(num_7==1,pos_7+s_f_m,when(num_6==1,pos_6+s_f_m,when(num_5==1,pos_5+s_f_m,when(num_4==1,pos_4+s_f_m,when(num_3==1,pos_3+s_f_m,when(num_2==1,pos_2+s_f_m,when(num_1==1,pos_1+s_f_m,-o_f_ö_1)))))))))

when(d<300,1,when(d<501,2,when(d<701,3,when(d<900,0,0))))

RM

quazoosl
Corporal
Corporal
Posts: 29
Joined: Thu Oct 10, 2019 12:41 pm
TopSolid Module: TopSolid'Design
TopSolid Version: 6.20

Re: Expressions, how they really work

Unread post by quazoosl » Thu Mar 05, 2020 8:47 am

fair point, the expressions available are quite limited and sometimes you're going to have to make do.

If the num values are only ever 1 or 0 you could replace num_1==1 with just num_1 and keep the same functionality.

Personally I would probably split this up in two and something like this:

Code: Select all

chosen_pos 	when(num_9,pos_9,when(num_8,pos_8,when(num_7,pos_7,when(num_6,pos_6,when(num_5,pos_5,when(num_4,pos_4,when(num_3,pos_3,when(num_2,pos_2,when(num_1,pos_1,-o_f_ö_1)))))))))
pos_corrected	when(chosen_pos==-o_f_ö_1,chosen_pos,chosen_pos+s_f_m)
But to each his own of course :)

Post Reply