TurboCAD Forums

The Ultimate Resource for TurboCAD Knowledge

Register
 
When posting a problem be sure to include which version you are using.  Give as much information as possible.  If the problem is with a specific file be sure to attache it to your post.

Parametric Part Scripts: Line Bores
Read 349 times
* 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?

Logged


* July 10, 2017, 09:12:00 AM
#1
If you round UP, maybe attached can be a workaround.

Torfinn

Logged
V18, V19, V20, V21, 2015 Pro. Platinum
Deluxe V20, V21, 2015
RedSDK enabled
Windows 10 Home Premium 64 bit, 32 GB
NVIDIA Geforce GTX 780m, 1 GB


* July 10, 2017, 09:29:55 AM
#2
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.

Logged
Nikki
TC20 platinum
TC 2015 platinum
TC 2017 with lightworks


* July 10, 2017, 09:43:13 AM
#3
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

Logged
V18, V19, V20, V21, 2015 Pro. Platinum
Deluxe V20, V21, 2015
RedSDK enabled
Windows 10 Home Premium 64 bit, 32 GB
NVIDIA Geforce GTX 780m, 1 GB


* July 10, 2017, 09:45:53 AM
#4
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)))));

Logged


* July 10, 2017, 10:46:53 AM
#5
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 ;)
« Last Edit: July 10, 2017, 11:47:55 AM by Torfinn »

Logged
V18, V19, V20, V21, 2015 Pro. Platinum
Deluxe V20, V21, 2015
RedSDK enabled
Windows 10 Home Premium 64 bit, 32 GB
NVIDIA Geforce GTX 780m, 1 GB


* July 10, 2017, 11:50:43 AM
#6
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.


Logged


* July 10, 2017, 01:36:17 PM
#7
necronian, THANK YOU !

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

Torfinn

Logged
V18, V19, V20, V21, 2015 Pro. Platinum
Deluxe V20, V21, 2015
RedSDK enabled
Windows 10 Home Premium 64 bit, 32 GB
NVIDIA Geforce GTX 780m, 1 GB