def RunCommand(is_interactive): if check(): print("Current plugin is already activated") else: compas_rhino.rs.MessageBox("Env has changed, re-activating plugin", 0, "Re-activating Needed") if activate(): compas_rhino.rs.MessageBox( "Restart Rhino for the change to take effect", 0, "Restart Rhino") else: compas_rhino.rs.MessageBox("Someting wrong during re-activation", 0, "Error") return Browser() errorHandler = ErrorHandler(title="Server side Error", showLocalTraceback=False) sc.sticky["RV2.proxy"] = Proxy(errorHandler=errorHandler) sc.sticky["RV2.proxy"].restart() sc.sticky["RV2.system"] = { "session.dirname": CWD, "session.filename": None, "session.extension": 'rv2' } scene = Scene(SETTINGS) scene.clear() sc.sticky["RV2"] = {"scene": scene} sc.sticky["RV2.sessions"] = []
def RunCommand(is_interactive): browser = BrowserForm() browser.Show() sc.sticky["RV2.proxy"] = Proxy(background=False) settings = { "layers.skeleton": "RV2::Skeleton", "layers.form": "RV2::FormDiagram", "layers.force": "RV2::ForceDiagram", "layers.thrust": "RV2::ThrustNetwork", "show.form.vertices": True, "show.form.edges": True, "show.form.faces": False, "show.force.vertices": True, "show.force.edges": True, "show.force.faces": False, "show.thrust.vertices": True, "show.thrust.edges": True, "show.thrust.faces": True, "color.form.vertices": (0, 255, 0), "color.form.vertices:is_fixed": (0, 255, 255), "color.form.vertices:is_external": (0, 0, 255), "color.form.vertices:is_anchor": (255, 255, 255), "color.form.edges": (0, 255, 0), "color.form.edges:is_external": (0, 0, 255), "color.thrust.vertices": (255, 0, 255), "color.thrust.vertices:is_fixed": (0, 255, 0), "color.thrust.vertices:is_anchor": (255, 0, 0), "color.thrust.edges": (255, 0, 255), "color.thrust.faces": (255, 0, 255), "color.force.vertices": (0, 255, 0), "color.force.vertices:is_fixed": (0, 255, 255), "color.force.edges": (0, 255, 0), "color.force.edges:is_external": (0, 0, 255), "scale.thrust.external": 0.25, "vertical.zmax": 4.0, "vertical.kmax": 100, "horizontal.kmax": 100, "horizontal.alpha": 100 } scene = Scene(settings) scene.clear() sc.sticky["RV2"] = { "session": { "cwd": None, "ext": 'rv2', "current": None }, "scene": scene # "data": DATA }
def RunCommand(is_interactive): Browser() errorHandler = ErrorHandler(title="Server side Error", showLocalTraceback=False) sc.sticky["RV2.proxy"] = Proxy(errorHandler=errorHandler) sc.sticky["RV2.system"] = { "session.dirname": CWD, "session.filename": None, "session.extension": 'rv2' } scene = Scene(SETTINGS) scene.clear() sc.sticky["RV2"] = {"scene": scene} sc.sticky["RV2.sessions"] = []
# -------------------------------------------------------------------------- # create force diagram # -------------------------------------------------------------------------- time.sleep(1) force = ForceDiagram.from_formdiagram(form) force = move_diagram(force) rhinoforce = RhinoForceDiagram(force) rhinoforce.draw(settings) # -------------------------------------------------------------------------- # horizontal equilibrium # -------------------------------------------------------------------------- time.sleep(1) proxy = Proxy() horizontal = proxy.package("compas_rv2.equilibrium.horizontal_nodal_proxy") formdata, forcedata = horizontal(rhinoform.diagram.data, rhinoforce.diagram.data) rhinoform.diagram.data = formdata rhinoforce.diagram.data = forcedata rhinoform.draw(settings) rhinoforce.draw(settings) # -------------------------------------------------------------------------- # vertical equilibrium, draw thrustnetwork # -------------------------------------------------------------------------- time.sleep(1) vertical = proxy.package("compas_tna.equilibrium.vertical_from_zmax_proxy")
from compas_cloud import Proxy from compas.geometry import Translation # CACHING INPUT PARAMETERS proxy = Proxy() transform_points_numpy = proxy.function('compas.geometry.transform_points_numpy') # create a proxy funciton pts = [[0,0,0], [1,0,0]] pts_cache = proxy.cache(pts) # cache the object to server side and return its reference print(pts_cache) # will print: {'cached': some_unique_id} T = Translation().from_vector([100, 0, 0]).matrix result = transform_points_numpy(pts_cache, T) # call the function through proxy print(result) # will print: [[100.0, 0.0 ,0.0], [101.0, 0.0, 0.0]] # CACHING RETURNED DATA transform_points_numpy = proxy.function('compas.geometry.transform_points_numpy', cache=True) # this function will now return a cache object instead of the actual data pts = [[0,0,0], [1,0,0]] pts_cache = proxy.cache(pts) print(pts_cache) # will print: {'cached': some_unique_id} T = Translation().from_vector([100, 0, 0]).matrix result_cache = transform_points_numpy(pts_cache, T) # call the function through proxy print(result_cache) # will print: {'cached': some_unique_id}
T = Translation([100, 0, 0]).matrix start = time.time() for i in range(0, 100): pts = transform_points(pts, T) result1 = pts end = time.time() print('transform 10k points 100 times (native python): ', end - start, 's') # USING CLOUD WITH CACHE from compas_cloud import Proxy proxy = Proxy() transform_points_numpy = proxy.function( 'compas.geometry.transform_points_numpy', cache=True) pts = [[i, 0, 0] for i in range(0, 10000)] T = Translation([100, 0, 0]).matrix start = time.time() pts = proxy.cache(pts) for i in range(0, 100): pts = transform_points_numpy(pts, T) result2 = proxy.get(pts)
import random import compas from compas.datastructures import Mesh from compas.utilities import i_to_rgb """ instead of `from compas.numerical import dr_numpy` use following code to import module""" from compas_cloud import Proxy p = Proxy() dr_numpy = p.function('compas.numerical.dr_numpy') dva = { 'is_fixed': False, 'x': 0.0, 'y': 0.0, 'z': 0.0, 'px': 0.0, 'py': 0.0, 'pz': 0.0, 'rx': 0.0, 'ry': 0.0, 'rz': 0.0, } dea = { 'qpre': 1.0, 'fpre': 0.0, 'lpre': 0.0, 'linit': 0.0, 'E': 0.0, 'radius': 0.0, }
from compas_cloud import Proxy import time print("\n starting a new Proxy and by default starts a server in background") proxy = Proxy(background=True) time.sleep(3) print( "\n restarting the background server and open a new one in a prompt console" ) proxy.background = False proxy.restart() time.sleep(3) print("\n check if the proxy is healthily connected to server") print(proxy.check()) time.sleep(3) print("\n shut the the server and quite the program") proxy.shutdown() time.sleep(3)
from compas_cloud import Proxy # define a psuedo task that will take few seconds to finish def func(a): import time for i in range(a): time.sleep(1) print('sleeped ', i, 's') # initiate a Sessions object through Proxy that connects to a background server p = Proxy() s = p.Sessions() # add several tasks to the session using different parameters s.add_task(func, 1) s.add_task(func, 2) s.add_task(func, 3) s.add_task(func, 4) s.add_task(func, 5) # kick of the taks and start to listen to the events when tasks start or finish s.start() s.listen()
from compas_cloud import Proxy import time proxy = Proxy() dot = proxy.function('numpy.dot') a = [[1, 0], [0, 1]] b = [['a']] dot(a, b) """ This should raise an error: Exception: ValueError:shapes (2,2) and (1,1) not aligned: 2 (dim 1) != 1 (dim 0) """
from compas_cloud import Proxy from compas.geometry import Translation proxy = Proxy() transform_points_numpy = proxy.function( 'compas.geometry.transform_points_numpy') # create a proxy funciton pts = [[0, 0, 0], [1, 0, 0]] T = Translation([100, 0, 0]).matrix result = transform_points_numpy(pts, T) # call the function through proxy print(result) # will print: [[100.0, 0.0 ,0.0], [101.0, 0.0, 0.0]]