News:

When replying to a specific statement be sure to quote the previous post.

Main Menu
TurboCAD 2026 Platinum box
Now available

TurboCAD 2026.2

The latest update for TurboCAD 2026. It installs over any 2026 build and keeps your activation, drawings and settings. Get it from the Start Page or Help > Check for Update.

PPM Scripting, calling Macro Custom Function

Started by Alvin Gregorio, December 25, 2024, 05:25:05 PM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Alvin Gregorio

Can someone please tell me why this PPM script is not calling the Box.ppm correctly?
I have the Box.ppm in a folder named "Macro" which is in the same folder as this .ppm script.
The issue seems to start at Line 11, which reads
   "TableTop = Box(TableLength, TableWidth, TopThickness);".
And the issue probably occurs at every Line that has the Box text in it.


Box.ppm
Input(x0,y0,z0,x1,y1,z1)

R = Rectangle(x1-x0, y1-y0, (x0+x1)/2, (y0+y1)/2);
T = Thickness(R, z1-z0);
Output(Move(T, 0, 0, z0));

table top with four legs -001.ppm
Units(1[mm]); // Default unit of drawing is millimeters

TableLength = Parameter("Table Length", 1200.00, LINEAR);
TableWidth = Parameter("Table Width", 600.00, LINEAR);
TableHeight = Parameter("Table Height", 750.00, LINEAR);
LegThickness = Parameter("Leg Thickness", 50.00, LINEAR);

TopThickness = Parameter("Top Thickness", 25.00, LINEAR);

// Create the tabletop
TableTop = Box(TableLength, TableWidth, TopThickness);

// Position the tabletop
Move(TableTop, 0, 0, TableHeight - TopThickness);

// Create the four legs
Leg1 = Box(LegThickness, LegThickness, TableHeight - TopThickness);
Move(Leg1, 0, 0, 0);

Leg2 = Box(LegThickness, LegThickness, TableHeight - TopThickness);
Move(Leg2, TableLength - LegThickness, 0, 0);

Leg3 = Box(LegThickness, LegThickness, TableHeight - TopThickness);
Move(Leg3, 0, TableWidth - LegThickness, 0);

Leg4 = Box(LegThickness, LegThickness, TableHeight - TopThickness);
Move(Leg4, TableLength - LegThickness, TableWidth - LegThickness, 0);

// Combine the tabletop and legs
Table = BooleanUnion(TableTop, Leg1, Leg2, Leg3, Leg4);

// Output the final table
Output(Table);
Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

nikkipollard

#1
Alvin you have 6 Parameters for the Macro but you have only used 3 in the main file - You need to have a value for each parameter.
in the macro file - 5 commas
Input(x0,y0,z0,x1,y1,z1)

In the main file
3 parameters missing
TableTop = Box(TableLength, TableWidth, TopThickness);

I think your macro is trying to go from corner to corner.  I would define a corner to corner macro like this.

//Box macro corner to corner
//BoxA(x0,y0,z0,x1,y1,z1)

Units(1[mm])

//these values are for testing the macro they can be commented out when you know the macro works, as expected

x0 = 100 
y0 = 150
z0 = 25
x1 = 150
y1 = 200
z1 = 250


Input(x0,y0,z0,x1,y1,z1)


dx1 = x1-x0;
dx = IF(dx1<0,dx1 * -1,dx1);

dy1 = y1- y0;
dy = IF(dy1<0,dy1 * -1,dy1);

dz1 = z1 - z0;
dz = IF(dz1<0,dz1 * -1,dz1);

R = Move(Thickness(Rectangle(dx,dy),dz),0,0,-dz/2);

Show = Move(R,(x0+x1)/2,(y0+y1)/2,(z0+z1)/2);


Output(Show)



A macro that would work for your table

//Box macro using size and thickness
//BoxB(LengthX,LengthY,Depth)
Units(1[mm])
W = 100   //Length X
L = 150   //Length Y
D = 200   //Depth

Input(W,L,D)
R = Move(Thickness(Rectangle(W,L),D),0,0,-D/2)

Output(R)


Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

nikkipollard

Alvin Your main macro doesn't look right either.
When you move the parts you need an identifier

leg2 = Move(leg,x1,y1,z1)
This is what I did.


//Simple Rectangular Table

Units(1[mm]); // Default unit of drawing is millimeters

//Parameters
TableLength = Parameter("Table Length", 1200.00, LINEAR);
TableWidth = Parameter("Table Width", 600.00, LINEAR);
TableHeight = Parameter("Table Height", 750.00, LINEAR);
LegThickness = Parameter("Leg Thickness", 50.00, LINEAR);

TopThickness = Parameter("Top Thickness", 25.00, LINEAR);

// Create the tabletop
TableTop = BoxB(TableLength, TableWidth, TopThickness);

// Position the tabletop
tt1 = Move(TableTop, 0, 0, TableHeight - TopThickness/2);

//calculations
LH = TableHeight - TopThickness //leg height
Lt = LegThickness/2
TL2 = TableLength/2
TW2 = TableWidth/2

// Create the four legs
Leg = BoxB(LegThickness, LegThickness, LH);

l1= Move(Leg, - TL2 + Lt, - TW2 + Lt, LH/2);
l2= Move(Leg, - TL2 + Lt, TW2 - Lt, LH/2);
l3= Move(Leg, + TL2  - Lt, TW2 - Lt, LH/2);
l4= Move(Leg, + TL2 - Lt, - TW2 + Lt, LH/2);

