-
Notifications
You must be signed in to change notification settings - Fork 1
/
modelderivative.ts
218 lines (188 loc) · 6.05 KB
/
modelderivative.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import { ApiResponse, ApsConfiguration, ApsServiceRequestConfig, SdkManager, SdkManagerBuilder } from "@aps_sdk/autodesk-sdkmanager"
import { BeginsWith, Between, DeleteManifest, DerivativeDownload, EqualsTo, JobPayloadFormatAdvancedThumbnail, JobPayloadFormatSVFAdvancedRVT, MatchId, MatchIdType, ModelDerivativeClient } from "@aps_sdk/model-derivative";
import { InformationalApi, SupportedFormats, JobPayloadFormatThumbnail, ExtractorVersion, JobPayloadFormatSVF2AdvancedRVT, Model2dView, JobPayloadFormatSVF2AdvancedIFC, BuildingStoreys, Width, Height, JobPayloadFormatSVFAdvancedIFC, Job, XAdsDerivativeFormat, Region, OutputType, Manifest, ModelViews, ObjectTree, ModelViewsDataMetadata, Properties, SpecificPropertiesPayload, SpecificPropertiesPayloadQuery, Payload, SpecificProperties } from "@aps_sdk/model-derivative";
import { JobPayloadOutputDestination, JobsApi, JobPayload, JobPayloadOutput, JobPayloadInput, JobPayloadFormat, JobPayloadFormatSVF2, JobPayloadFormatSVF, View } from "@aps_sdk/model-derivative";
import 'dotenv/config';
const sdkmanager: SdkManager = SdkManagerBuilder.create().build();
const modelDerivativeClient = new ModelDerivativeClient(sdkmanager);
const accessToken: string = process.env.accessToken;
const urn: string = process.env.urn;
const derivativeUrn = process.env.derivativeUrn;
const modelGuid = process.env.modelGuid;
//#region Informational
/**
* Function to fetch all supported formats
*/
async function getFormats() {
try {
const formats: SupportedFormats = await modelDerivativeClient.getFormats(accessToken);
console.log(formats);
}
catch (error) {
console.error(error);
}
}
//#endregion
//#region Jobs
/**
* Function to start a translation job
*/
async function startjob() {
try {
// initialise svf2 output format with desired options
const svfPayloadFormat: JobPayloadFormatSVF = {
views: [View._2d, View._3d],
type: OutputType.Svf,
// optional advanced options
advanced: <JobPayloadFormatSVFAdvancedRVT>{ _2dviews: Model2dView.Legacy, generateMasterViews: true, extractorVersion: ExtractorVersion.Next }
};
// initialise thumbnail output format with desired options
const thumbnailPayloadformat: JobPayloadFormatThumbnail = {
type: OutputType.Thumbnail,
advanced: <JobPayloadFormatAdvancedThumbnail>{ width: Width[100], height: Height[200] }
};
const jobPayload: JobPayload = {
input: <JobPayloadInput>{ urn: urn, compressedUrn: false }, //, rootfileName: '<>'
output: <JobPayloadOutput>{
formats: [svfPayloadFormat, thumbnailPayloadformat],
}
};
let job: Job = await modelDerivativeClient.startJob(accessToken, jobPayload);
let result = job.result;
console.log(job);
}
catch (error) {
console.error(error);
}
}
//#endregion
//#region Manifest
/**
* Function to fetch Manifest
*/
async function getManifest() {
try {
let manifest: Manifest = await modelDerivativeClient.getManifest(accessToken, urn, { region: Region.Us });
let hasThumbnail = manifest.hasThumbnail;
}
catch (error) {
console.error(error);
}
}
async function deleteManifest() {
try {
let result: DeleteManifest = await modelDerivativeClient.deleteManifest(accessToken, urn);
}
catch (error) {
console.error(error);
}
}
//#endregion
//#region Derivatives
/**
* Function that returns the downloadable url
*/
async function getDerivativeUrl() {
try {
let derivativeDownload: DerivativeDownload = await modelDerivativeClient.getDerivativeUrl(accessToken, derivativeUrn, urn);
console.log(derivativeDownload.url);
}
catch (error) {
console.error(error);
}
}
async function getDerivativeHeaders() {
try {
let derivativeHeaders: ApiResponse = await modelDerivativeClient.headCheckDerivative(accessToken, urn, derivativeUrn);
console.log(derivativeHeaders.response.headers);
}
catch (error) {
console.error(error);
}
}
//#endregion
//#region MetaData API
/**
* Function to get list of Model views
*/
async function getModelViews() {
try {
let modelViews: ModelViews = await modelDerivativeClient.getModelViews(accessToken, urn);
let guid = modelViews.data.metadata[1].guid;
} catch (error) {
console.error(error);
}
}
/**
* Function to fetch Object tree
*/
async function getObjectTree() {
try {
let objectTree: ObjectTree = await modelDerivativeClient.getObjectTree(accessToken, urn, modelGuid);
if (objectTree.isProcessing) {
console.log(" 202 response. Call the endpoint again or iteratively to get 200 OK.");
return;
}
for (let x of objectTree.data.objects[0].objects) {
console.log(x.name);
}
} catch (error) {
console.error(error);
}
}
/**
* Function to fetch all properties
*/
async function getAllProperties() {
try {
let allProperties: Properties = await modelDerivativeClient.getAllProperties(accessToken, urn, modelGuid)
if (allProperties.isProcessing) {
console.log(" 202 response. Call the endpoint again or iteratively to get 200 OK.");
}
}
catch (error) {
console.error(error);
}
}
/**
* Function to fetch specific properties
*/
async function fetchSpecificProperties() {
try {
// Specify the request payload
const specificPropertiesPayload: SpecificPropertiesPayload = {
fields: ["objectid", "name"],
query: <MatchId>{$in: [MatchIdType.ObjectId,2646]}
};
let specificProps: SpecificProperties = await modelDerivativeClient.fetchSpecificProperties(accessToken, urn, modelGuid, specificPropertiesPayload);
console.log(specificProps);
}
catch (error) {
console.error(error);
}
}
//#endregion
//#region Thumbnail
/**
* Function to fetch thumbnail
*/
async function getThumbnail() {
try {
let response = await modelDerivativeClient.getThumbnail(accessToken, urn);
}
catch (error) {
console.error(error);
}
}
//#endregion
//startjob();
// getFormats();
// getManifest();
// deleteManifest();
// getThumbnail();
// getDerivativeUrl();
// getDerivativeHeaders();
// getModelViews();
// getObjectTree();
// getAllProperties();
// fetchSpecificProperties();