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

    Add attributes to a face???

    Scheduled Pinned Locked Moved Developers' Forum
    13 Posts 5 Posters 514 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.
    • M Offline
      Mcdull
      last edited by

      @thomthom said:

      You can add attributes to any Entity. The attributes are stored with the face, so if you delete the face it disappears. To retrieve the attribute again you use get_attribute on that face.

      how to realize this?
      if i select a face and i want to set an attribute "wall" to the face.
      thank u~

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

        To set it

        face=model.selection[0]
        face.set_attibute("McDullAttribute","Wall",true)
        ### this gives the face your-attribute called Wall that is true
        
        

        To get it

        face=model.selection[0]
        is_wall=face.get_attibute("McDullAttribute","Wall")
        if is_wall
          puts "This face is a Wall"
        else
          puts "This face is NOT a Wall"
        end#if
        
        

        You can work out how to set/get the attributes of any entity like this...

        TIG

        1 Reply Last reply Reply Quote 0
        • M Offline
          Mcdull
          last edited by

          thank u very much.as i use this method,it appears a error message:

          Error; #<NoMethodError; d;\test.rb;3; undefined method `set_attibute' for #<Sketchup;;Face;0x5fa96a8>>
          

          i check the sketchup ruby api document.face has not the set_attibute, just the entity has it.
          so do i need to do it like this:

          face = entities.add_face pts
           entity1 = entities[1]
           status = entity1.set_attribute("McDullAttribute","Wall",true)
          

          but the face has been exist before, i should not use

          face = entities.add_face pts
          

          ,but use select method

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

            Sorry about the typo for attibute read attribute 😳

            TIG

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @mcdull said:

              i check the sketchup ruby api document.face has not the set_attibute, just the entity has it.
              so do i need to do it like this:

              Code; Select all
              >     face = entities.add_face pts
              >     entity1 = entities[1]
              >     status = entity1.set_attribute("McDullAttribute","Wall",true)
              

              The Face class extends the Entity class. So a Face class has all the methods of the Entity class.

              
                  face = entities.add_face(pts)
                  status = face.set_attribute("McDullAttribute","Wall",true)
              
              

              In the API, for each class you see which class it extends (if any)
              Example: http://code.google.com/intl/nb/apis/sketchup/docs/ourdoc/face.html
              Notice that right before the list of methods it says "Parent: Drawingelement".

              And you also got this diagram you can use as a reference to see how the classes are related: http://code.google.com/intl/nb/apis/sketchup/docs/diagram.html

              Doing this:

              
              face = entities.add_face pts
              entity1 = entities[1]
              
              

              Gives you no guaranty that you get the face. You could be getting any random entity that way.

              Thomas Thomassen β€” SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • M Offline
                Mcdull
                last edited by

                @tig said:

                Sorry about the typo for attibute read attribute 😳

                I'm a newer to use sketchup ruby api and i am so careless to find the little mistake.
                thank u very much.u are so kind ~

                1 Reply Last reply Reply Quote 0
                • M Offline
                  Mcdull
                  last edited by

                  i got it,i know that Entity is the parent class,but there is a spelling mistake and i am too careless to find it. thank u very much~

                  1 Reply Last reply Reply Quote 0
                  • B Offline
                    baldaman
                    last edited by

                    Dear jewellers,
                    your discussion give me an idea...
                    If it is possible to define attributes for entities like faces, what about using this method to create an area reporter with the area of each face embeded in an attribute?
                    It would be wonderfull if the area of the face (or collection of faces) could be updated if the geometry is changed... πŸ˜„

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      @baldaman said:

                      Dear jewellers,
                      your discussion give me an idea...
                      If it is possible to define attributes for entities like faces, what about using this method to create an area reporter with the area of each face embeded in an attribute?
                      It would be wonderfull if the area of the face (or collection of faces) could be updated if the geometry is changed... πŸ˜„

                      I have something like that in the workings already.

                      Thomas Thomassen β€” SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • Chris FullmerC Offline
                        Chris Fullmer
                        last edited by

                        I'm amazed that you keep coming back to the observer's Thom πŸ˜„ They have caused you so much pain already.

                        Lately you've been tan, suspicious for the winter.
                        All my Plugins I've written

                        1 Reply Last reply Reply Quote 0
                        • thomthomT Offline
                          thomthom
                          last edited by

                          @chris fullmer said:

                          I'm amazed that you keep coming back to the observer's Thom πŸ˜„ They have caused you so much pain already.

                          well... that's the part I haven't done yet. there is an issue with the area calculation SU does when you have skewed groups/components. haven't gotten to the part of adding the observers yet. But I dread it. I've yet not dared to go back to DoubleCut. 😞

                          Thomas Thomassen β€” SketchUp Monkey & Coding addict
                          List of my plugins and link to the CookieWare fund

                          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