sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Over right the face class

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 212 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.
    • M Offline
      morci429
      last edited by

      Is there a way to over right the face class and add more functions to it?
      What I’m trying to do is add a Boolean attribute generically to the face class called looked_at.
      So that when i do my calculations i can check this variable and see if that face was looked at or not yet

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

        It is always a bad idea to overwrite an existing class. That will cause problems with other scripts in the future. There are ways to make your own class that is a subclass, or just make your own method for faces that examines the face and returns a value. That is safe.

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

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

          @morci429 said:

          Is there a way to over right the face class and add more functions to it?
          What I’m trying to do is add a Boolean attribute generically to the face class called looked_at.
          So that when i do my calculations i can check this variable and see if that face was looked at or not yet

          It is possible to ADD methods to the Face class [or any class for that matter] but it's not recommended that you do this as if other scripters do the same thing with the same method name but different outcome in the method then disaster will ensue for one of you as one version won't work as expected...

          That said, what you describe sounds wholly unsuitable for the Face class anyway - even if you had made such a method it would be set true/false 'generally' at each step, and not for a specific 'face'. If that's what you want a class variable @@lookedat would suffice within your own class, without recourse to messing with the premade classes...
          What I think you really want is a tool that uses an attribute like face.set_attribute("MorciDict","lookedat",true) for a specific face...
          You can add/change this attribute to any face that you tool encounters, and 'looks at'...
          Later when you want to test for them or even to collect these together, you can make a set of all faces in the entities that have that attribute set true, thus.
          lookedatfaces=[] model.active_entities.each{|e|lookedatfaces << e if e.class==Sketchup::Face and e.get_attribute("MorciDict","lookedat",false)}
          Now you have an array of all faces that have been 'lookedat' ?

          I'm puzzled as to how you know a face has been 'lookedat' but that's another issue..........

          TIG

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

            Tig you are right, using AttributeDeictionary is the right way to go and does exactly what i need.
            Thank you

            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