sketchucation logo sketchucation
    • 登入
    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!
    🔌 Smart Spline | Fluid way to handle splines for furniture design and complex structures. Download

    How to cut from object

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    47 貼文 4 Posters 4.9k 瀏覽 4 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • A 離線
      ado130
      最後由 編輯

      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 條回覆 最後回覆 回覆 引用 0
      • sdmitchS 離線
        sdmitch
        最後由 編輯

        @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 條回覆 最後回覆 回覆 引用 0
        • A 離線
          ado130
          最後由 編輯

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

          1 條回覆 最後回覆 回覆 引用 0
          • sdmitchS 離線
            sdmitch
            最後由 編輯

            @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 條回覆 最後回覆 回覆 引用 0
            • A 離線
              ado130
              最後由 編輯

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

              1 條回覆 最後回覆 回覆 引用 0
              • sdmitchS 離線
                sdmitch
                最後由 編輯

                @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 條回覆 最後回覆 回覆 引用 0
                • A 離線
                  ado130
                  最後由 編輯

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

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

                  1 條回覆 最後回覆 回覆 引用 0
                  • 1
                  • 2
                  • 3
                  • 3 / 3
                  • 第一個貼文
                    最後的貼文
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement