@tig said:
Assuming they do/could overlap, then you need to check for geometry intersections.
Try this - you pass two arguments - references to a group or component-instance - returns 'true
' if they do intersect|touch, or 'false
' if there is no intersection [or 'nil' if incorrect arguments]: e.g.TIG.intersect?(e1, e2)
module TIG
> def self.intersect?(e1=nil, e2=nil)
> if e1.is_a?(Sketchup;;Group) || e1.is_a?(Sketchup;;ComponentInstance)
> if e1.is_a?(Sketchup;;Group)
> es1 = e1.entities
> else
> es1 = e1.definition.entities
> end
> fail = false
> else
> fail = true
> end
> if e2.is_a?(Sketchup;;Group) || e2.is_a?(Sketchup;;ComponentInstance)
> fail = false
> else
> fail = true
> end
> if fail
> puts("#{self}.intersect? requires references to two groups/component-instances.\nReturns 'true' [intersecting || touching] or 'false'.")
> return nil
> end
> ens = e1.parent.entities
> tr1 = e1.transformation
> grp = ens.add_group()
> grp.transform!(tr1) ### so can see cut lines IF erase! is disabled at the end !
> ges = grp.entities
> es1.intersect_with(true, tr1, ges, tr1, true, e2)
> if ges[0]
> int = true
> else
> int = false
> end
> grp.erase!
> return int
> end
> end
Note that they do not need to be 'solids', but a check for that could be added...
That seems really nice and cool but I've never worked with ruby nor the ruby interface in sketchup.
I do have some basic coding skills in C (and some other languages).
Does it matter that instead of having groups that I have components (as far as I understood it doesn't).
SUSolids sees all my components as solids at the moment so if that is what you mean by solid than yes all my components are solids.
Furthermore I understand the code more or less up till the checking if there're actually 2 components selected. After that it's a bit unclear how it checks for the intersection (it seems like you're using the intersection tool but the arguments are unclear).
Further it should be possible to just use a for loop to check the whole model for intersections right?
One other thing would it be possible to check for only touching between just 2 components (multiple would be better) in a certain plain (of 1 of the components).
So let me explain that a bit more correctly by first telling what I want to use the check for. I want to make a move command/script/tool that moves 1 a component along an axis (both direction being possible) until it collides with another surface/component. This means that if a component is moved along the x-axis it should only look if it's touching any other components in the x-direction (or an yz-plane). Meaning if I have a rod in a cylinder with their longitudinal axis in the x-axis and I let the rod be moved/translated along the x-axis than even if their walls are touching in the y or z direction it should stop the translation. The translation should be stopped as soon as an intersection or a touch at base of the rod touches and yz-plane is detected.