// Combine the tabletop and legs
Table = BooleanUnion(tt1, l1, l2, l3, l4);

// Output the final table
Output(Table);



Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

nikkipollard

#3
Alvin here is how I would create the same Table using a box macro with 2 points as parameters


Point to Point  box macro


//Box macro corner to corner

//BoxA(Point(0,0,0),Point(0,0,0))

Units(1[mm])

//these values are for testing the macro they can be commented out when you know the macro works, as expected

P0 = Point(100,150,25)
P1 = Point(150,200,250)

//coordinates
x0 = PointX(P0)
y0 = PointY(P0)
z0 = PointZ(P0)
x1 = PointX(P1)
y1 = PointY(P1)
z1 = PointZ(P1)

Input(P0,P1)

//Side lengths - positive
dx1 = x1-x0;
dx = IF(dx1<0,dx1 * -1,dx1);

dy1 = y1- y0;
dy = IF(dy1<0,dy1 * -1,dy1);

dz1 = z1 - z0;
dz = IF(dz1<0,dz1 * -1,dz1);

R = Move(Thickness(Rectangle(dx,dy),dz),0,0,-dz/2);

Show = Move(R,(x0+x1)/2,(y0+y1)/2,(z0+z1)/2);


Output(Show)




Table ppm

//Simple Table ppm using a point to point box macro
Units(1[mm]); // Default unit of drawing is millimeters

TableLength = Parameter("Table Length", 1200.00, LINEAR);
TableWidth = Parameter("Table Width", 600.00, LINEAR);
TableHeight = Parameter("Table Height", 750.00, LINEAR);
LegThickness = Parameter("Leg Thickness", 50.00, LINEAR);

TopThickness = Parameter("Top Thickness", 25.00, LINEAR);

//BoxA(Point(0,0,0),Point(0,0,0))


//calculations
LH = TableHeight - TopThickness //leg height
TL2 = TableLength/2
TW2 = TableWidth/2

// Define the tabletop
TableTop = BoxA(Point(-TL2,-TW2,LH),Point(TL2,TW2,TableHeight));


// define the four legs
Leg1 = BoxA(Point(-TL2,-TW2,0),
            Point(-TL2+LegThickness,-TW2+LegThickness,LH));
Leg2 = BoxA(Point(-TL2,+TW2,0),
            Point(-TL2+LegThickness,+TW2-LegThickness,LH));
Leg3 = BoxA(Point(TL2,+TW2,0),
            Point(TL2-LegThickness,+TW2-LegThickness,LH));
Leg4 = BoxA(Point(TL2,-TW2,0),
            Point(TL2-LegThickness,-TW2+LegThickness,LH));



// Boolean add the  tabletop and legs
Table = BooleanUnion(TableTop, Leg1,Leg2,Leg3,Leg4);

// reference point
RefP = RefPoint(0,0)
// Output the final table and reference point
Output(RefP,Table);


Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Alvin Gregorio

#4
Thank you Nikki.

My script was created by MS_Copilot which MS automatically installed on my computer some time ago.
I did it for curiosity's sake-- to see what MS Copilot would create.  I had your table PPM script you shared some time ago in mind as a good test example.  I thought that maybe MS Copilot would find your post and simply replicate that.
I also assumed the Box.ppm custom function MS Copilot was calling in its script was the TurboCAD installation-supplied one.  So that's why I used that one.
________________
I've never been successful at using a PPM Custom Function.
I think because I've never been able to get the example in the User Guide* to work.  So I didn't have confidence in examining it to fully grasp it.
Examining what you provided here should get me to grasp PPM Custom Functions.



*User Guide Custom Function use Example:

Format:
<file name>(<list of input parameters>)

Below is an example of a custom function. The file box.ppm can be found in the PPM Documentation Samples/Macro folder:

// box.ppm – defines a custom Box function.
// The custom function is called in this way:
// B = Box(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
// The function creates a 3D box with given min/max values


Input(x0,y0,z0,x1,y1,z1);
R = Rectangle(x1-x0, y1-y0, // Rectangle with Xmin = x0, Xmax= x1
(x0+x1)/2, (y0+y1)/2); // Ymin = y0, Ymax = y1
T = Thickness(R, z1-z0); // depth = Zmax - Zmin
Output(Move(T, 0, 0, z0)); // move result along z to Zmin


The script below is 'box_ blend.ppm', which calls the custom function 'box.ppm':

//box_blend.ppm uses the custom Box.ppm function in the Macro folder.

x = Parameter("size", 5, LINEAR, GreaterThan(0));
r1 = Parameter("r1", 0.5, LINEAR, GreaterThan(0));
b0 = Box(0, 0, 0, x, x, x);
b1 = G3Fillet(b0, Point(x/2, 0, 0), Array(r1, r1*2));
Output(b1);


Someone really needs to fix the User Guide formatting.  The run-ons are ridiculous.
Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

nikkipollard

Alvin that box will work because there are 6 parameters. You need the same number of parameters in both scripts.

Examine the script of the box, provided by TC. It does work, it is just different to the Rectangle script, which has parameters  for a width a length and  x and y positions. (4 parameters) - the x and Y position are optional.

The example box script has parameters for coordinates. My BoxA macro has parameters for 2 Points - which is six coordinates in point form.

Your script seems to confuse the Box macro example, with the Rectangle Function.
and I guess the AI is has confused the SDK with ppms. ( - you can move )
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h