## Turbo Talk => General Discussion => Topic started by: necronian on July 10, 2017, 06:19:19 AM

Title: Parametric Part Scripts: Line Bores
Post by: necronian on July 10, 2017, 06:19:19 AM
I'm trying to add linebores for shelving to my parametric parts. What I want to do is draw a series of circles 5mm in diameter 32mm apart, the number and location of circle is determined by the inside height of my cabinet. So if I have a cabinet 66" high I can fit 52 holes in my linebore. Then to find the starting center location of my first hole would be the difference between the height and 52*32mm divided by 2. (66-(52*32mm))/2. I place my first hole at 0.2440944882" then draw 51 more holes 32mm apart.

However I can't figure out how to find the starting location for my first hole, the PPM doesn't seem to have a Floor or Int function. I saw that there was a Mod function which I could have used but it only supports integers. Is there a way to achieve what I am looking for?
Title: Re: Parametric Part Scripts: Line Bores
Post by: Torfinn on July 10, 2017, 09:12:00 AM
If you round UP, maybe attached can be a workaround.

Torfinn
Title: Re: Parametric Part Scripts: Line Bores
Post by: nikkipollard on July 10, 2017, 09:29:55 AM
I am surprised that there isn't a floor function. There is one in the calculator palette.
I use floor with the other method of creating parametric symbols.
Title: Re: Parametric Part Scripts: Line Bores
Post by: Torfinn on July 10, 2017, 09:43:13 AM
I am not sure what you guys meen with Floor, but guess it is to the top of Bottomplate in the cabinet, in ppm we write that ourself, it is the last Parameter in the PPM i showed.

Torfinn
Title: Re: Parametric Part Scripts: Line Bores
Post by: necronian on July 10, 2017, 09:45:53 AM
I CAN'T SOLVE THE CAPTCHA! I'm as dumb as a robot.

nikkipollard: I know it's crazy, but Floor() doesn't work and I tried floor() but that consistently crashes Turbocad. The only usable documentation I found is at http://www3.turbocadcommunity.com/tiki-index.php?page=Parametric+Part+Manager and there isn't much to it.

Thanks Torfinn, but the issue I have is that I don't know the size ahead of time. The idea is for this to be a part of a much larger assembly, I'm getting the size by passing in another part and grabbing the Extents. We use tongue and groove construction, for example here is the working groove macro I wrote:

Input(part,groove_offset,thickness,part_offset,side);

x1=ExtentsX1(part);
x2=ExtentsX2(part);
y1=ExtentsY1(part);
y2=ExtentsY2(part);

LeftGroove = SetProperties(
Polyline(
Point(x1+part_offset+thickness,y2-groove_offset),
Point(x1+part_offset+thickness,y1+groove_offset)
),
"Layer"="GROOVE");

RightGroove = SetProperties(
Polyline(
Point(x2-part_offset-thickness,y1+groove_offset),
Point(x2-part_offset-thickness,y2-groove_offset)
),
"Layer"="GROOVE");

TopGroove = SetProperties(
Polyline(
Point(x2-groove_offset,y2-part_offset-thickness),
Point(x1+groove_offset,y2-part_offset-thickness)
),
"Layer"="GROOVE");

BottomGroove = SetProperties(
Polyline(
Point(x1+groove_offset,y1+part_offset+thickness),
Point(x2-groove_offset,y1+part_offset+thickness)
),
"Layer"="GROOVE");

NOGROOVE=Group();

Output(
IF(side==1,LeftGroove,
IF(side==3,RightGroove,
IF(side==2,TopGroove,
IF(side==4,BottomGroove,
NOGROOVE)))));
Title: Re: Parametric Part Scripts: Line Bores
Post by: Torfinn on July 10, 2017, 10:46:53 AM
Thanks, then i understand, but i still dont know what you meen with Floor in a ppm :)
And Floor is not a command, by the list of legal commands.

Torfinn

Edit;
Now i know ;)
Title: Re: Parametric Part Scripts: Line Bores
Post by: necronian on July 10, 2017, 11:50:43 AM
Floor and Ceil are math functions in most spreadsheets, programming languages, etc. Floor finds the largest integer less than or equal to the input so floor(5), floor(5.4) and floor(5.9999) all will return 5. Ceil is essentially the opposite operation.

I was complaining to a friend and he said that if turbocad is using IEEE double I can try to take advantage of that to round to the nearest integer. I tried it and it seems to work, although I'm not super happy with the solution because it's a hack.

Try,
c = 4503599627370496; //MAGIC NUMBER!
intermediate = 2.4 + c;
rounded = intermediate - c;

Fnt = TextFont(0,300,0,"Arial");
Fsty = TextStyle(MIDDLE, TOP, ITALIC, BOLD);

Output(Text(""+rounded+"", Fnt, Fsty));

The number 4503599627370496 is 2^52, which is the size of the mantissa of a double. I think. To be honest my grasp of floating point numbers isn't great and mostly half remembered from my long ago computer architecture courses in college.

Title: Re: Parametric Part Scripts: Line Bores
Post by: Torfinn on July 10, 2017, 01:36:17 PM
necronian, THANK YOU !

That was truly a magic number :)
Then we can just make our own Floor and Ceiling ppm function, very nice.

Torfinn
Title: Re: Parametric Part Scripts: Line Bores
Post by: nikkipollard on February 16, 2018, 11:48:38 PM
I am sorry for revisiting an old thread.
This works for rounding off a number how do you use it for finding the floor or ceiling?
Title: Re: Parametric Part Scripts: Line Bores
Post by: nikkipollard on February 17, 2018, 12:24:28 AM
Hopefully I figured out another way,
Mod might work for me to work out the "ceiling" when dividing 2 numbers.
I am not a maths genius so I could be way off.

Use mod to find out the remainder
c=Mod(1000,170);
work out the difference between the "divisor" and the "remainder"
d=170-c
e=1000+d
ceiling=e/170

It doesn't work if there isn't a remainder though. IF solves that.

Title: Re: Parametric Part Scripts: Line Bores
Post by: Torfinn on February 17, 2018, 04:01:42 AM
A typo i guess, as Mod use , not /
c=Mod(1000,170); will work

Torfinn
Title: Re: Parametric Part Scripts: Line Bores
Post by: nikkipollard on February 17, 2018, 10:05:29 PM
Yes thanks