Grasshopper

algorithmic modeling for Rhino

Hi all,

I wish to track the changes a user makes to a Grasshopper definition. My naive idea is to somehow access the redo/undo stack and store the info to a text/xml file over time. Would this be an appropriate/reasonable approach? Is there a way to access the stack?

Thank you,

Jason

Views: 628

Replies to This Discussion

GH_Document.UndoServer.UndoNames wouldn't be a bad place to start :) 

Hi Andrew,

Thanks for the suggestion, that would indeed be a good place to start!

I managed to access UndoRecords by a hackish(?) approach. I register a custom eventhandler/callback to the document's UndoStateChanged event.

doc.UndoStateChanged += print_event #doc is the active grasshopper document

# My callback

def print_event(sender,e):
    if e:
        if e.Record:
            print e.Record.Name

I am able to get the name and time of the undo. However I also want additional information. For example, on a 'new wire' record, I would like to know which two components the wire connects. Is this even possible? I tried to look into UndoRecord's actions, but got a little lost there.

My overall aim is to track and log specific user events. For example, when he/she changes a particular slider value or changes the code in a particular Python component (I do not want to create custom components).

Thanks.

Hmm I would think that the language wouldn't matter - unless the Python component works in a radically different way from the C#/VB components.  Here's the code and also the sample definition.

import scriptcontext as sc

active_doc = ghenv.Component.OnPingDocument()

def custom_callback(sender, e):
    if e and e.Record:
        _name =  e.Record.Name
        if not sc.sticky.has_key('record'):
            sc.sticky['record']= [_name]
        else:
            sc.sticky['record'].append(_name)
        
if x:
    #register callback
    active_doc.UndoStateChanged += custom_callback

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service