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

    Component definition list from Ruby vs SU window

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 373 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

      I use this code to list all used component definition names:

      def TESTXD.listcompnames1
      		$componentnames=[]
      		Sketchup.active_model.entities.each{|e|
      			TESTXD.listcompnames2(e)
      		}
      		$componentnames.uniq!
      		$componentnames.sort!
      		puts ($componentnames)
      	end
      	def TESTXD.listcompnames2(e)
      		theclass=e.class
      		if theclass==Sketchup;;Group 
      			gen=e.entities
      			gen.each{|gent|
      				TESTXD.listcompnames2(gent)
      			}
      		elsif theclass==Sketchup;;ComponentInstance
      			$componentnames<<e.definition.name
      			e.definition.entities.each{|ent|
      				TESTXD.listcompnames2(ent)
      			}
      		end
      	end
      

      This gives me a list in the ruby console.
      Now if I compare this list with the list shown in the components windows I see that certain definitions are available in ruby but not in the components window.

      Is this due to the fact that those component definitions are only used in nested component definitions? That makes no sense.
      Or maybe I'm missing something.

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

        ok, hitting 'Expand' would be a good idea 😳 😳 😳 😳

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

          If you have a lot of model entities, duplicate instances etc it can take a while to sift through it all.
          It's quicker to iterate the model.definitions and compile lists of 'names' [or references] for all groups, components, used-components, unused-components and images thus

          defs=Sketchup.active_model.definitions
          groups=[]; group_defs=[]; group_refs=[]; images=[]
          compo_names=[]; used_compo_names=[]; unused_compo_names=[]
          compo_refs=[]; compos_instances=[]
          compos_instances_names=[]; compos_instances_refs=[]
          defs.each{|d|
            if d.image?
              images << d.name
            elsif d.group?
              groups << d.instances[0].name
              group_defs << d
              group_refs << d.instances
            else ### compo
              compo_names << d.name
              if d.instances[0]
                used_compo_names << d.name
              else ### unused
                unused_compo_names << d.name
              end
              compo_refs << d
              compo_instances << d.instances
              ins=[]; d.instances.each{|i|ins << i.name}
              compo_instances_names << [d.name, ins]
              compo_instances_refs << [d, d.instances]
            end
          }
          

          Choose which data you want to extract for later use...

          TIG

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

            Note that the DefinitionList include groups and images as well. As TIG mentioned, some components are hidden by default in SketchUp's Component Browser - sub-component of imported models for instance. They are marked with ComponentDefinition.internal?.

            Detailed explanation of the ComponentList and ComponentDefinitions in SketchUp: http://www.thomthom.net/thoughts/2012/02/definitions-and-instances-in-sketchup/

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

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

              great, thank you both for the information!

              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