• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

New Material Methods! (With bugs :( )

Scheduled Pinned Locked Moved Developers' Forum
25 Posts 7 Posters 4.1k Views
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.
  • T Offline
    thomthom
    last edited by 15 Jan 2011, 00:00

    http://code.google.com/apis/sketchup/docs/releases.html

    @unknownuser said:

    Expanded the Material Class
    New methods:
    Material.remove
    Material.name=
    Material.write_thumbnail

    NOTE: There's a type here: it's Materials.remove(material)

    Bug Alert! 😒
    Sketchup::Materials.remove
    When you erase a material with materials.remove the entities with the material doesn't revert back to default materials. The material disappear from the material list, but is still applied to materials in the model.
    When you use "Fix Problem" it will report lots of invalid materials and it will then remove the material from the front side, but leave the back side with the invalid material.

    Workaround (annoyingly this means traversing the entire model - so it's not the fastest.)

    <span class="syntaxdefault"><br />def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">save_remove_material</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> material</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> model </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  for e in model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br />    e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">material </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> nil if e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">respond_to</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">material </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&&</span><span class="syntaxdefault"> e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">material </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> material<br />    e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">back_material </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> nil if e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">respond_to</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">back_material </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&&</span><span class="syntaxdefault"> e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">back_material </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> material<br />  end<br />  for d in model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definitions<br />    next if d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">image</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault">    for e in d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br />      e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">material </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> nil if e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">respond_to</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">material </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&&</span><span class="syntaxdefault"> e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">material </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> material<br />      e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">back_material </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> nil if e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">respond_to</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">back_material </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&&</span><span class="syntaxdefault"> e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">back_material </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> material<br />    end<br />  end<br />end<br /></span>
    

    InvalidMaterial.png

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

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 15 Jan 2011, 01:20

      @thomthom said:

      http://code.google.com/apis/sketchup/docs/releases.html

      @unknownuser said:

      Expanded the Material Class
      New methods:
      Material.remove
      Material.name=
      Material.write_thumbnail

      NOTE: There's a typo here: it's Materials.remove(material)

      You mean it's an instance method of the Materials collection.

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • P Offline
        Pixero
        last edited by 15 Jan 2011, 07:31

        @thomthom said:

        There's a type here: it's Materials.remove(material)

        That's a great addition. I have some ideas that would greatly benefit from this... πŸ€“

        1 Reply Last reply Reply Quote 0
        • S Offline
          simon le bon
          last edited by 15 Jan 2011, 09:15

          but no retro compatibility 😒

          http://i274.photobucket.com/albums/jj245/Spendauballet/SketchUp/NewMaterialMethods.jpg
          *s

          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 15 Jan 2011, 11:10

            @thomthom said:

            NOTE: There's a type here: it's Materials.remove(material)

            Oh great, a typo in my typo notice. πŸ˜’ 😳

            @simon le bon said:

            but no retro compatibility 😒

            No. That's evolution for yah. With the changes and additions in SU8 there might be some plugins that will require SU8 as a minimum.

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

            1 Reply Last reply Reply Quote 0
            • T Offline
              thomthom
              last edited by 15 Jan 2011, 11:13

              Just hope that no one had extended Material.name= anywhere. πŸ˜•
              Dan: did you say there was a way to detect if a method had been overwritten?

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

              1 Reply Last reply Reply Quote 0
              • T Offline
                TIG Moderator
                last edited by 15 Jan 2011, 11:37

                @thomthom said:

                Just hope that no one had extended Material.name= anywhere. πŸ˜•
                Dan: did you say there was a way to detect if a method had been overwritten?

                This is 'detected' in my additional class methods and the code only makes the new method if it doesn't already exist...
                Amongst others there are material.name='newname', material.delete and material.save_thumbnail('filepath') that mimic these new methods in this v8 only... so they get made in earlier versions as needed - see http://forums.sketchucation.com/viewtopic.php?p=301258#p301258
                So

                
                class Sketchup;;Material
                  if not Sketchup;;Material.method_defined?(;name=)
                   def name=(new_name=nil)
                     ### etc code to rename material
                   end#def
                  end#if
                end#class
                

                etc etc

                TIG

                1 Reply Last reply Reply Quote 0
                • D Offline
                  Dan Rathbun
                  last edited by 15 Jan 2011, 17:11

                  SO TIG you may wish to update your extension then to alias the method names write_thumbnail() and remove() ??

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 15 Jan 2011, 17:16

                    But there is no knowing of which other plugins has done this. There's a number of them that extended Group, Image and Array. It would be interesting to make a script that could scan the base classes for modification and map them. To get a feel of how the general state of the SU Ruby environment.

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

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      Dan Rathbun
                      last edited by 15 Jan 2011, 17:56

                      @thomthom said:

                      But there is no knowing of which other plugins has done this.

                      Dont say there is no way, just because you don't know how (..YET,) ... remember Ruby is cool! Ruby will find a way, or allow a way through it's immaculate dynamistic glory.
                      β˜€

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        TIG Moderator
                        last edited by 15 Jan 2011, 18:39

                        @dan rathbun said:

                        SO TIG you may wish to update your extension then to alias the method names write_thumbnail() and remove() ??

                        I could - trust Google not to copy my naming conventions!

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          Dan Rathbun
                          last edited by 15 Jan 2011, 19:18

                          @tig said:

                          @dan rathbun said:

                          SO TIG you may wish to update your extension then to alias the method names write_thumbnail() and remove() ??

                          I could - trust Google not to copy my naming conventions!

                          They could be following the conventions they have established already in the API .. although they didn't in this case (which really irks me to no end.. a quick check of the API methods index is all it takes.. before 'inventing' a new method..)

                          All the other thumbnail methods use " save_thumbnail()"
                          " write" was used for images, textures, and IO operations, such as defaults to plist or registry.

                          " remove()" was used when you 'dettached' an item from something else, but did not actually delete or dipose of it, as in an observer, or removing entity references from the selection set.

                          " delete()" was used when you actually wanted to dispose of something, such as deleting an attribute, dictionary, or a set.

                          So the question is.. did they follow their OWN conventions with these new methods??

                          I'm not here much anymore.

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            thomthom
                            last edited by 15 Jan 2011, 22:02

                            And why would the delete method be part of Materials instead of Material ?

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

                            1 Reply Last reply Reply Quote 0
                            • D Offline
                              Dan Rathbun
                              last edited by 15 Jan 2011, 22:10

                              @thomthom said:

                              And why would the delete method be part of Materials instead of Material ?

                              Because self.kill is suicidal, socially unacceptable, and often religiously repugnant.

                              Seriously, an object does not often dispose of itself, especially when it's a member of a collection. The collection class has a method(s) to dispose of one (or more,) of it's members. Ie Array instance methods: .shift, .pop, .slice etc....

                              I'm not here much anymore.

                              1 Reply Last reply Reply Quote 0
                              • T Offline
                                thomthom
                                last edited by 15 Jan 2011, 22:13

                                entity.erase! ... πŸ˜’ πŸ˜„

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

                                1 Reply Last reply Reply Quote 0
                                • D Offline
                                  Dan Rathbun
                                  last edited by 15 Jan 2011, 22:44

                                  @thomthom said:

                                  entity.erase! ... πŸ˜’ πŸ˜„

                                  (1) that's not a Ruby method.. it's a Google written method (that doesn't really follow convention.)

                                  (2) It uses the **!** ("in place",) suffix to denote the operation is immediate against the receiver... BUT it is actually just an alias for Sketchup::Entities#erase_entities(receiver)
                                  πŸ€“
                                  .. yes there are bound to be variances ... likely caused by human error.

                                  I'm not here much anymore.

                                  1 Reply Last reply Reply Quote 0
                                  • T Offline
                                    thomthom
                                    last edited by 17 Jan 2011, 15:21

                                    Cursed! Materials.remove is bugged! http://forums.sketchucation.com/viewtopic.php?f=180&t=34217&p=301158#p301158

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

                                    1 Reply Last reply Reply Quote 0
                                    • T Offline
                                      TIG Moderator
                                      last edited by 17 Jan 2011, 15:44

                                      So material.remove doesn't exist BUT is in the API docs ???
                                      Then materials.remove(material) exists but doesn't work as expected !!!

                                      What is going on ???

                                      At least my 'clunky' old material.delete works... and it reverts all objects that were using that material to have 'nil'! [but it does have to traverse all model.entities and definition.entities too to achieve it !]

                                      TIG

                                      1 Reply Last reply Reply Quote 0
                                      • T Offline
                                        thomthom
                                        last edited by 17 Jan 2011, 15:47

                                        @tig said:

                                        So material.remove doesn't exist BUT is in the API docs ???

                                        Yes - the docs where wrong.

                                        @tig said:

                                        At least my 'clunky' old material.delete works... and it reverts all objects that were using that material to have 'nil'! [but it does have to traverse all model.entities and definition.entities too to achieve it !]

                                        Yea. When using Materials.remove you still need to iterate the whole model, but at least one doesn't ahve to create temp groups and use purge.
                                        Too bad this method is bugged when it finally appeared.

                                        But material.name= seem to work fine. Which is very good as one doesn't need to clone a new variant of the material.

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

                                        1 Reply Last reply Reply Quote 0
                                        • J Offline
                                          jhauswirth
                                          last edited by 20 Jan 2011, 14:54

                                          @tig said:

                                          Then materials.remove(material) exists but doesn't work as expected !!!

                                          What is going on ???

                                          It is working as intended. It would all make sense if you guys could see how the Ruby API is implemented in SU.
                                          The Ruby API is a very thin wrapper around our C++ code. So in this case we have a CMaterialManager class
                                          in SU and the Ruby Materials class wraps CMaterialManager. When you get Materials from the model you get the
                                          Ruby wrapper around CMaterialManager. CMaterialManager knows nothing about the model. Its just
                                          a std::vector<CMaterial*> CMaterialVec; and all Materials.remove does is call
                                          CMaterialManager.RemoveMaterial(CMaterial*), which just removes the given material from the CMaterialVec.
                                          What everyone is asking for is probably a new method in model called model.remove_material (you guys can start
                                          another thread on what it should be called). This new method would live in model because
                                          model owns Materials and the entities that are assigned the materials. So model has all the info
                                          needed to implement what you are asking for. Sorry for messing this up, I sneaked these new methods
                                          in right before release which didn't get properly reviewed by the beta group because there were no
                                          release notes made for the new methods.

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

                                          Advertisement