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!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    REQ: Checking if components (solids) intersect

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

      @pgarmyn said:

      @giro

      		model=Sketchup.active_model
      > 		ss=model.selection
      > 		ents=model.active_entities
      > 		ss.clear
      > 		gps=ents.grep(Sketchup;;Group)
      > 		ins=ents.grep(Sketchup;;ComponentInstance)
      > 		ens=gps+ins
      > 		ens.uniq!
      > 		ens.compact!
      > 		for i in (0..ens.length-2)  ############changed from length-1 to length-2
      > 			for j in ((i+1)..ens.length-1)
      > 				if TIG.intersect?(ens[i], ens[j])
      > 					ss.add(ens[i])
      > 					ss.add(ens[j])
      > 				end
      > 			end
      > 		end
      >         puts "Any intersecting groups/component-instances are highlighted..."
      

      I think, in this case, the last TIG.intersect?(ens[i], ens[j]) is with i=length-2 and j=length-1
      Otherwise j = i+1 will become ens.length : for 5 elements (0 to 4) in ens, j will be 5.

      i tried to run this code in sketchup 15 64 bits, thinking it could run faster than is sketchup 8

      All the contrary

      it is much slower in sketchup 15 64 bits... (about 10 times...)

      i am very disapointed

      am i the only one to experience that?

      1 條回覆 最後回覆 回覆 引用 0
      • B 離線
        Bobvandevoort
        最後由 編輯

        This is my version of the srcipt for now that seems to work for all non nested component instances

        module Bob
        
        # Huge parts of this code were written by TIG this is a sligthly modified version
        
        	def self.intersectBob?(e1=nil, e2=nil)
        	
        		mod = Sketchup.active_model # Open model
        		ent = mod.entities # All entities in model
        		instance1 = e1 #sel[0]
        		instance2 = e2 #sel[1]
        		ci_def = instance1.definition 
        		tr1 = instance1.transformation
        		test1 = Sketchup.active_model.entities.add_instance ci_def, tr1
        		ci_def2 = instance2.definition 
        		tr2 = instance2.transformation
        		test2 = Sketchup.active_model.entities.add_instance ci_def2, tr2
        		result = test1.intersect(test2) 
        		cnt = result.entities.count 
        		if  cnt > 0
        			int=true
        			result.definition.entities.each {|ent|
        			if ent.is_a? Sketchup;;Face
        				ent.material = 'red' #Sketchup;;Color.new(255, 0, 0)
        			end}
        		else
        		int=false
        		end
        		
        	return int
        	end 
        	
        	#def self.del()	#does not work like this typing Bob.del into the ruby console, meaning result has to be changed from local to global variable but I don't know how yet
        	#result.erase!	
        	#end	
        
        	def self.intersectALL()
        		model=Sketchup.active_model
        		ss=model.selection
        		ents=model.active_entities
        		ss.clear
        		gps=ents.grep(Sketchup;;Group)
        		ins=ents.grep(Sketchup;;ComponentInstance)
        		ens=gps+ins
        		ens.uniq!
        		ens.compact!
        		(ens.length).times{|i|
        			(ens.length).times{|j|
        				next if j<=i
        				if self.intersectBob?(ens[i], ens[j])
        					ss.add(ens[i])
        					ss.add(ens[j])
        				end
        			}
        		}
        		puts "Any intersecting component-instances are highlighted..."
        	end
        end
        
        

        In this script I still need to fix the deleting function which later will have to be added to an observer class so as soon as another is clicked (or a button is pressed) the resulting intersection is deleted.

        The more important function that still has to be added is that it does the check for all the nested components (and possibly groups).

        @giro
        I only have the 32 bits version so can't say

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

        Advertisement