🏢 PlaceMaker | 25% off for February including new Google Earth data imports! Learn more
  • Deleting an observer

    3
    0 Votes
    3 Posts
    343 Views
    Dan RathbunD
    You should always be running your code within your OWN namespace, so using a global variable is NEVER needed. I use @@ module vars to hold references to observers. YES you can write a method within your observer class that can remove itself. I do this sometimes, and it is really just a wrapper for the remove_observer() method. This example assumes your using your Observer in a Singleton manner: class MySelectionObs < Sketchup;;SelectionObserver @@watched = [] def attach(selection) raise(TypeError,"argument is not a Sketchup;;Selection object.") unless selection.class==(Sketchup;;Selection) if selection.class==(Sketchup;;Selection) && (not self.watching?(selection)) selection.add_observer(self) @@watched << selection end end def dettach(selection) raise(TypeError,"argument is not a Sketchup;;Selection object.") unless selection.class==(Sketchup;;Selection) if selection.class==(Sketchup;;Selection) && self.watching?(selection) selection.remover_observer(self) @@watched.delete(selection) end end def verify_watchlist() unless @@watched.empty? @@watched.delete_if {|e| e.class != Sketchup;;Selection } @@watched.delete_if {|e| !e.model.valid? } end end def watching() verify_watchlist() return @@watched.dup end def watching?(selection) raise(TypeError,"argument is not a Sketchup;;Selection object.") unless selection.class==(Sketchup;;Selection) verify_watchlist() return @@watched.include?(selection) end ### define your other callback methods ### end # class ONE BIG EXCEPTION : NEVER dettach (remove) observers within the onQuit() callback of an AppObserver subclass instance !! A BugSplat! will occur.
  • Problems with Soap Skin Bubbles

    40
    0 Votes
    40 Posts
    11k Views
    C
    @dave r said: Patience. The author has always updated it in the past. I'm sure it'll get updated soon. yes, version 12 which works until 10 april 2012 was released. http://www.tensile-structures.de/sb_software.html and taking system time back worked for me for last 2 days.
  • Model.import() always true?

    6
    0 Votes
    6 Posts
    257 Views
    A
    For yery corrupted collada files, there appears just a messagebox "import failed [OK]". The ruby console does not display any exception but just true``. For some collada files, SketchUp says there is a chance that the import could fail and asks if I want to continue [yes]/[no]. If I click yes, it succeeds to import it anyways, if I click no, the same messagebox appears "import failed [Ok]. In all cases, the console says true. I tried it with begin ... rescue ... end without success. model.zip
  • Selectionobserver

    13
    0 Votes
    13 Posts
    697 Views
    K
    hmmm... ok. in this case i don't understand why the lines behaved like that. not that important. ok, thanks to you once again.
  • Soap Skin &amp; Bubble expires

    23
    0 Votes
    23 Posts
    4k Views
    C
    Soap Skin & Bubble expried yesterday. what to do?
  • Ruby &quot;split&quot; in file line reading

    8
    0 Votes
    8 Posts
    3k Views
    C
    @shirazbj said: Heard of regular expressions before, This time I tried to understand it. Thanks. Regular expression are simultaneously very useful and painful to work with. There is a great quote by Jamie Zawinski which goes "Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems." I first ran into them at Dive into Python 3 which gives a couple simple case studies and although the language is slightly different the regular expressions are basically the same. Looking at the regular expression given by /[-|+]?\d.\dE[-|+]?\d\d\d/ we have the / on each end marking the start and end of the expression. There are two blocks of [-|+]? which matches an optional + or - sign. I would read this is "0 or 1 instances of + or -". Then we have \d.\dE which matches a single digit, then some arbitrary number of digits until it find an E, then we again have an option sign followed by exactly 3 digits. So this pattern will match a single numerical value in the string given. The .scan method then constructs an array out of every match. From here you can wrap blocks in parenthesis to create groups so you can break the matches up into their own arrays which is what I had done originally until I realized Ruby would parse scientific notation with the .to_f method.
  • When do Tools.active_tool_id return 0 ?

    6
    0 Votes
    6 Posts
    918 Views
    Dan RathbunD
    @unknownuser said: By the way, it seems that, on MAC, active_tool_name may return a truncated text (for instance "ctionTool" for SelectionTool, or "angle" for Rectangle). Yes... this is the reason we are treating this issue. We need to use the tool_id rather than the tool_name to work around the Mac bug. In SU8 Google did fix the Mac tool name bug for the ToolsObserver, but forgot to fix the Tools collection active_tool_name() method.
  • How to insert a component instance from a definition.

    6
    0 Votes
    6 Posts
    283 Views
    honoluludesktopH
    OK, thanks. I must have done it wrong, when I tried to use entities.add_instance previously. I will work on it tomorrow.
  • Drawing an array of boxes

    15
    0 Votes
    15 Posts
    763 Views
    Z
    Thanks Dan, I have read the pragmatic programmers book but that was a while back and unfortunately I have a deadline submission I need to meet next week, i've managed to get the C++ side of the coding done but am struggling with the Ruby and don't have time to re-assess what i've learnt, just need to sift through the relevant information and collaborate it.
  • Syntax Highlighting in SU WebDialog

    13
    0 Votes
    13 Posts
    2k Views
    alexschreyerA
    The Ace highlighter looks very good, too. Great to see a few of these popping up now. However, I just fixed my Ruby editor up with Codemirror, so I am not moving... I'll have an updated version of my editor ready after a bit of testing. Here is a picture for now: [image: 5MTg_2011-04-08_1623.png] Cheers, Alex
  • Resizing WebDialog windows

    8
    0 Votes
    8 Posts
    966 Views
    J
    @thomthom said: Callbacks from WebDialog Javascript under OSX is asynchronous - so sending multiple callbacks rapidly will eat some of the messages. You'd have to have a messagepump system to verify each message is received by Ruby before sending a new callback from Javascript. Do you know if anyone has yet managed to build such a system? I searched around a little on the forums and all I could seem to find was stuff like this: http://forums.sketchucation.com/viewtopic.php?f=180&t=22698 The javascript code in the Dynamic Components folder shows what seems to be one half of such a system, and thus gives a bit of a starting point, but it would be nice to have something a little more substantial to start from...
  • Pause until action is complete

    12
    0 Votes
    12 Posts
    719 Views
    Dan RathbunD
    @zane said: That's great! Thanks Dan and Chris No problem, I fixed a mistake in the done=() method of the second example (above.)
  • Fog Distance -what does it refer to?

    13
    0 Votes
    13 Posts
    864 Views
    D
    thanks TIG you are beginning to show me how skp REALLY works so i think i can move my camera (accurately) a little closer by a combination of the above info - i can tell skp where to put the camera, fog start and fog end precisely using coords and these 'commands'
  • Question about menu.add_item

    12
    0 Votes
    12 Posts
    778 Views
    W
    I see. Thank you,Tig!
  • Dynamic non-component

    2
    0 Votes
    2 Posts
    244 Views
    TIGT
    I'm not sure what you're trying to achieve... This might help [a bit] - it traps errors .......... class MyEntitiesObserver < Sketchup;;EntityObserver def onChangeEntity(entity) width = entity.bounds.width.to_f model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, width*2.0, 0] pts[3] = [0, width*2.0, 0] begin face = entities.add_face pts face.add_observer($mmmmmmmmmmmmmmmmmmmmm) entity.edges.each{|i| i.erase! if not e.edges[1]} rescue puts 'error' face.remove_observer($mmmmmmmmmmmmmmmmmmmmm) face.add_observer($mmmmmmmmmmmmmmmmmmmmm) end end end model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [1, 0, 0] pts[2] = [1, 2, 0] pts[3] = [0, 2, 0] face = entities.add_face pts $mmmmmmmmmmmmmmmmmmmmm=MyEntitiesObserver.new() face.add_observer($mmmmmmmmmmmmmmmmmmmmm) I suggest you rename your observer as something less obvious... i.e. others might have used it !
  • Text in the corner of a rendered image

    5
    0 Votes
    5 Posts
    332 Views
    Dan RathbunD
    I posted a blurp at the bottom of the API page: @dan said: Model.add_note returns a Sketchup::Text object associated with the View (has no point, leader or arrow.) [ie, there is no such object class as Note or Sketchup::Note.] Bug: (on PC as of v7.1,) The note (Text object,) will NOT be displayed if there are no other DrawingElements to render. A note added to an empty model will not be displayed until some element is added to the model. If all other DrawingElements execpt the note are deleted, the note will NOT be displayed (but is still in the Entities collection.) So modify the previous example: mynote = model.add_note "test", 0.1, 0.1 ... later in the code, delete the Sketchup::Text object referenced by mynote mynote.erase! or Sketchup.active_model.entities.erase_entities( mynote )
  • Definition Observer

    6
    0 Votes
    6 Posts
    515 Views
    K
    Thanks TIG. TT - I revisited your observers chart page after posting the initial message. Definitely very helpful. Thanks for maintaining it. -- Karen
  • Sketchup and Ruby

    3
    0 Votes
    3 Posts
    540 Views
    A
    Thank you very much for your reply. Unfortunately, I do not have a lot of experience with this kind of stuff so I might need some more guidance
  • Enums's index of an inputbox return

    4
    0 Votes
    4 Posts
    302 Views
    S
    all good now. I'll download the ruby book. Thanks dan.
  • Problem with texture coordinates

    3
    0 Votes
    3 Posts
    279 Views
    A
    Thanks! I found the essential step in your code ( TT::Face.corners( e )). It seems to work for me just fine when I change the order of the points to (the array c contains always exactly 4 points in the same order). pt_array[0] = c[0] pt_array[1] = Geom;;Point3d.new(0,0,0) pt_array[2] = c[1] pt_array[3] = Geom;;Point3d.new(1,0,0) pt_array[4] = c[2] pt_array[5] = Geom;;Point3d.new(1,1,0) pt_array[6] = c[3] pt_array[7] = Geom;;Point3d.new(0,1,0)

Advertisement