Path#points= doesn't work

edited June 2015 in Ruby Scripting

Steps to reproduce the problem:

  1. draw a path
  2. select it
  3. run the following code. I think it should change the path points to [[1,2],[3,4]] but the path doesn't change.

=

lv = RBA::Application.instance.main_window.current_view

lv.each_object_selected { |obj|
  obj.shape.path.points = [RBA::Point.new(1,2),RBA::Point.new(3,4)]
}

I thought maybe it's not changing it because obj.shape.path is a pointer to the path rather than the path itself or something.. Is this the desired behavior or am I missing something?

The only way I've found to do it is to make a second path with the desired points, place it, and erase the first path. But this is troublesome and not perfect, e.g. User Properties and beginning and end types etc are not copied over without some effort.

Thanks,
David

Comments

  • edited November -1

    Hi David,

    recall our discussion about "OO style" API? That's another case.

    I shall explain that: obj.shape.path returns a copy of that path. You basically modify the copy, so it won't have an effect.

    But you can assign the path object:

    p = obj.shape.path
    p.points = ...
    obj.shape.path = p
    

    That should preserve the user properties.

    It's actually not possible to adopt a "OO style" API, because a shape does not necessarily represent a RBA::Path object. The layout database stores objects in a compact way, so Shape is a facade delivering the working objects such as Box, Path or Polygon.

    Matthias

  • edited November -1
    Ah! A simple fix again. Thank you Matthias.

    I am slowly learning...

    Thanks,
    David
Sign In or Register to comment.