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

    Face-tag number

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 4 Posters 547 Views 4 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.
    • renderizaR Offline
      renderiza
      last edited by

      Here is an attempt to pick faces that have same area size and paint them. It is limited to up to five different area size for faces but you can modify it to add more. Not sure if this is the way to go but at least is a starting point and if I find better way I will share it. Also this does not add the tag object on top of face at the moment.

      model = Sketchup.active_model
      @sel = model.selection
      ents = model.active_entities
      
      faces = ents.grep(Sketchup;;Face)
      @cw1 = []
      @cw2 = []
      @cw3 = []
      @cw4 = []
      @cw5 = []
      
      faces.each do |face|
      	
          #######
          ## A ##
          #######
          if @cw1.first == nil 
              if face.area.to_i != @cw2area and face.area.to_i != @cw3area and face.area.to_i != @cw4area and face.area.to_i != @cw5area
                  @cw1 << face
                  @cw1area = face.area.to_i   
              end
          end
      	
          if @cw2.first == nil
              if face.area.to_i != @cw1area and face.area.to_i != @cw3area and face.area.to_i != @cw4area and face.area.to_i != @cw5area
                  @cw2 << face
                  @cw2area = face.area.to_i
              end
          end
      	
          if @cw3.first == nil
              if face.area.to_i != @cw1area and face.area.to_i != @cw2area and face.area.to_i != @cw4area and face.area.to_i != @cw5area
                  @cw3 << face
                  @cw3area = face.area.to_i
              end
          end
      	
          if @cw4.first == nil
              if face.area.to_i != @cw1area and face.area.to_i != @cw2area and face.area.to_i != @cw3area and face.area.to_i != @cw5area
                  @cw4 << face
                  @cw4area = face.area.to_i
              end
          end
      	
          if @cw5.first == nil
              if face.area.to_i != @cw1area and face.area.to_i != @cw2area and face.area.to_i != @cw3area and face.area.to_i != @cw4area
                  @cw5 << face
                  @cw5area = face.area.to_i
              end
          end
      
      
          #######
          ## B ##
          #######
          model = Sketchup.active_model
          materials = model.materials
          
          if face.area.to_i == @cw1area
              @cw1 << face
              face.material = [255,0,0]
          end
      	
      	if face.area.to_i == @cw2area
              @cw2 << face
              face.material = [0,255,0]
          end
      	
      	if face.area.to_i == @cw3area
               @cw3 << face
               face.material = [0,0,255]
          end
      	
      	if face.area.to_i == @cw4area
               @cw4 << face
               face.material = [255,0,255]
          end
      	
      	if face.area.to_i == @cw5area
               @cw5 << face
               face.material = [255,255,0]
          end
      	
      end 
      

      If you have any questions or suggestion please let me know...cheers!

      [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

      1 Reply Last reply Reply Quote 0
      • renderizaR Offline
        renderiza
        last edited by

        @pingpink said:

        I noticed the same face area of the sloped faces and the upright faces , they have different colours.I don't know why it happens for this time , I will look later.

        Not sure myself why that is happening but will look into it.

        @pingpink said:

        I just tried to map components on coloured faces , but I have to select faces and a panel component together to place and copy on the faces.
        Not sure that I have to do the attribute's name on coloured faces to have the same names as component's names for component mapping.

        To avoid having to select coponents and faces manually maybe try adding the code below to the one on top. Note that you have to name the component definition name manually.

        
        components = ents.grep(Sketchup;;ComponentInstance)
        
        #########
        ## cw1 ##
        #########
        components.each do |component|
        	if component.definition.name == "cw1"
        		@sel.add component
        	end
        end
        @sel.add @cw1
        
        #####################################################
        ## Put code that place component copy to face here ##
        #####################################################
        
        @sel.clear #Clears selection to select cw2
        
        #########
        ## cw2 ##
        #########
        components.each do |component|
        	if component.definition.name == "cw2"
        		@sel.add component
        	end
        end
        @sel.add @cw2
        
        #####################################################
        ## Put code that place component copy to face here ##
        #####################################################
        
        @sel.clear
        
        #########
        ## cw3 ##
        #########
        components.each do |component|
        	if component.definition.name == "cw3"
        		@sel.add component
        	end
        end
        @sel.add @cw3
        
        #####################################################
        ## Put code that place component copy to face here ##
        #####################################################
        
        @sel.clear
        
        #########
        ## cw4 ##
        #########
        components.each do |component|
        	if component.definition.name == "cw4"
        		@sel.add component
        	end
        end
        @sel.add @cw4
        
        #####################################################
        ## Put code that place component copy to face here ##
        #####################################################
        
        @sel.clear
        
        #########
        ## cw5 ##
        #########
        components.each do |component|
        	if component.definition.name == "cw5"
        		@sel.add component
        	end
        end
        @sel.add @cw5
        
        #####################################################
        ## Put code that place component copy to face here ##
        #####################################################
        

        Hope this helps and your plugin look very good from the video I saw...very impressive! 👍

        [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

        1 Reply Last reply Reply Quote 0
        • pingpinkP Offline
          pingpink
          last edited by

          Thank you kindly for your recommendation , it's my task to do facade modeling. I'm revising codes in each module now to make it better.

          I'm curious that Is there a way to do a code for copying different coloured panels and lay down on a base in the program ? For example , in a picture there are 2 different panels and I want to copy out. So, it can reduce a time of copying faces to draw patterns and convert to components, and then do mapping prototype panels back onto faces.


          Copy different panels to make a component later.

          1 Reply Last reply Reply Quote 0
          • renderizaR Offline
            renderiza
            last edited by

            Hi, here is one example on how to do what you mentioned. Add the following code bellow the one on top...

            
            @model = Sketchup.active_model
            @sel = @model.selection
            @ents = @model.active_entities
            
            ###
            if @cw1.first != nil
            	@sel.clear
            	cw1sample = @cw1.first
            	@sel.add cw1sample
            	cw1group = @ents.add_group(@sel)
            
            	tr1 = Geom;;Transformation.new([0, -300, 0])
            	instance = @ents.add_instance(cw1group.definition, tr1)
            	instance.transform!(tr1)
            end
            ###
            if @cw2.first != nil
            	@sel.clear
            	cw2sample = @cw2.first
            	@sel.add cw2sample
            	cw2group = @ents.add_group(@sel)
            
            	tr1 = Geom;;Transformation.new([200, -300, 0])
            	instance = @ents.add_instance(cw2group.definition, tr1)
            	instance.transform!(tr1)
            end
            ###
            if @cw3.first != nil
            	@sel.clear
            	cw3sample = @cw3.first
            	@sel.add cw3sample
            	cw3group = @ents.add_group(@sel)
            
            	tr1 = Geom;;Transformation.new([400, -300, 0])
            	instance = @ents.add_instance(cw3group.definition, tr1)
            	instance.transform!(tr1)
            end
            ###
            if @cw4.first != nil
            	@sel.clear
            	cw4sample = @cw4.first
            	@sel.add cw4sample
            	cw4group = @ents.add_group(@sel)
            
            	tr1 = Geom;;Transformation.new([600, -300, 0])
            	instance = @ents.add_instance(cw4group.definition, tr1)
            	instance.transform!(tr1)
            end
            ###
            if @cw5.first != nil
            	@sel.clear
            	cw5sample = @cw5.first
            	@sel.add cw5sample
            	cw5group = @ents.add_group(@sel)
            
            	tr1 = Geom;;Transformation.new([800, -300, 0])
            	instance = @ents.add_instance(cw5group.definition, tr1)
            	instance.transform!(tr1)
            end
            

            I had to make face that you want to copy & move a group so at the end they are still groups. Not sure if you want to explode them back to lose face but I am sure there is a way to do that. Anyways hope this help...cheers!

            [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

            1 Reply Last reply Reply Quote 0
            • pingpinkP Offline
              pingpink
              last edited by

              Thank you so much ! , The code is amazing to copy tag faces. The group result suits with my code to convert groups to components and create the center axis on the panel plane , but my code can do mapping components on faces only the component which is parallel to the floor, not vertical exactly copy from the model. So , I tried to rotate panels by this code :

                 #tr1 = Geom;;Transformation.new([0, -300, 0])
                 pt = [300,0,0]
                 v = Geom;;Vector3d.new(1,0,0) # The axis position to rotate opanel
                 tr1 = Geom;;Transformation.rotation(pt,v,-45.degrees)
                 instance = @ents.add_instance(cw1group.definition, tr1)
                 instance.transform!(tr1)
              
              The code cannot be used properly if there is a slope panel group . The outcome of rotation could not be flat plane rotation. In the image , the rotation have to be like this , so the components can be placed fit onto the subdividing faces.
              
              Ah,I just found the example of rotation in this link. I think it works :    [http://sketchucation.com/forums/viewtopic.php?f=15&t=41419](http://sketchucation.com/forums/viewtopic.php?f=15&t=41419)
              

              Thanks once again for good advice.


              Rotate panels parallel to the floor

              1 Reply Last reply Reply Quote 0
              • renderizaR Offline
                renderiza
                last edited by

                Hi, this might be the way to get them all flat...

                
                @model = Sketchup.active_model
                @sel = @model.selection
                @ents = @model.active_entities
                
                ###
                if @cw1.first != nil
                   @sel.clear
                   cw1sample = @cw1.first
                   @sel.add cw1sample
                   
                   faces = @sel.grep(Sketchup;;Face)
                   faces.each do |face|
                       PI = Math.acos(-1)
                       @rot = Math;;acos(face.normal.z)*(180/PI)
                   end
                     
                   cw1group = @ents.add_group(@sel)
                
                   tr1 = Geom;;Transformation.rotation(ORIGIN, X_AXIS, -@rot.degrees)
                   tr2 = Geom;;Transformation.new([0, -300, 0])
                  
                   instance = @ents.add_instance(cw1group.definition, tr1)
                   instance = instance.transform!(tr2)
                end
                ###
                if @cw2.first != nil
                   @sel.clear
                   cw2sample = @cw2.first
                   @sel.add cw2sample
                
                   faces = @sel.grep(Sketchup;;Face)
                   faces.each do |face|
                       PI = Math.acos(-1)
                       @rot = Math;;acos(face.normal.z)*(180/PI)
                   end
                  
                   cw2group = @ents.add_group(@sel)
                   
                   tr1 = Geom;;Transformation.rotation(ORIGIN, X_AXIS, -@rot.degrees)
                   tr2 = Geom;;Transformation.new([200, -300, 0])
                  
                   instance = @ents.add_instance(cw2group.definition, tr1)
                   instance = instance.transform!(tr2)
                   
                end
                ###
                if @cw3.first != nil
                   @sel.clear
                   cw3sample = @cw3.first
                   @sel.add cw3sample
                
                   faces = @sel.grep(Sketchup;;Face)
                   faces.each do |face|
                       PI = Math.acos(-1)
                       @rot = Math;;acos(face.normal.z)*(180/PI)
                   end
                   
                   cw3group = @ents.add_group(@sel)
                   
                   tr1 = Geom;;Transformation.rotation(ORIGIN, X_AXIS, -@rot.degrees)
                   tr2 = Geom;;Transformation.new([400, -300, 0])
                  
                   instance = @ents.add_instance(cw3group.definition, tr1)
                   instance = instance.transform!(tr2)
                end
                ###
                if @cw4.first != nil
                   @sel.clear
                   cw4sample = @cw4.first
                   @sel.add cw4sample
                
                   faces = @sel.grep(Sketchup;;Face)
                   faces.each do |face|
                       PI = Math.acos(-1)
                       @rot = Math;;acos(face.normal.z)*(180/PI)
                   end
                   
                   cw4group = @ents.add_group(@sel)
                   
                   tr1 = Geom;;Transformation.rotation(ORIGIN, X_AXIS, -@rot.degrees)
                   tr2 = Geom;;Transformation.new([600, -300, 0])
                  
                   instance = @ents.add_instance(cw4group.definition, tr1)
                   instance = instance.transform!(tr2)
                end
                ###
                if @cw5.first != nil
                   @sel.clear
                   cw5sample = @cw5.first
                   @sel.add cw5sample
                
                   faces = @sel.grep(Sketchup;;Face)
                   faces.each do |face|
                       PI = Math.acos(-1)
                       @rot = Math;;acos(face.normal.z)*(180/PI)
                   end
                   
                   cw5group = @ents.add_group(@sel)
                   
                   tr1 = Geom;;Transformation.rotation(ORIGIN, X_AXIS, -@rot.degrees)
                   tr2 = Geom;;Transformation.new([800, -300, 0])
                  
                   instance = @ents.add_instance(cw5group.definition, tr1)
                   instance = instance.transform!(tr2)
                end
                
                

                Hope this is what you were looking for...cheers!

                [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                1 Reply Last reply Reply Quote 0
                • pingpinkP Offline
                  pingpink
                  last edited by

                  Thank you very very much Renderiza !
                  After running a code , there's an error about the constant's name of " PI "

                  PI = Math.acos(-1)
                  

                  So , I changed it to be

                  pi = Math.acos(-1)
                  

                  And it works perfectly to copy out the different panel types !

                  I'm wondering again , in case of " RE-TAG NO." of face to change a new name and
                  a new colour. I defined the variables to relate with the function of copyout_rotate2.rb

                  @cw6 = []
                  @cw7 = []
                  @cw8 = []
                  @cw9 = []
                  @cw10 = []
                  

                  But there's a SyntaxError in this part of condition between 'and'...
                  Not sure if there's a limitation of values. My intention is to do a copy flat panel at the end result after finished tagging panels , but in some cases of same area panel would have different patterns or materials , so they should have different names , and colours to replace the correct panel components.

                  if @cw1.first == nil 
                                if face.area.to_i != @cw2area 
                  				and face.area.to_i != @cw3area 
                  				and face.area.to_i != @cw4area 
                  				and face.area.to_i != @cw5area
                  				and face.area.to_i != @cw6area
                  				and face.area.to_i != @cw7area
                  				and face.area.to_i != @cw8area
                  				and face.area.to_i != @cw9area
                  				and face.area.to_i != @cw10area
                              @cw1 << face
                              @cw1area = face.area.to_i   
                          end
                      end
                  

                  The RE-TAG IDEA


                  Example of re-tag and copy out a panel on a model base


                  This is a re-tag option


                  Copy out the different coloured faces

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

                    But then again...
                    Math::PI
                    gives you PI without the convolution,
                    as does
                    180.degrees

                    I don't understand the unneeded complexity...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • tt_suT Offline
                      tt_su
                      last edited by

                      Pi is part of the Math module: Math::PI

                      Also, beware that there is an important difference between and and && as well as or and ||. https://www.tinfoilsecurity.com/blog/ruby-demystified-and-vs

                      1 Reply Last reply Reply Quote 0
                      • pingpinkP Offline
                        pingpink
                        last edited by

                        Thanks TIG , tt_su

                         pi = Math::PI is Math.acos(-1) ?
                        
                         It has a same result after testing a code.
                        
                         I read in the link , thinking that it should be put in a pair at the same line.
                         There's no errors.It works!
                        
                         if @cw1.first == nil 
                                      if face.area.to_i != @cw2area and face.area.to_i != @cw3area and 
                        			  face.area.to_i != @cw4area and face.area.to_i != @cw5area and 
                        			  face.area.to_i != @cw6area and face.area.to_i != @cw7area and
                        			  face.area.to_i != @cw8area and face.area.to_i != @cw9area and 
                        			  face.area.to_i != @cw10area
                                    @cw1 << face
                                    @cw1area = face.area.to_i   
                                end
                            end
                        
                          BUT , it my RE_TagNo.rb seems doesnt't link with the copyout_rotate2_and.rb to bring out the re-tag face panel.
                        
                        ###### ADDING 
                        	faces = sel.grep(Sketchup;;Face)
                        	@cw6 = []
                        	@cw7 = []
                        	@cw8 = []
                        	@cw9 = []
                        	@cw10 = []
                        
                        	
                        	faces.each do |face|
                        		if @cw6.first == nil
                                    @cw6area = face.area.to_i
                        	
                        		elsif @cw7.first == nil
                                    @cw7area = face.area.to_i
                        
                        		elsif @cw8.first == nil
                                    @cw8area = face.area.to_i
                        	
                        		elsif @cw9.first == nil
                                    @cw9area = face.area.to_i
                        
                        		else @cw10.first == nil
                                    @cw10area = face.area.to_i
                        		end
                        	end
                        
                        if input[1] == "Orange"
                           
                               #attribute_name = input[0].name
                               #face.area.to_i == @cw6area
                        	   
                               faces.each do |e|	   
                        	   e.material = [255,165,0]#Orange
                        	   end 
                        

                        copyout_rotate2_and.rb


                        RE_TagNo.rb

                        1 Reply Last reply Reply Quote 0
                        • pingpinkP Offline
                          pingpink
                          last edited by

                          Thank you very much,Renderiza !

                               I've tested the codes , it works very good.I can see the different panel types by coloured faces. I noticed the same face area of the sloped faces and the upright faces , they have different colours.I don't know why it happens for this time , I will look later.
                               I just tried to map components on coloured faces , but I have to select faces and a panel component together to place and copy on the faces.
                               Not sure that I have to do the attribute's name on coloured faces to have the same names as component's names for component mapping.
                          
                          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