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

    Adding attributes help

    Scheduled Pinned Locked Moved Developers' Forum
    29 Posts 8 Posters 1.6k Views 8 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.
    • L Offline
      lothcat
      last edited by

      @tig said:

      When you use set_attribute(...) it applies it to the specified entity AND it's only attached to that entity [or later copies of it].
      Your earlier code attached the attribute to a face... so when you run model.get_attribute(...) it quite rightly returns nil because you haven't attached that attribute to the model ??
      You can attached an attribute to a model BUT your code is attaching it to a face.
      You need to find some faces and then iterate through them and use face.get_attribute(...) on each in turn and get their attributes ???

      You're right, that was stupid. I have it fixed now. Thanks!

      1 Reply Last reply Reply Quote 0
      • L Offline
        lothcat
        last edited by

        OK, so, now that I have that figured out, I'd like to know if there's a way to tell if a face is vertical or horizontal. It seems like face.plane would do that, but I've found frustratingly little about how plane works.

        I'm not sure of the board etiquette. Should I post this question as a new topic, or is this OK?

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

          @lothcat said:

          OK, so, now that I have that figured out, I'd like to know if there's a way to tell if a face is vertical or horizontal. It seems like face.plane would do that, but I've found frustratingly little about how plane works.
          I'm not sure of the board etiquette. Should I post this question as a new topic, or is this OK?

          If it stops here no new topic needed... but if you want to talk about faces some more make a new topic...
          Rather than face.plane try face.normal - that's the vector perpendicular to a face.
          So if face.normal==Z_AXIS [or [0,0,1]] it's facing vertically up or face.normal==Z_AXIS.reverse [or [0,0,-1]] if facing straight down.
          To test it a face is 'vertical' try if face.normal.z==0 - that is true as the normal has no element in the vertical [z].
          With a bit of thought you can contrive other tests - e.g. if face.normal.y.abs != 1 is true if the normal doesn't face exactly in either of the Y/green axes direction - i.e. it faces in any direction except directly to the front or back...

          TIG

          1 Reply Last reply Reply Quote 0
          • L Offline
            lothcat
            last edited by

            Thank you!

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

              @dan rathbun said:

              No don't do that [make a hash into an array], you lose your keys!
              Make your hashes into strings with hashstr = hash.inspect()
              Save the hashstr into the dictionary.
              To read, get the hashstr from the dictionary.
              Then hash = eval(hashstr) to convert it back.

              I really wouldn't save a ruby string as an attribute and later eval it. It opens up for code injection and lets people run whatever malicious code they want on someone else's computer just by sending them a model made to take advantage of this vulnerability and wait for the moment where eval is called.

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

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

                @eneroth3 said:

                I really wouldn't save a ruby string as an attribute and later eval it. It opens up for code injection and lets people run whatever malicious code they want on someone else's computer just by sending them a model made to take advantage of this vulnerability and wait for the moment where eval is called.

                +1 eval = evil

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

                  @unknownuser said:

                  'he's good bad', but he ain't evil!

                  I tend to agree with this**[anchor= goto=http://www.infoq.com/articles/eval-options-in-ruby:2ingvk9h]article[/anchor:2ingvk9h]**...

                  eval has it's uses, that's why it's there...
                  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
                  • eneroth3E Offline
                    eneroth3
                    last edited by

                    @driven said:

                    @unknownuser said:

                    'he's good bad', but he ain't evil!

                    I tend to agree with this**[anchor= goto=http://www.infoq.com/articles/eval-options-in-ruby:13hbt2pf]article[/anchor:13hbt2pf]**...

                    eval has it's uses, that's why it's there...
                    john

                    There are cases where it's fine to use. I use it myself in my attribute editor plugin for instance to let people assign things such as 1.m or Sketchup.active_model.selection.first.length to an attribute. However executing code saved in a model opens up for people to forge an evil model that causes the code to be executed without the user knowing about it.

                    Also arrays are allowed and can be used instead of hashes when it comes to just serializing data.

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

                    1 Reply Last reply Reply Quote 0
                    • S Offline
                      slbaumgartner
                      last edited by

                      I agree with Julia. Using eval is a bit like owning a pet tiger: you have to be careful what you put in the cage with it!

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

                        Yea, like you wouldn't feed raw user data to your database, you don't want to feed user data to eval. (I consider anything read in from the system or file to be "user data"). Validate and sanitize - this is the stuff you want to find a library that has solved all the edge cases for you.

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

                        Advertisement