sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Style validation

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 3 Posters 367 Views 3 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.
    • CadFatherC Offline
      CadFather
      last edited by

      this is all i could find, on retrieving a style name that seems to work from the console.

      styles = Sketchup.active_model.styles
      style = styles.selected_style
      UI.messagebox ('The selected style is; ' + style.name)
      
      

      but i can't get it to work with a validation proc - something along these 'lines'...

       cmd.set_validation_proc {
       styles = Sketchup.active_model.styles
       style = styles.selected_style
       
       if style.name = mystyle.style
           MF_CHECKED
         else
           MF_UNCHECKED
         end
       }
      
      1 Reply Last reply Reply Quote 0
      • TIGT Online
        TIG Moderator
        last edited by

        Do you mean:

        if style.name = mystyle.style .name

        What is 'mystyle' ?

        TIG

        1 Reply Last reply Reply Quote 0
        • D Offline
          driven
          last edited by

          @cadfather said:

          this is all i could find, on retrieving a style name that seems to work from the console.]

          Sketchup.active_model.styles.methods
          

          will show you there are a lot more that work...

          but, what are you trying to achieve?
          john

          learn from the mistakes of others, you may not live long enough to make them all yourself...

          1 Reply Last reply Reply Quote 0
          • CadFatherC Offline
            CadFather
            last edited by

            yes TIG i think that is it - i'm going to try it. (fail)

            mystyle.style is just the name of the file i'm calling (from a toolbar).

            John, then i wanted to have an icon which activated if that particular style was active (selected).

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

              Still as clear as mud πŸ˜’

              What is 'mystyle' ?
              What is its 'style' ?

              If you are not clear, try to type mystyle.class and it'll tell you...

              TIG

              1 Reply Last reply Reply Quote 0
              • CadFatherC Offline
                CadFather
                last edited by

                i've got a toolbar, clicking an icon it loads and applies a style from a folder (mystyle.style, for want of a better name). this part is working fine.

                what i was trying to do is for the icon to highlight anytime that style is active.

                (from the api the 'active' procedure didn't work but the 'selected' did)

                hope this makes some sense..

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

                  So " mystyle.style" is actually a string representing a .style file physically on the PC.
                  Lets say you have reference to the file as @style_file = ".../somefolder/mystyle.style"
                  If you have named it logically then its Style is named ' mystyle'.
                  So @style_name = File.basename(@style_file, ".*")
                  gives you the string 'mystyle' [or the basename of whatever the file that is queried that way].

                  NOW you can compare the name of the current style and the name of the style_file thus:

                       cmd.set_validation_proc {
                       ### let's assume @style_file is set elsewhere, as perhaps; 
                       @style_file = ".../somefolder/mystyle.style"
                       ### get its name...
                       @style_name = File.basename(@style_file, ".*")
                       ### compare current style name and basename
                       if Sketchup.active_model.styles.selected_style.name == @style_name
                           MF_CHECKED
                         else
                           MF_UNCHECKED
                         end
                       }
                  

                  To pass @ variables you need the validation to take place inside the module...end where that @ variable is set...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • CadFatherC Offline
                    CadFather
                    last edited by

                    ok TIG, thanks for that, i shall have a go with this.

                    i thought i wasn't too far with my first example! πŸ˜’

                    Thanks!

                    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