From ee9f45c23cfb262cca77bc5b674b0b0850bec5b7 Mon Sep 17 00:00:00 2001 From: Alan Rynne Date: Thu, 1 Jul 2021 16:23:35 +0200 Subject: [PATCH] Python script + minor changes --- CSharpStarter/Program.cs | 9 +++++++ PythonStarter/test.py | 51 ++++++++++++++++++++++++++++++++++++++++ WebStarter/app.js | 19 +++++++++++++-- 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 PythonStarter/test.py diff --git a/CSharpStarter/Program.cs b/CSharpStarter/Program.cs index 630b99e..05c4895 100644 --- a/CSharpStarter/Program.cs +++ b/CSharpStarter/Program.cs @@ -26,6 +26,15 @@ namespace CSharpStarter commitObj["myProp"] = "myPropValue"; commitObj["myOtherProp"] = new List { "A", "list", "of", "values" }; + var boxes = new List(); + for (int i = 0; i < 10; i++) + { + for (int j = 0; j < 10; j++) + { + boxes.Add(new Point(i, j, 0)); + } + } + commitObj["boxes"] = boxes; // Send the object to Speckle, get back the commit id var commitId = Helpers.Send("2d9b814ed6", commitObj, "Upload from my console app", null, 0, defaultAccount, false).Result; diff --git a/PythonStarter/test.py b/PythonStarter/test.py new file mode 100644 index 0000000..8cc71d0 --- /dev/null +++ b/PythonStarter/test.py @@ -0,0 +1,51 @@ +from specklepy.api.client import SpeckleClient +from specklepy.api.credentials import get_default_account, get_local_accounts +from specklepy.transports.server import ServerTransport +from specklepy.api import operations + +# Initialise the Speckle client pointing to your specific server. +client = SpeckleClient(host="https://speckle.xyz") + +# Get the default account +# If you have more than one account, or the account is not the default, use get_local_accounts +account = get_default_account() + +# Authenticate using the account token +client.authenticate(token=account.token) + +# Your account email +print('Welcome!!',account.userInfo.email, account.serverInfo.url) + + +# use that stream id to get the stream from the server +streamId = "42c06de34f" +branch = client.branch.get(streamId, "main", 1) +hash = branch.commits.items[0].referencedObject + + + + +# next create a server transport - this is the vehicle through which you will send and receive +transport = ServerTransport(client=client, stream_id=streamId) + +# this receives the object back from the transport. +# the received data will be deserialised back into a `Block` +received_base = operations.receive(obj_id=hash, remote_transport=transport) + +for list in received_base["@data"]: + for item in list: + item.z += 1 + + +# this serialises the modified points and sends it to the transport +hash = operations.send(base=received_base, transports=[transport]) + +# you can now create a commit on your stream with this object +commit_id = client.commit.create( + stream_id=streamId, + branch_name="python", + object_id=hash, + message="Points were modified by AECTechDemo.py script", + ) + +print("Successfully created commit with id:", commit_id) \ No newline at end of file diff --git a/WebStarter/app.js b/WebStarter/app.js index 442c951..5acb9d2 100644 --- a/WebStarter/app.js +++ b/WebStarter/app.js @@ -1,7 +1,22 @@ -console.log("Hello Speckle!") - +let token = "096315ee1bf8c961444b270746becd1e8474baa79e" +let objUrl = + "http://localhost:3000/streams/2d9b814ed6/objects/d679e6ff0efb8c9c102b8f8136b0f68a" // Create the viewer instance let viewer = new window.Speckle.Viewer({ container: document.getElementById("viewer"), showStats: true }) + +viewer.loadObject(objUrl, token) + +viewer.interactions.zoomExtents(0.95, false) + +viewer.on("select", objects => { + console.info(`Selection event. Current selection count: ${objects.length}.`) + console.log(objects) +}) + +viewer.on("object-doubleclicked", obj => { + console.info("Object double click event.") + console.log(obj ? obj : "nothing was doubleckicked.") +})