[compas_view2]: Update all variables

Dear compas team,

Let me use this toy example;

I control the x-value of a point, with a compas_view2 slider. I can see my point updating inside compas_view2.

If a line has its origin at the above-mentioned point, is there a way to update it in compas_view2 without explicitly redrawing the line inside the point slider?

@Li_Chen can objects be parented and updated like that?

Yes, but partially.
If I’m not mistaken, on creation of line, the point is rebuild, this means you would need to update the line data in the slider but no need to rebuild the object itself.
Here’s an example

from compas.geometry import Point, Line
from compas.colors import Color
from compas_view2.app import App

p1 = Point(0, 0, 0)
p2 = Point(0, 0, 1)
line = Line(p1, p2)

viewer = App(viewmode="shaded", enable_sidebar=True, width=1600, height=900)
pointobj1 = viewer.add(p1, pointsize=20, pointcolor=(1, 0, 0))
pointobj2 = viewer.add(p2, pointsize=20, pointcolor=(0, 1, 0))
lineObj = viewer.add(line, linewidth=2)

@viewer.slider(title="Slide Point", maxval=100, step=1, bgcolor=Color.white())
def slide(value):
    value = value / 100
    p1.x = value

    # Update line start point
    line.start = p1

1 Like