Python script + minor changes

This commit is contained in:
Alan Rynne
2021-07-01 16:23:35 +02:00
parent e8bcebdda1
commit ee9f45c23c
3 changed files with 77 additions and 2 deletions
+9
View File
@@ -26,6 +26,15 @@ namespace CSharpStarter
commitObj["myProp"] = "myPropValue";
commitObj["myOtherProp"] = new List<string> { "A", "list", "of", "values" };
var boxes = new List<Point>();
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;
+51
View File
@@ -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)
+17 -2
View File
@@ -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.")
})