During BeforeTransformEvent, how can I find selected objects when modifying curves by transforming control points?


#1

Hello!

I have an event handler attached to BeforeTransformObjects. I want to be able to extract the objects in the document that the transform is being applied to and the transformation. There’s a known bug around the Objects field in the RhinoTransformObjectsEventArgs passed to the event handler being null, even when the ObjectCount is non-zero. I’ve been working around this by grabbing a list of selected objects from the active document, and this setup works in most cases.

However, if I add curves to a document, turn control points on, and transform one of the points, my transform handler gets called with object count 0,

To repro:

Download, build and install (or set up your own event handler):

DemoTransformHandler.zip (38.0 KB)

Open a new document
Install the plugin
Then:
(1) Run “DemoTransformHandler” to attach the event handler.
(2) Add a new line
(3) Drag the line to translate it.
(4) Note that the event handler is called with an objectCount of 1, a null objects array (see known bug above), and that the document reports one selected object.
(5) Run PointsOn, select the line, finish the command.
(6) Drag the line’s start point to a new location.
(7) Note that the event handler is called with ObjectCount 0, and that the document is reporting that no objects are selected.

Anybody have ideas on whether there’s a way for me to find a structured representation of the transformation and the particular control point that it’s being applied to?


(Dale Fugier) #2

Hi Andrew,

Instead of this

var selected = m_doc.Objects.GetSelectedObjects(false, false).ToArray();

try this:

var selected = m_doc.Objects.GetSelectedObjects(false, true).ToArray();

Does this help?

– Dale


#3

Hi Dale,

Yup – and that answers my noobie question of “what’s a grip and why would I want to select it” at the same time :wink:

So let’s say I have some properties that I’ve calculated per-control point of a curve that I want to update when a grip is moved. I would like to be able to re-calculate only the effected properties, and perform the calculation for unaffected control points.

I think that this is a long shot, but is there a way to get a handle on what fields of the owning object are being effected? For example, when a grip connected to some curve’s control point is dragged, is there a way to get the relevant index into the control points array of the curve?

I could iterate over the grip’s owner’s fields and diff them against their previous value, or compare them to the CurrentLocation of the grip. However, given that the grip object itself (or some event handler attached to it?) has a reference to the appropriate field in the owner, I thought that there might be ways to avoid the less-robust technique of checking equivalence field-by-field.

Thank you,

Andrew


(Dale Fugier) #4

Hi Andrew,

You might want to look into custom grips, for it is possible to you to register your own grip handler and then write a command that enables your grips. This is how Rhino’s EditPtOn command works.

Here is a sample that demonstrates how to write your own custom grip handler. This sample is probably a bit overkill forit also also implements a custom curve object.

https://github.com/dalefugier/SampleCsRectangleGrips

Let me know if you have any questions.

– Dale


#5

Thank you again Dale, much appreciated.