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

    How to cut from object

    Scheduled Pinned Locked Moved Developers' Forum
    47 Posts 4 Posters 3.9k 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.
    • A Offline
      ado130
      last edited by

      I am slightly confused now 😄 because before you said

      @unknownuser said:

      You don't need to add the edges to a new group.
      raw it directly over the face in the active_entities.
      edges = Sketchup.active_model.active_entities.add_circle(center, dir, radius, segs)

      So what should I do?
      If I understood Sam correctly, I need sth like
      group = Sketchup.active_model.active_entities.add_group() gents = group.entities active_faces = model.active_entities.grep(Sketchup::Face) edges = gents.add_circle(center, dir, radius) group.explode circle_face = model.active_entities.grep(Sketchup::Face) - active_faces
      .. and then?
      I'm not sure what is meant by "add a group inside the original group".

      By the way, thanks Sam, or, thanks to both.

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        @ado130 said:

        group = Sketchup.active_model.active_entities.add_group() gents = group.entities active_faces = model.active_entities.grep(Sketchup::Face) edges = gents.add_circle(center, dir, radius) group.explode circle_face = model.active_entities.grep(Sketchup::Face) - active_faces
        .. and then?
        I'm not sure what is meant by "add a group inside the original group".

        By the way, thanks Sam, or, thanks to both.

        ###group = Sketchup.active_model.active_entities.add_group();
        ### remove previous statement since you have already defined "group".
        gents = group.entities
        active_faces = gents.grep(Sketchup;;Face);### modified
        circle_group = gents.add_group; cge = circle_group.entities;### new
        edges = cge.add_circle(center, dir, radius);### modified
        circle_group.explode;### new
        circle_face = (gents.grep(Sketchup;;Face) - active_faces)[0];### modified
        
        

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • A Offline
          ado130
          last edited by

          I had never defined the group in this method previous.
          This is what I have now:

          def notch(x, y, z, radiuses, depths, directions)
          	model = Sketchup.active_model 
          	countOfNotch = x.length.to_i
          	countOfNotch.times do |i|
          		
          		center = [x[i], y[i], z[i]].map(&;to_f)		
          		radius = radiuses[i]
          		depth = depths[i]
          		direction = directions[i]
          		
          		case direction
          			when "N"
          				dir = Geom;;Vector3d.new(0,0,1)
          			when "E"
          				dir = Geom;;Vector3d.new(-1,0,0)
          			when "S"
          				dir = Geom;;Vector3d.new(0,0,-1)
          			when "W"
          				dir = Geom;;Vector3d.new(1,0,0)		
          			when "F"
          				dir = Geom;;Vector3d.new(0,-1,0)	
          			when "B"
          				dir = Geom;;Vector3d.new(0,1,0)				
          			else
          				dir = Geom;;Vector3d.new(0,0,1)		
          		end		
          		
          		gents = group.entities
          		active_faces = gents.grep(Sketchup;;Face);### modified
          		circle_group = gents.add_group; cge = circle_group.entities;### new
          		edges = cge.add_circle(center, dir, radius);### modified
          		circle_group.explode;### new
          		circle_face = (gents.grep(Sketchup;;Face) - active_faces)[0];### modified	
          		circle_face.pushpull(-depth)		
          	end
          end
          

          Of cource, I define a group in method, where I draw a rectangel block, but it's independently. So first I call this method, it'll draw several blocks, and then, if is necessary (according to input file) I'll call a method for notch.

          1 Reply Last reply Reply Quote 0
          • A Offline
            ado130
            last edited by

            Hmm, I have one main method, one method for rectangle blocks and next method for cylinders, but in every of those methods I have
            group = Sketchup.active_model.active_entities.add_group() entities = group.entities
            so then i.e.
            circle = entities.add_circle(center, dir, radius)
            or
            entities.add_line(ptA, ptB) etc bottom = entities.add_face(ptA, ptB, ptC, ptD)
            So this is the wrong solution?
            If I understand correctly, I need have group = Sketchup.active_model.active_entities.add_group() only in main method and then passed as a variable to other methods?

            1 Reply Last reply Reply Quote 0
            • sdmitchS Offline
              sdmitch
              last edited by

              @ado130 said:

              I had never defined the group in this method previous.

              That being the case, group must be created as a module variable(@group) or defined in the same way it is in the other methods or passed as a variable to other methods. The previous code would have created an empty group.

              Nothing is worthless, it can always be used as a bad example.

              http://sdmitch.blogspot.com/

              1 Reply Last reply Reply Quote 0
              • sdmitchS Offline
                sdmitch
                last edited by

                @ado130 said:

                Hmm, I have one main method, one method for rectangle blocks and next method for cylinders, but in every of those methods I have
                group = Sketchup.active_model.active_entities.add_group() entities = group.entities
                so then i.e.
                circle = entities.add_circle(center, dir, radius)
                or
                entities.add_line(ptA, ptB) etc bottom = entities.add_face(ptA, ptB, ptC, ptD)
                So this is the wrong solution?
                If I understand correctly, I need have group = Sketchup.active_model.active_entities.add_group() only in main method and then passed as a variable to other methods?

                You have a group containing a rectangular block that you you want to "drill" holes in. In order to do that, you have to add a group inside that group to contain the circle defining the drill hole. After exploding the group containing the circle, the original group will contain the block, the drill hole outline, and hopefully the face that is to be pushpulled to create the drill hole.

                Nothing is worthless, it can always be used as a bad example.

                http://sdmitch.blogspot.com/

                1 Reply Last reply Reply Quote 0
                • A Offline
                  ado130
                  last edited by

                  So there are 2 solutions for this (I think)

                  1. save somewhere the group where will be notch
                  2. find that group somehow
                    because, when I do a dril, I'm using this
                  		group = nil
                  		face = nil
                  		Sketchup.active_model.entities.each{|g|
                  			next unless g.is_a?(Sketchup;;Group)
                  			g.entities.each{|f|
                  				next unless f.is_a?(Sketchup;;Face)
                  				if f.classify_point(center) == Sketchup;;Face;;PointInside then
                  					group = g
                  					face = f
                  				end
                  			}	
                  		}
                  

                  2.) Exist a way how to find "my" group, where is the rectangular block, when the center point is outside that block?

                  1 Reply Last reply Reply Quote 0
                  • sdmitchS Offline
                    sdmitch
                    last edited by

                    @ado130 said:

                    So there are 2 solutions for this (I think)

                    1. save somewhere the group where will be notch
                    2. find that group somehow
                      because, when I do a dril, I'm using this
                    		group = nil
                    > 		face = nil
                    > 		Sketchup.active_model.entities.each{|g|
                    > 			next unless g.is_a?(Sketchup;;Group)
                    > 			g.entities.each{|f|
                    > 				next unless f.is_a?(Sketchup;;Face)
                    > 				if f.classify_point(center) == Sketchup;;Face;;PointInside then
                    > 					group = g
                    > 					face = f
                    > 				end
                    > 			}	
                    > 		}
                    

                    2.) Exist a way how to find "my" group, where is the rectangular block, when the center point is outside that block?

                    Perhaps

                    if center.on_plane f.plane then
                    	group = g
                    	face = f
                    end
                    
                    

                    Nothing is worthless, it can always be used as a bad example.

                    http://sdmitch.blogspot.com/

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      ado130
                      last edited by

                      It almost works, but the result is

                      http://i.imgur.com/RMnKEB6.png

                      def notch(x, y, z, radiuses, depths, directions)
                      	model = Sketchup.active_model 
                      	countOfNotch = x.length.to_i
                      	countOfNotch.times do |i|
                      		
                      		center = [x[i], y[i], z[i]].map(&;to_f)		
                      		radius = radiuses[i]
                      		depth = depths[i]
                      		direction = directions[i]
                      		
                      		case direction
                      			when "N"
                      				dir = Geom;;Vector3d.new(0,0,1)
                      			when "E"
                      				dir = Geom;;Vector3d.new(-1,0,0)
                      			when "S"
                      				dir = Geom;;Vector3d.new(0,0,-1)
                      			when "W"
                      				dir = Geom;;Vector3d.new(1,0,0)		
                      			when "F"
                      				dir = Geom;;Vector3d.new(0,-1,0)	
                      			when "B"
                      				dir = Geom;;Vector3d.new(0,1,0)				
                      			else
                      				dir = Geom;;Vector3d.new(0,0,1)		
                      		end		
                      		
                      		group = nil
                      		Sketchup.active_model.entities.each{|g|
                      			next unless g.is_a?(Sketchup;;Group)
                      			g.entities.each{|f|
                      				next unless f.is_a?(Sketchup;;Face)
                      				if center.on_plane? f.plane then
                      					group = g
                      				end
                      			}	
                      		}	
                      		gents = group.entities
                      		active_faces = gents.grep(Sketchup;;Face);
                      		circle_group = gents.add_group; cge = circle_group.entities;
                      		edges = cge.add_circle(center, dir, radius);
                      		circle_group.explode;
                      		circle_face = (gents.grep(Sketchup;;Face) - active_faces)[0];
                      		circle_face.pushpull(-depth)		
                      	end
                      end
                      

                      It works only if the cylinder's face is whole on the block.

                      It "works", if I have two blocks on each other

                      http://i.imgur.com/kAnKpQY.png

                      1 Reply Last reply Reply Quote 0
                      • sdmitchS Offline
                        sdmitch
                        last edited by

                        In the second image, are both blocks in the same group? If so two new faces will be created and only one is being pushpulled.

                        Nothing is worthless, it can always be used as a bad example.

                        http://sdmitch.blogspot.com/

                        1 Reply Last reply Reply Quote 0
                        • A Offline
                          ado130
                          last edited by

                          No, they aren't. I know it's a problem and if I will do drill into 2 blocks, they need to be in the same group. But for now, the problem is first image. It looks like, pushpull tools pushpull the block and not cylinder(drill/notch).

                          It works!! I had a little bug in my input file.
                          So final code is

                          		group = nil
                          		Sketchup.active_model.entities.each{|g|
                          			next unless g.is_a?(Sketchup;;Group)
                          			g.entities.each{|f|
                          				next unless f.is_a?(Sketchup;;Face)
                          				if center.on_plane? f.plane then
                          					group = g
                          				end
                          			}	
                          		}	
                          		gents = group.entities
                          		active_faces = gents.grep(Sketchup;;Face)
                          		circle_group = gents.add_group; cge = circle_group.entities
                          		edges = cge.add_circle(center, dir, radius)
                          		circle_group.explode
                          		circle_face = (gents.grep(Sketchup;;Face) - active_faces)[0]
                          		circle_face.pushpull(-depth)	
                          		togos = [] 
                          		edges.each{|edge| togos << edge unless edge.faces[0] }
                          		model.active_entities.erase_entities(togos) if togos[0]	
                          

                          Many many many thanks to both!
                          Maybe a question about the second image, is it possible do it somehow?
                          i.e.: Even if they are 4 blocks next to each (2x2 matrix) and create a hole in the middle.
                          It occurred to me, try to apply this method twice (or more, if there will be more blocks next to each other).
                          Or maybe 2nd solution, make a temporary group with all common groups/faces where will be a hole.

                          Edit:
                          So, I edited it

                          		groups = []
                          		i = 0
                          		Sketchup.active_model.entities.each{|g|
                          			next unless g.is_a?(Sketchup;;Group)
                          			g.entities.each{|f|
                          				next unless f.is_a?(Sketchup;;Face)
                          				if center.on_plane? f.plane then
                          					groups.each {|x| next if g == x}
                          					groups[i] = g
                          					i += 1
                          				end
                          			}	
                          		}	
                          		
                          		groups = groups.uniq
                          				
                          		countOfGroups = groups.length.to_i
                          		countOfGroups.times do |i|
                          			group = groups[i]
                          			gents = group.entities
                          			active_faces = gents.grep(Sketchup;;Face)
                          			circle_group = gents.add_group; cge = circle_group.entities
                          			edges = cge.add_circle(center, dir, radius)
                          			circle_group.explode
                          			circle_face = (gents.grep(Sketchup;;Face) - active_faces)[0]
                          			next if circle_face == nil
                          			circle_face.pushpull(-depth)	
                          			togos = [] 
                          			edges.each{|edge| togos << edge unless edge.faces[0] }
                          			model.active_entities.erase_entities(togos) if togos[0]		
                          		end
                          

                          http://i.imgur.com/GDdGN4p.png

                          It "works", but there is a problem, if I need do a drill over 3 (more) blocks.
                          Or when I have 4 blocks, etc..

                          http://i.imgur.com/o0xkiYw.png

                          I found that after this circle_face = (gents.grep(Sketchup::Face) - active_faces), there are two faces, so I tried ".last", it helped, but still don't work at well.

                          http://i.imgur.com/J8tQrBb.jpg

                          Aby ideas?

                          1 Reply Last reply Reply Quote 0
                          • A Offline
                            ado130
                            last edited by

                            It seems that it works. Is it correct way?
                            Just one question, how can I delete the black lines?, or hide them.

                            def drill(x, y, z, radiuses, depths, directions)
                            	model = Sketchup.active_model 
                            	countOfDrills = x.length.to_i
                            	countOfDrills.times do |i|
                            		
                            		center = [x[i], y[i], z[i]].map(&;to_f)		
                            		radius = radiuses[i]
                            		depth = depths[i]
                            		direction = directions[i]
                            		
                            		case direction
                            			when "N"
                            				dir = Geom;;Vector3d.new(0,0,1)
                            			when "E"
                            				dir = Geom;;Vector3d.new(-1,0,0)
                            			when "S"
                            				dir = Geom;;Vector3d.new(0,0,-1)
                            			when "W"
                            				dir = Geom;;Vector3d.new(1,0,0)		
                            			when "F"
                            				dir = Geom;;Vector3d.new(0,-1,0)	
                            			when "B"
                            				dir = Geom;;Vector3d.new(0,1,0)				
                            			else
                            				dir = Geom;;Vector3d.new(0,0,1)		
                            		end		
                            		
                            		groups = []
                            		i = 0
                            		Sketchup.active_model.entities.each{|g|
                            			next unless g.is_a?(Sketchup;;Group)
                            			g.entities.each{|f|
                            				next unless f.is_a?(Sketchup;;Face)
                            				if center.on_plane? f.plane then
                            					groups.each {|x| next if g == x}
                            					groups[i] = g
                            					i += 1
                            				end
                            			}	
                            		}	
                            		
                            		groups = groups.uniq
                            		
                            		countOfGroups = groups.length.to_i
                            		countOfGroups.times do |i|
                            			group = groups[i]
                            			gents = group.entities
                            			activeFaces = gents.grep(Sketchup;;Face)
                            			circleGroup = gents.add_group; cge = circleGroup.entities
                            			edges = cge.add_circle(center, dir, radius)
                            			circleGroup.explode
                            			circleFace = (gents.grep(Sketchup;;Face) - activeFaces).last
                            			next if circleFace == nil
                            			normal = circleFace.normal
                            			activeFaces = gents.grep(Sketchup;;Face)
                            			circleFace.pushpull(-depth)
                            			deleteFace = (gents.grep(Sketchup;;Face) - activeFaces)[0]
                            			if deleteFace.normal == normal then
                            				deleteFace.erase!	
                            			end
                            		end
                            	end
                            end
                            
                            1 Reply Last reply Reply Quote 0
                            • sdmitchS Offline
                              sdmitch
                              last edited by

                              @ado130 said:

                              Just one question, how can I delete the black lines?, or hide them.

                              Try this

                              groups = groups.uniq
                              countOfGroups = groups.length.to_i
                              countOfGroups.times do |i|
                               group = groups[i]
                               gents = group.entities
                               activeFaces = gents.grep(Sketchup;;Face)
                               circleGroup = gents.add_group; cge = circleGroup.entities
                               edges = cge.add_circle(center, dir, radius)
                               circleGroup.explode;
                               (gents.grep(Sketchup;;Face) - activeFaces).each{|circleFace|
                                next if center.distance(circleFace.bounds.center) > radius
                                circleFace.pushpull(-depth)
                               ]
                               remove = gents.grep(Sketchup;;Edge).find_all{|e|e.faces.length<2}
                               gents.erase_entities(remove.reverse)
                              end
                              
                              

                              cut from object.gif

                              Nothing is worthless, it can always be used as a bad example.

                              http://sdmitch.blogspot.com/

                              1 Reply Last reply Reply Quote 0
                              • A Offline
                                ado130
                                last edited by

                                It seems that it works too. Thanks!
                                But black lines are still there.
                                You have there "]", I think, it should be "}"?

                                1 Reply Last reply Reply Quote 0
                                • sdmitchS Offline
                                  sdmitch
                                  last edited by

                                  @ado130 said:

                                  It seems that it works too. Thanks!
                                  But black lines are still there.
                                  You have there "]", I think, it should be "}"?

                                  Yes, you are right. Sorry about that.

                                  The black vertical lines in the 'drill hole'?

                                  Nothing is worthless, it can always be used as a bad example.

                                  http://sdmitch.blogspot.com/

                                  1 Reply Last reply Reply Quote 0
                                  • A Offline
                                    ado130
                                    last edited by

                                    Yeah, you're right, but I meant black lines in rectangular blocks (rather, all lines).

                                    1 Reply Last reply Reply Quote 0
                                    • sdmitchS Offline
                                      sdmitch
                                      last edited by

                                      @ado130 said:

                                      Yeah, you're right, but I meant black lines in rectangular blocks.

                                      Well, if you didn't want them, why did you create then in the first place.

                                      groups = groups.uniq
                                      countOfGroups = groups.length.to_i
                                      countOfGroups.times do |i|
                                      	group = groups[i]; group.make_unique
                                      	gents = group.entities
                                      	activeFaces = gents.grep(Sketchup;;Face)
                                      	activeEdges = gents.grep(Sketchup;;Edge);#<-- save active edges
                                      	circleGroup = gents.add_group; cge = circleGroup.entities
                                      	edges = cge.add_circle(center, dir, radius)
                                      	circleGroup.explode;
                                      	(gents.grep(Sketchup;;Face) - activeFaces).each{|circleFace|
                                      		next if center.distance(circleFace.bounds.center) > radius
                                      		circleFace.pushpull(-depth)
                                      	}
                                         #remove unused circle edges
                                      	remove = gents.grep(Sketchup;;Edge).find_all{|e|e.faces.length<2}
                                      	gents.erase_entities(remove.reverse)
                                      	# hide vertical edges in drill hole
                                      	soften = (gents.grep(Sketchup;;Edge)-activeEdges).find_all{|e|e.line[1].parallel?(dir) && !e.soft?}
                                      	soften.each{|e|e.soft=e.smooth=true}
                                      	# remove co-planar edges
                                      	remove = gents.grep(Sketchup;;Edge).find_all{|e|(e.faces.length>=2 && e.faces.find_all{|f|f.normal.parallel?(e.line[1].axes[1])}.length==2)}
                                      	gents.erase_entities(remove.reverse)
                                      
                                      

                                      Nothing is worthless, it can always be used as a bad example.

                                      http://sdmitch.blogspot.com/

                                      1 Reply Last reply Reply Quote 0
                                      • A Offline
                                        ado130
                                        last edited by

                                        Sorry for the delayed response. It looks fine, thanks again!

                                        http://i.imgur.com/TtoBovE.png

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

                                        Advertisement