Intersect two Component Instances
-
Hi Forum,
I'm going crazy trying to intersect two component instances.I want to intersect a instance of the component Model and a instance of the component Plane and store the intersecting edges in intersection_edges in the Plane Component. I fail miserably probably because I don't really understand how the transformations work on instances. Any Help would be really great, I already spend more than 2 hours trying to get this to work.
entities.each do |s| if s.definition.name=="Model" $model_tr = s.transformation $entities_model=s.definition.entities end if s.definition.name=="Plane" $plane_tr = s.transformation $entities_plane=s.definition.entities end end intersection_edges = $entities_plane.intersect_with(false,$model_tr.inverse ,$entities_plane,$plane_tr,false,$entities_model.collect)
Thank you very much!
-
First off please don't use $ variables - one day they'll clash with other's code and cause disasters... use @ ones if your code spans 'def' methods...
Also calling your component/instance 'model' is just confusing as that's normally used for 'the model' itself ! And 'plane' refers to something that a face has...
Make references to the two 'containers' instead of their entities !
Say @xmodel and @xplane - we can deal with the entities later...Then try...
intersection_edges = Sketchup.active_model.active_entities.intersect_with(true, @xplane.transformation.inverse , @xplane.definition.entities, @xplane.transformation.inverse , true, [@xmodel, @xplane])
Note that 'intersection_edge's might also include new faces etc...
This is untested- the principle is that you intersect the objects where they are and put the results into the desired container...
Try messing around with the .inverse methods if the intersection id not where it's required... -
@tig said:
First off please don't use $ variables - one day they'll clash with other's code and cause disasters... use @ ones if your code spans 'def' methods...
Also calling your component/instance 'model' is just confusing as that's normally used for 'the model' itself ! And 'plane' refers to something that a face has...
Make references to the two 'containers' instead of their entities !
Say @xmodel and @xplane - we can deal with the entities later...
Try messing around with the .inverse methods if the intersection id not where it's required...Thanks for the quick reply.
I replaces the global variables and renamed the instances.model = Sketchup.active_model entities = model.entities instance_body=0 instance_bulkhead=0 entities.each do |s| if s.definition.name=="Model" instance_body=s; end if s.definition.name=="BPC" instance_bulkhead=s end end intersection_edges = Sketchup.active_model.active_entities.intersect_with(true, instance_bulkhead.transformation.inverse , instance_bulkhead.definition.entities, instance_bulkhead.transformation.inverse , true, [instance_body, instance_bulkhead])
I tried every possible combination of inverse and non-inverse but there's always strange stuff happening. It does only work if both instances are not transformed at all so I guess it must have something to do with the transforms.
Thank you very much
The lines are the intersection_edges
-
It's quite possible to get this to work... unfortunately I don't have a spare moment to look at it right now in any detail... have you tried permutations of all .transformation/.transformation.inverse to see what happens... This MIGHT work - assuming there are only 2 active entities !! Perhaps dump the 'inverse' = untested...
model = Sketchup.active_model entities = model.active_entities instance_body=nil instance_bulkhead=nil entities.each do |s| if s.definition.name=="Model" instance_body=s elsif s.definition.name=="BPC" instance_bulkhead=s end end return unless instance_body && instance_bulkhead tr=Geom;;Transformation.new() intersection_edges = entities.intersect_with(true, tr, instance_bulkhead.definition.entities, instance_bulkhead.transformation.inverse , true, [instance_body, instance_bulkhead])
???
-
Thank you! This works indeed. I just had to remove the one ".inverse".
intersection_edges = entities.intersect_with(true, tr, instance_bulkhead.definition.entities, instance_bulkhead.transformation, true, [instance_body, instance_bulkhead])
The one remaining problem is now that there are usually more than two entities and this intersects all of them with the instance_body including the instance_body itself. Do you have a quick tip how to restrict the intersect to the two objects instance_body and instance_bulkhead?
Thank you very much for your help, it's much appreciated
-
Here is another shot at it for you to try
model = Sketchup.active_model entities = model.entities model_component=nil;plane_component=nil cmps=entities.find_all{|c| c.class==Sketchup;;ComponentInstance} cmps.each{|c| (model_component=c;break) if c.name=="Model"} cmps.each{|c| (plane_component=c;break) if c.name=="Plane"} if model_component and plane_component intersection_edges=plane_component.definition.entities.add_group;intersection_edges.name="Intersection_Edges" plane_component.definition.entities.intersect_with(true,plane_component.transformation,intersection_edges.entities,intersection_edges.transformation,true,model_component) intersection_edges.transform! plane_component.transformation.inverse else UI.messagebox "Both components not found" end
-
Thank you. That solved the last Problem with the intersect.
you guys have been very helpful@TIG,sdmitch Thanks a thousand
Advertisement