sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Inputbox Hamlet(to do or not todo)

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 159 Views 2 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.
    • jolranJ Offline
      jolran
      last edited by

      Hi! Im doing a simple inputbox for this plugin.
      http://forums.sketchucation.com/viewtopic.php?f=180&t=38481

      It's all TIG's (made in 30 min!)script. I will just have to add prompts for 3 values. Angle, spacing and units.
      This is what I've got so far(It doesent refer to any values in the script yet).

      promts=["Angle (deg)", "Spacing", "Units"] 
         defaults=["45", "20", ".cm"]
         list = ["", "", ".cm|.inches"]
         input =UI.inputbox promts, defaults, list, "Hatchfaces"
      

      I though it would be a simple task, but scanning through this forum there seams to be different opinions for what is correct and non correct constructions for UI.

      Since this plugin will hatch faces, I thought putting a context-menu would be a good choice, followed by an inputbox prompt. However reading up a bit in here rmb click menus can be hazardous!??
      And The Use of globals versus instance-varibles is confusing as well.
      It's all a bit confusing to me, any tips would be very welcome.

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

        @angle=45.0 if not @angle # remembered if set this session
        @spacing=20.to_l if not @spacing # remembered if set this session
        prompts=["Angle(deg); ", "Spacing; "]
        values=[@angle, @spacing]
        title = "Hatchfaces Parameters"
        results = UI.inputbox(prompts, values, title)
        return nil if not results # i.e. the user canceled
        @angle=results[0]
        @spacing=results[1]
        

        This initially sets the 'angle' as a float, so it's expecting a float input so 45 or 22.5 will work, use angle.degrees when using it later. It initially sets the 'spacing' as a 'length', so now like in the VCB the user can type in 20 [i.e. in current units] or 20cm or 200mm or 8" etc and it'll work OK with that - so no need for a dropdown list for setting these units... The spacing should be usable directly in your code without recasting its 'type' etc...
        By using @ variables they will be remembered between uses in that session, when set inside a method, if it's inside a class use @@ variables as these persist across instances... [tip: declare the @@s within the class itself and use them in the methods as needed] Avoid global $ variables that can clash with other's coding as they are accessible to everything! ... BY using @ or [@@] then if the spacing is changed the next time you use the tool in that SUp session its dialog will show the last used angle/spacing rather than the defaults.

        TIG

        1 Reply Last reply Reply Quote 0
        • jolranJ Offline
          jolran
          last edited by

          Great! That makes things a lot clearer.

          @unknownuser said:

          Avoid global $ variables that can clash with other's coding as they are accessible to everything!

          Thats especially the thing I was not sure about about. The last thing I wanna do is barge in here ruin everyones scripts..

          Thanks a lot!

          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