• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Move child component in dynamic component

Scheduled Pinned Locked Moved Plugins
3 Posts 2 Posters 725 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    macumber
    last edited by 28 Mar 2010, 20:33

    I am attempting to move a child in a dynamic component through a Ruby script by setting the entity's transformation. This appears to work at first, but I get a really weird effect when I redraw (either through redraw_with_undo or using the hand icon). The objects seem to jump around, if I keep resetting the transformation and redrawing eventually it converges to the right place. Does anyone know why this is happening or a better way to move these sub components in a Ruby script(while still allowing the user to move them through the UI)? Here is my demo script and I have attached the problem component.

    Thanks a lot,
    Dan

    OpenStudio_DaylightingControls.skp

    import the component "OpenStudio_DaylightingControls.skp" and place at the origin

    select the component as the only component then run this script

    selection = Sketchup.active_model.selection
    view = Sketchup.active_model.active_view

    for i in 0..10
    puts selection[0].definition.entities[0].transformation.origin
    selection[0].definition.entities[0].transformation = Geom::Transformation.translation([0.m, -1.m, 0.m])
    puts selection[0].definition.entities[0].transformation.origin

    $dc_observers.get_latest_class.redraw_with_undo(selection[0])

    view.refresh

    sleep(1)
    end

    1 Reply Last reply Reply Quote 0
    • S Offline
      scottlininger
      last edited by 1 Apr 2010, 18:30

      Hello Dan! Sorry I missed this post. Here are two solutions to your problem. (I'm sure there are others, too.)

      1. Instead of moving the "sub" DCs with Ruby and asking the parent to redraw, have the subDCs position themselves based off of some custom attributes in the parent. You script would set these attributes, like sensor_1_x to 5.9, sensor_2_y to 25.0, etc. Then when you fire a redraw, the children will puppet themselves properly. (But, if the user tries to manually reposition them, it will ignore them... maybe not what you want.)

      2. Add a couple of more lines to you existing script...

      selection = Sketchup.active_model.selection
        view = Sketchup.active_model.active_view
      
        for i in 0..10
          puts selection[0].definition.entities[0].transformation.origin
          selection[0].definition.entities[0].transformation = Geom;;Transformation.translation([0.m, -1.m, 0.m])
          puts selection[0].definition.entities[0].transformation.origin
      
          # DCs keep track of their "last size" in some attributes.
          # This allows them to infer whether they have been scaled
          # manually by the user.
          #
          # In this case, you are changing the bounding box of the DC
          # by moving its subparts, and so it thinks that the scale
          # tool has been applied, and is making some bad repositioning
          # decisions based on that. Doh!
          #
          # These are the methods that the DC plugins uses to tell the DC
          # to "recalculate" its bounding box. Do this after your translation
          # and things are happier. (I can explain more if you want...)
          lenx, leny, lenz = selection[0].unscaled_size
          selection[0].set_last_size(lenx, leny, lenz)
      
          $dc_observers.get_latest_class.redraw_with_undo(selection[0])
          view.refresh
          sleep(1)
      
      • Scott Lininger
        SketchUp Software Engineer
        Have you visited the Ruby API Docs?
      1 Reply Last reply Reply Quote 0
      • M Offline
        macumber
        last edited by 1 Apr 2010, 21:57

        Works great, thanks so much! I guarantee I would not have gotten that on my own.

        (PS I went with option 2 because the user can still move them on their own.)

        Thanks a lot,
        Dan

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          1/3
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement