sketchucation logo sketchucation
    • Login
    1. Home
    2. pistepilvi
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 5
    • Groups 1

    pistepilvi

    @pistepilvi

    10
    Reputation
    1
    Profile views
    5
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    pistepilvi Unfollow Follow
    registered-users

    Latest posts made by pistepilvi

    • Material observer behaviour on OS X

      Hi all,

      The behaviour of the MaterialsObserver on OS X is puzzling me: material observers are assigned to active_model.materials, so I would expect them to work on one model only. When creating multiple documents, this works as expected: a onMaterialSetCurrent observer assigned to one model will not respond to changing the active material for another model when using the paint bucket.

      However, when running a Ruby script that changes the active material for Sketchup.active_model, observers from all models react to the event. So when running the script below on one model, then creating a new file and running it for that model, the messagebox will appear twice. After creating yet another model and running the script, it will appear three times and so on. Strangely, when using the paint bucket, only the observer for the current model responds.

      Is this some glitch or actually expected behaviour?

      As I am trying to temporarily switch off the material observer, I am thinking of storing all models and their observers in a hash, so I can just loop through them and switch them off one by one. Does that sound like a sensible solution, or is there a better way to make sure no material observers will react to setting the active material in my script?

      class SU2LUX_materials_observer < Sketchup;;MaterialsObserver
        def onMaterialSetCurrent(materials, material)
          UI.messagebox ("observer reporting; " + Sketchup.active_model.to_s + " " + self.to_s)
        end
      end
      
      puts "creating observer"
      puts myObserver = SU2LUX_materials_observer.new
      puts "assigning observer"
      puts Sketchup.active_model.materials.add_observer(myObserver)
      puts "setting active material"
      Sketchup.active_model.materials.current = Sketchup.active_model.materials[1] 
      
      posted in Developers' Forum
      pistepilviP
      pistepilvi
    • RE: Detecting active model switches on OS X

      @dan rathbun said:

      Attach a model observer and provide onDeleteModel and onEraseAll callbacks that output something to the console.

      Thanks again!

      onEraseAll does fire on Windows when opening another model, but not on OS X unfortunately. Interestingly enough, I also can't get it to fire on erasing all objects. onDeleteModel doesn't seem to ever trigger. I'll focus on other issues for now, this one can wait.

      posted in Developers' Forum
      pistepilviP
      pistepilvi
    • RE: Detecting active model switches on OS X

      @dan rathbun said:

      Try to only open 1 Settings dialog per model.
      Display its name/path in the caption bar.
      Whatever changes are done, save them to the model that "belongs" to the dialog.

      That sounds like the best solution, thanks! It took a while, but I have now implemented this behaviour. Unless somebody finds a showstopper within the coming days, I'll announce the new version of the plugin here on the sketchUcation forum.

      Now that I have settings windows for all individual opened files, I would like to be able to close the relevant ones automatically when the user closes one of the files. I expected there to be an observer that notifies me when files are being closed, but again I get the impression I'm looking for something that isn't there. I could use onPreSaveModel, but that won't work if the user saves manually before closing. This is not a critical issue, but if anybody knows of a workaround that would be very helpful. ๐Ÿ˜„

      posted in Developers' Forum
      pistepilviP
      pistepilvi
    • RE: Detecting active model switches on OS X

      Thank you both for the constructive replies. Somehow yesterday I couldn't find any relevant threads, but earlier today I did with slightly different search terms and I've looked at them in detail. From what I understand, I can get a unique id for each model and check for that at critical moments (when opening dialogs, or when changing settings), but there is no way to catch the exact moment when a user switches files on OS X. So the technical situation is clear.

      The script I'm working on is SU2LUX (https://bitbucket.org/luxrender/su2lux/src), the exporter for LuxRender. Render settings are stored in attribute dictionaries, so when multiple files are open there are multiple sets of settings that can be accessed. However, there is always only one settings dialog.

      The main design issue I need to solve is this: When two models are open and my exporting options dialog shows the values from model 1, then the user switches to model 2 and changes a value in the dialog, what do I do? One approach would be to check for a change in active_model and update all values in the dialog as soon as anything is changed. Another is to create a collection of open models and display them in a dropdown (or just a text) at the top of the dialog, so one can always see what model one is working on, regardless of which one is active_model. A third possibility is to create one settings dialog per file.

      None of these options seems ideal, but I'll just have to decide which one is the best one. If anybody has input on this or can think of a better solution, I would much appreciate it.

      posted in Developers' Forum
      pistepilviP
      pistepilvi
    • Detecting active model switches on OS X

      Hi all,

      While working on a rendering plugin/exporter, I noticed that errors appear when having multiple SketchUp models open on OS X. This is no surprise as the plugin has been written assuming there would always just be one active model per session, but it is a clear usability issue and I would like to solve it.

      So far, I haven't found any observer that triggers on switching from one model to another when both models are already open. Is there any observer that I may have overlooked that keeps track of Sketchup.active_model?

      If no observer is available, what would be a good way to detect that the active model has changed? I could of course check for changes in Sketchup.active_model when any of the existing observers is triggered (including ViewObserver), but this would still miss the scenario where the user just clicks on a different SketchUp window to activate it. And perhaps more importantly, I'm always worried about slowing down SketchUp when using observers.

      posted in Developers' Forum
      pistepilviP
      pistepilvi