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

    Drawingelement.material and face.back_material? [SOLVED]

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 456 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.
    • P Offline
      Pout
      last edited by Pout

      I just did some tests on a simple face with 4 edges.

      If I use this command (select=the face):
      status=select[0].material="Material1" (drawingelement class)
      then the back side of the face gets material 1

      and if i use this command:
      status=select.back_material="Material1" (face class)
      then the front side of the face gets material 1

      Why is this? And why are these commands seperated over 2 classes?
      And is there any possibility to give a complete selection a certain material at once? (wether it is a combination of lines and faces or a group)

      Thx again.
      Regards

      1 Reply Last reply Reply Quote 0
      • R Offline
        RickW
        last edited by

        I've never had that happen. What code are you using to set "select"? Why are you using select[0] in the first case, and select in the second case? I did a similar test with a 4-edged face, and face.material= always set the front face, and face.back_material= always set the back face.

        Explanation about the different classes:

        An edge is a drawingelement, but it is not a face. It can receive a material, but it cannot receive a back material, having no back. This is the same for curves, text, instances, and groups - they can receive a material, but not a back material.

        A face is a drawingelement as well, and thus inherits the .material= method. However, it does have a back, and can receive a back material. Thus, it has a unique method for that purpose.

        Rather than creating a .material= method for each subclass to drawingelement, it made more sense to create it for drawingelement and let each subclass inherit that method, then add the requisite .back_material= method only for the face subclass.

        Hope that helps,

        RickW
        [www.smustard.com](http://www.smustard.com)

        1 Reply Last reply Reply Quote 0
        • P Offline
          Pout
          last edited by

          This is how i do it:

          I create a face with 4 edges. I select the face
          Ruby console:
          model=Sketchup.active_model
          select=model.selection

          If i then execute the command:
          status=select.material="Material1"
          Error: #<NoMethodError: (eval):149: undefined method material=' for #<Sketchup::Selection:0x474fe88>> (eval):149* if I do this command: *status=select[0].back_material="Material1" Material1 **--> SO THIS IS OK** status=select[1].back_material="Material1" Error: #<NoMethodError: (eval):149: undefined method back_material=' for nil:NilClass>
          (eval):149

          Now today when i try this command:
          status=select.back_material="Material1"
          Error: #<NoMethodError: (eval):149: undefined method `back_material=' for #Sketchup::Selection:0x474fe88>
          (eval):149

          I don't get it anymore 😞
          How can i give all selected objects a certain color/material?

          1 Reply Last reply Reply Quote 0
          • tbdT Offline
            tbd
            last edited by

            Sketchup.active_model.selection.each do |ent|
             ent.material = "Material1" if ent.respond_to? ;material
            end
            
            1. always verify if the receiver supports that (respond_to? :symbol)
            2. dont use [0], [1], ... on a selection - sometime you receive a face, sometime an edge, sometime nil
            3. you can do the same for back_material

            SketchUp Ruby Consultant | Podium 1.x developer
            http://plugins.ro

            1 Reply Last reply Reply Quote 0
            • P Offline
              Pout
              last edited by

              thank you very much 😄

              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