sketchucation logo sketchucation
    • Login
    1. Home
    2. Doi
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download
    D
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 3
    • Groups 1

    Doi

    @Doi

    10
    Reputation
    1
    Profile views
    3
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    Doi Unfollow Follow
    registered-users

    Latest posts made by Doi

    • RE: How do you make individual components

      Wow TIG,

      thank you so much! Both edits work a treat πŸ˜„, but yes yours is definitely more succinct - I have always had issues with my code being a tad too verbose, and possibly missing the trees for the forest... 😳

      After my previous post, I was thinking it did seem odd that I wasn't working directly with the definition, but I'm sure I would never have found it without the help β˜€

      Thanks again - now onto the next tweak...

      Cheers,
      Doi!

      posted in Plugins
      D
      Doi
    • RE: How do you make individual components

      Hi TIG,

      thanks for the clarification, it is nice to know I wasn't completely lost and was heading down the right track in one of my circular attempts - when I encountered an "All entities must have a common parent" error I went back to my initial attempt for my first post... πŸ˜‰

      The current issue now seems to be that my exploded_entities need a reference to their 'parent' before being added to the group, yet I thought this is what add_group/to_component process was doing? From what I understand from the API, you must have a Component Instance first, then use it to create the Component Definition - then multiple Instances can be created under the Definition?

      Using your example, my code becomes:

      orig_entities = Sketchup.active_model.entities
      ### Note; there is (correctly) no difference between calling .entities, or .active_entities here
      ...
      #re-create component
      temp_group =  orig_entities.add_group(exploded_component)
      adj_component = temp_group.to_component
      adj_definition = adj_component
      adj_definition.name= orig_definition.name
      adj_definition.description= orig_definition.description
      

      The console throws:
      Console02.PNG

      Line 42 is the temp_group = orig_entities.add_group(exploded_component) method call.

      If it helps, here is the entire script:

      require 'sketchup.rb'
      
      #
      #
      #
      def parsecomponents
      	# containers
      	adjustedcomps = Sketchup;;Entities.new
      	# data
      	model = Sketchup.active_model
      	orig_entities = model.entities
      	
      	layers = model.layers
      	unattached_layer = layers.add "Unattached Elements" #anything that ends up here to be deleted...
      	
      	puts "Starting-----------------------------"
      	orig_entities.each do |e|
      		case e
      			when Sketchup;;ComponentInstance
      				totalfaces = 0
      				adjusted = 0
      				orig_definition = e.definition
      				orig_transform = e.transformation
      				# output working component
      				puts e.typename + "; " + orig_definition.name
      				if exploded_component = e.explode
      					puts "Exploded into; " + exploded_component.class.to_s
      					# parse component entities
      					exploded_component.each do |ce|
      						# swap material if required
      						if ce.is_a? Sketchup;;Face
      							totalfaces += 1
      							if !ce.material && ce.back_material
      								ce.material= ce.back_material
      								ce.back_material= nil
      								adjusted += 1
      							end #end if
      						end #end if
      					end #end do	
      					
      					#re-create component
      					temp_group =  Sketchup.active_model.entities.add_group(exploded_component)
      					adj_component = temp_group.to_component
      					adj_definition = adj_component
      					adj_definition.name= orig_definition.name
      					adj_definition.description= orig_definition.description
      						
      					puts "Recreated; " + adj_definition.name
      					puts "Total Faces; " + totalfaces.to_s + ";;Adjusted; " + adjusted.to_s
      				else
      					UI.messagebox "Failed to Explode Component!"
      				end
      			else 
      				# anything other than a component is not wanted...
      				e.layer= unattached_layer
      				puts e.typename + " moved to Unattached Layer!"
      			end # end case
      	end # end do
      	puts
      	puts "Completed----------------------"
      end # end parsecomponents
      
      ###########################################
      if(file_loaded("swapmaterials02.rb"))
      	menu = UI.menu("Plugins");
      	menu.add_item("Parse Model") {parsecomponents}
      end
      #------------------------------------------
      
      file_loaded("swapmaterials02.rb")
      

      Cheers Doi! πŸ’š

      posted in Plugins
      D
      Doi
    • RE: How do you make individual components

      Hi,

      My first post, so before anything else, hello πŸ˜„

      A bit of background on my component issue...
      I have a model that I have 'inherited' (approximately 130 buildings) that need to be cleaned up - basically lots of unconnected entities, and components with materials applied to the back face etc. I have thrown together a quick and dirty script to fix these issues (I was a little surprised at how easy it was to fix all that; ruby is very nice to use) πŸ˜‰
      Where things have gone a little screwy, is when I try to re-create the individual components.

      All my searching keeps pointing me back to the API documentation, which is fine, but I must not be interpreting it correctly, and am now just going round in circles?..

      The basic process I am trying to do is:

      temp_group = exploded_entities.add_group
      adjusted_component = temp_group.to_component
      

      The API docs state that calling the explode method on a ComponentInstancewill return an Entitiesobject. I read this as an Entities container (array?) filled with the individual Entityobjects that make up the building - the Entities container class is the only one with the add_group method!?
      Functionally I am able to access the exploded building as expected, as I said above the clean up steps work no worries, what I am finding is that the exploded_entities object is of type Array and as such throws a no method error when calling add_group?

      Here is the code in question:

      # output working component
      puts e.typename + "; " + compname
      if exploded_component = e.explode
        puts "Exploded into; " + exploded_component.class.to_s
        # parse component entities
        exploded_component.each do |ce|
          ...fixing stuff here
        end #end do
      	
      #re-create component
      temp_group =  exploded_component.add_group
      adj_component = temp_group.to_component
      				
      puts "Recreated; " + adj_component.name
      puts "Total Faces; " + totalfaces.to_s + ";;Adjusted; " + adjusted.to_s
      

      Here is the console output:
      console.PNG

      I know it'll be something really simple - it usually is πŸ˜•

      Thanks in advance

      posted in Plugins
      D
      Doi