-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-profile-trusses.ts
166 lines (139 loc) · 3.15 KB
/
create-profile-trusses.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//// API Route Configuration
const paragonApiBaseUrl = "https://designserver.paragontruss.com/api/public";
const paragonApiHeaders = {
Authorization: `JWT ${process.env.PARAGON_API_KEY}`,
"Content-Type": "application/json",
};
//// Main function
async function main() {
console.log("Creating project...");
const project = await createProject({ name: "API Test Project" });
console.log("Creating truss...");
const truss = await createTruss(project.guid, {
name: "RT-1",
topChordPoints: [
{ x: 0, y: 4.163118960624631 },
{ x: 144, y: 76.1631189606246 },
{ x: 288, y: 4.163118960624631 },
],
bottomChordPoints: [
{ x: 0, y: 0 },
{ x: 288, y: 0 },
],
leftOverhang: { distance: 24 },
rightOverhang: { distance: 24 },
});
console.log(`Successfully created truss!`);
console.log(`Project URL: https://design.paragontruss.com/${project.guid}`);
}
main().catch(console.error);
//// POST /projects route
async function createProject(project: NewProject): Promise<Project> {
const response = await fetch(`${paragonApiBaseUrl}/projects`, {
method: "POST",
headers: paragonApiHeaders,
body: JSON.stringify(project),
});
return await response.json();
}
interface NewProject {
name: string;
}
interface Project extends NewProject {
guid: string;
}
//// POST /createProfileTruss route
async function createTruss(
projectGuid: string,
profile: Profile,
): Promise<string> {
const response = await fetch(
`${paragonApiBaseUrl}/projects/${projectGuid}/createProfileTruss`,
{
method: "POST",
headers: paragonApiHeaders,
body: JSON.stringify(profile),
},
);
return await response.json();
}
//// Profile type
interface Profile {
name: string;
topChordPoints: Point2D[];
bottomChordPoints: Point2D[];
leftOverhang: Overhang;
rightOverhang: Overhang;
}
interface Overhang {
distance: number;
cutType?: "Plumb" | "Square" | "Horizontal" | null;
}
//// Truss type
interface Truss {
guid: string;
name: string;
plies: number;
members: Member[];
plates: Plate[];
bearings: Bearing[];
outsideToOutsideBearingSpan: number;
height: number;
width: number;
}
interface Member {
guid: string;
name: string;
assemblyName: string;
type: string;
lumber: Lumber;
geometry: Point2D[];
thickness: number;
overallLength: number;
bevelCuts: Plane3D[];
}
interface Lumber {
actualThickness: number;
actualWidth: number;
nominalWidth: number;
nominalThickness: number;
grade: string;
species: string;
structure: "Sawn" | "StructuralComposite";
treatmentType: string;
}
interface Plate {
guid: string;
name: string;
type: string;
center: Point2D;
length: number;
width: number;
plateOrientation: "FrontBack" | "TopBottom";
slotDirection: Direction3D;
normalDirection: Direction3D;
}
interface Bearing {
guid: string;
geometry: Segment2D;
}
//// Geometry types
interface Point2D {
x: number;
y: number;
}
interface Plane3D {
a: number;
b: number;
c: number;
d: number;
}
interface Direction3D {
x: number;
y: number;
z: number;
}
interface Segment2D {
basePoint: Point2D;
endPoint: Point2D;
}