sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Find vertex resulting from a pushpull or transformation

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 5 Posters 380 Views 5 Watching
    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.
    • E Offline
      erockrazor
      last edited by

      I may have mistakenly cross posted this in the newbie forum, thinking it was a newbie developers section, where this post would of belonged.. Sorry about that.

      My goal is to create a rectangular face, pushpull a user-input amount, and then be able to find the vertices (and create variables for them) of the new side created by the push pull. Similarly I want to be able to find the corner of a face, after rotation has occurred, so I can continue automated drawing using that point.

      This is my first real script I don't know exactly what to search for in the API or in this forum. Is this another way that transformation works?

      Even though this is my first post, you all have helped me out a lot on this script already. It's a script that builds a home based off of roof dimensions. I have finished the part of the script that can make gabled roofs but now I'm trying to automate the drawing of the house beneath. Thanks for everything.

      Here's a copy of my script, if it helps.

      
            model = Sketchup.active_model
           
          ##input box for roof properties
            prompts = ['X or Ridgeline Length;', 'Y or Slope Length;',
                'Tilt']
            defaults = [15.feet.inch, 11.feet.inch, 20]
            inputs = UI.inputbox( prompts, defaults, 'Astrum Gabled Roof Builder' )
      
          ## creating variables for the inputbox results
            ridge_length = inputs[0].to_i
            slope_length = inputs[1].to_i
            tilt_degrees = inputs[2].to_i
            tilt_degrees = tilt_degrees - (tilt_degrees * 2)
            ridge_mid = ridge_length / 2
      
      
          ## organizing the roofs face coordinates
            line1 = [0,0,0]
            line2 = [ridge_length,0,0]
            line3 = [ridge_length,slope_length,0]
            line4 = [0,slope_length,0]
            rotate_midpoint = [ridge_mid,0,0]
      
           # Make our roof into a group, push/pull & rotate
            roof_rotate = Geom;;Transformation.rotation rotate_midpoint, X_AXIS, tilt_degrees.degrees
            roof_spin = Geom;;Transformation.rotation rotate_midpoint, Z_AXIS, 180.degrees
           
            roof_group = model.entities
              face = roof_group.add_face line1, line2, line3, line4
              face.reverse!
              face.pushpull -6
              group = roof_group.add_group face.all_connected
              select = model.selection.add (group)
            group.transform!(roof_rotate)
            group2 = group.copy
            group2.transform!(roof_spin)
      
      
      
      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        A few observations in no particular order...
        I assume your code is inside your own module and method(s) >
        Add require('sketchup.rb') near the start.
        Don't use UI.inputbox, use the better inputbox() made available by that 'require'.
        Always parenthesize your arguments: inputbox(prompts, values, title)
        Remember there must be NO space between the method that the opening (...
        The values can be as lengths and a float to avoid issues later:
        defaults = [15.feet, 11.feet, 20.0]
        Do NOT set the angle [tilt] as an integer because then you can't use say 22.5 degrees !
        Do NOT [re]convert the inputs to integers after you read them in !
        Leave them as the two lengths and a float.
        Not sure why you change the 'tilt' ? Can't you use the angle the user provides ?
        At the moment the roof slope is halved and made downwards ?
        The transformations... parenthesize and don't over complicate things:
        roof_rotate = Geom::Transformation.rotation**(**rotate_midpoint, X_AXIS, tilt_degrees.degrees**)** roof_spin = Geom::Transformation.rotation**(**rotate_midpoint, Z_AXIS, 180.degrees**)**
        What you call 'lines' are neither lines nor edges, but points in 3d space...
        You would also be better off making the group and then adding the geometry directly into it...
        roof_group = model.**active_**entities face = roof_group.**entities.**add_face**(**line1, line2, line3, line4**)**
        Then:
        ` face.reverse!
        face.pushpull(-6.0) ### 6"

        NO NEED FOR group = roof_group.add_group(face.all_connected)

        the extrusion is already inside 'roof_group'

        group = roof_group
        select = model.selection.**add(**group) ### NO space before ( !`
        The transformations should do what you expect ?
        I.E. tilt the roof down about the ridge, copy it and rotate the copy 180 degrees about the ridge center?

        TIG

        1 Reply Last reply Reply Quote 0
        • eneroth3E Offline
          eneroth3
          last edited by

          In what way is inputbox better than UI.inputbox? I had no idea it existed but when trying it without arguments (SU 2013) I got into an endless loop with a messagebox telling me there were to few arguments.

          My website: http://julia-christina-eneroth.se/

          1 Reply Last reply Reply Quote 0
          • tt_suT Offline
            tt_su
            last edited by

            I wouldn't say it's better... and yes, it used to have that loop bug.... 😞

            1 Reply Last reply Reply Quote 0
            • eneroth3E Offline
              eneroth3
              last edited by

              From SU 2013 (the one I use to code to get backward compatibility)

              @unknownuser said:

              This is a wrapper for UI.inputbox. You call it exactly the same

              as UI.inputbox. UI.inputbox will raise an exception if it can't

              convert the string entered for one of the values into the right type.

              This method will trap the exception and display an error dialog and

              then prompt for the values again.

              def inputbox(*args)
              results = nil
              begin
              results = UI.inputbox *args
              rescue
              UI.messagebox $!.message
              retry
              end
              results
              end

              It doesn't seem to do more than just showing errors in a messagebox instead of the console. I don't really know what it's for.

              Sorry for stealing the thread btw

              My website: http://julia-christina-eneroth.se/

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                I think that the inputbox() is stricter in the class it accepts, so if the original is a length nothing else will do etc...
                It keeps re-prompting on an unacceptable input ?

                TIG

                1 Reply Last reply Reply Quote 0
                • tt_suT Offline
                  tt_su
                  last edited by

                  That's part of UI.inputbox - whatever the class the input values are the output values will be converted to.
                  inputbox() in sketchup.rb is just a utility wrapper to show UI::inputbox to keep prompting if the value the user entered invalid (cannot be converted into the input class).

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    The wrapper method in "sketchup.rb" is in need of an overhaul.

                    Post your suggestions in thread: [Code] better inputbox() wrapper

                    I'm not here much anymore.

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

                    Advertisement