Thanks @snabela , it definitely helped but after all successful calls the result is from the default model. The customisation has no any affect on the export data, always returns the default model export data.
Please see below our work-around in Python, it might also help other guys to experiment with the geometry API.
import configparser
import json
import tempfile
import requests
import os
import datetime
mainConfig = configparser.ConfigParser()
mainConfig.read('config.ini')
sd_base_url = mainConfig['dependencies']['shapediver_geometry_url']
def datetime_to_string(o):
if isinstance(o, datetime.datetime):
return o.__str__()
def get_session_id(structure_dict):
sd_ticket_backend = structure_dict["product"]['sdTicketBackEnd']
sd_ticket_url = os.path.join(
sd_base_url, 'api/v2/ticket', sd_ticket_backend)
full_data = requests.post(sd_ticket_url).json()
session_id = full_data["sessionId"]
params = full_data["parameters"]
# get the ID of the InputFromUI input
for id, param in params.items():
if param["name"] == "InputFromUI":
input_param_id = id
return session_id, input_param_id
def write_structure_to_file(structure_dict, temp_file):
try:
json.dump(structure_dict, temp_file)
temp_file.flush()
return temp_file
except ValueError:
print("Could not write file.")
def file_upload_url(input_param_id, session_id, size):
sd_query_upload_url = os.path.join(
sd_base_url,
'api/v2/session',
# session_id,
session_id,
'file/upload'
)
headers = {
'Content-Type': 'application/json'
}
payload = json.dumps({
input_param_id: {
"format": "text/plain",
"size": str(size)
}
})
upload_url = requests.post(
sd_query_upload_url, headers=headers, data=payload)
up_url = upload_url.json()["asset"]["file"][input_param_id]["href"]
file_id = upload_url.json()["asset"]["file"][input_param_id]["id"]
return up_url, file_id
def file_upload(href, file_path):
#open text file in read mode
text_file = open(file_path, "r")
#read whole file to a string
data = text_file.read()
print(data)
headers = {
'Content-Type': 'text/plain'
}
response = requests.request("PUT", href, headers=headers, data=data)
text_file.close()
return response.status_code
def customization_request(session_id, input_param_id, file_id):
sd_base_url = mainConfig['dependencies']['shapediver_geometry_url']
sd_output_url = os.path.join(
sd_base_url, 'api/v2/session/{}/output'.format(session_id))
data = json.dumps({input_param_id: file_id})
headers = {'Content-type': 'text/plain'}
print(data)
sd_object = requests.put(
sd_output_url, headers=headers, data=data)
outputs = sd_object.json()["outputs"]
params = []
for key, param in outputs.items():
if len(param["content"]) > 0:
params.append(param["content"][0])
return params
then we try to use these methods to query the parameters:
# call SD for sessionId
session_id, input_param_id = get_session_id(structure_data)
tempfile_struct = tempfile.NamedTemporaryFile(mode="w+")
temp_file = write_structure_to_file(string_data, tempfile_struct)
f_size = os.stat(temp_file.name).st_size
f_upload_url, file_id = file_upload_url(
input_param_id, session_id, f_size)
resp_upload_status = file_upload(f_upload_url, temp_file.name)
temp_file.close()
if session_id and resp_upload_status == 200:
print('Customizing...')
params = customization_request(
session_id, input_param_id, file_id)
return params
Could you please guide us to make this work?
Looping @Jonas_Modling to this post.