• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

How to fetch all material in SKP via Ruby?

Scheduled Pinned Locked Moved Developers' Forum
2 Posts 2 Posters 222 Views 2 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.
  • R Offline
    rahulnejanawar
    last edited by rahulnejanawar 10 Apr 2014, 10:46

    Hi,

    Is it possible to fetch all material items which are appear in the Sketchup materials window by ruby?
    Is there any function which do the above work ie which can access the all items(material type) in the Materials?

    I found that the below function which works for Model-

    
    model = Sketchup.active_model
    matrials = model.materials
    materials[0].name ==> gives name of the material
    

    Like this above any other function by which we can retrieve the all Material items which are present in Sketchup Materials(class index).

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 10 Apr 2014, 11:34

      You can only access the Materials that are loaded into the Model.
      You can iterate the list and get various aspects of the material.

      Sketchup.active_model.materials.each{|material|
        puts material.name
        puts material.display_name
        puts material.color
        puts material.alpha
        puts material.texture
        ### and so on...
        puts
      }
      

      I have included the puts so the info is shown in the Ruby Console but of course you can do other things with that...
      A Material's '.display_name' is not always the same as the '.name' [depends on its creation/source]
      A Texture can also be further probed to get info like its image, size and so on...

      Read the API http://www.sketchup.com/intl/en/developer/docs/classes.php

      If you must get details of SKM files not yet loaded [and not loadable using native API methods] then you could look at my SKMtools which offer many additional tools to import/export/interrogate SKM files etc...
      But please learn to walk before you run 😉

      TIG

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

      Advertisement