Intersecting 2 Groups Question
-
Hi, need some help figuring something out. I would like to intersect a set of lines with a face. The face is grouped. I can do it with the lines as loose geometry, as you see it set up in the picture.
int = ent.intersect_with(true, tr, ent, tr, false, face)
But if I move the face up to the grouped lines, I can't get it to work with this new line. I am changing it to use the line group entities, instead of the model's entities:
int = lent.intersect_with(true, ltr, ent, tr, false, face)
Any idea how to get this to work?ent = Sketchup.active_model.entities face = (ent.to_a.select {|e| e.is_a? Sketchup;;Group and e.name=="face"})[0] lines = (ent.to_a.select {|e| e.is_a? Sketchup;;Group and e.name=="lines"})[0] puts face; puts lines lent = lines.entities tr = Geom;;Transformation.new ltr = lines.transformation int = ent.intersect_with(true, tr, ent, tr, false, face)
-
Try
ent.intersect_with(true, tr, ent, tr, false, [face,lines])
You do realize that the resulting geometry goes directly into the model's active_entities?
Why no put that into a group - at least initially?
Note, since it always returns 'nil' there's no point in assigning a reference to this operation with int=... -
@tig said:
Try
ent.intersect_with(true, tr, ent, tr, false, [face,lines])
You do realize that the resulting geometry goes directly into the model's active_entities?
Why no put that into a group - at least initially?
Note, since it always returns 'nil' there's no point in assigning a reference to this operation with int=...Thanks, TIG. I haven't thought of it that way before, when trying to intersect two groups. That way worked. I used "intersect_with" with several past plugins, but still trying to understand it fully. Just doing some basic testing of general cases. So it doesn't matter, if the geomtry is simply going into the models's active_entities.
It doesn't always return 'nil'. Your way returns the new edges. That paticular case I was asking about returns 'nil'. And didn't work, in certian situations, like I expected. But using face.entities as reciever also returns the new edges, and works exactly the way I expect. The only difference I can see is possibly face.entities has a face in there, whereas lines.entities doesn't? Using lines.entities as reciever seems to returns 'nil'.
-Kwok
-
http://code.google.com/apis/sketchup/docs/ourdoc/entities.html#intersect_with says 'intersect_with' returns 'nil' always...
-
@tig said:
http://code.google.com/apis/sketchup/docs/ourdoc/entities.html#intersect_with says 'intersect_with' returns 'nil' always...
And we all know the are no mistakes in the API docs. But seriously, I know in practice that it's not true. I have a plugin that slices up a solid and add the edges returned each time, into an array. Looks something like this:
while @x < @total int = intersect_with_plane(plane) int.each do |i| @@cary << i end @x += @inc move_plane(plane, @inc) end def intersect_with_plane(plane) t = Geom;;Transformation.new int = @@plane_ent.intersect_with(true, plane.transformation, @@ent, t, false, @@g) end
-
So you are saying that
entities.intersect_with()
return the geometry that's added ?
I have tested this and I can confirm that you are correct -geo=entities.intersect_with(.....)
will return an array 'geo' of any newly made geometry - in direct contravention of what the API notes say !
Have you posted a comment in the API section ? -
@tig said:
So you are saying that
entities.intersect_with()
return the geometry that's added ?
I have tested this and I can confirm that you are correct -geo=entities.intersect_with(.....)
will return an array 'geo' of any newly made geometry - in direct contravention of what the API notes say !
Have you posted a comment in the API section ?No I haven't posted a comment. I am a beginner, found the docs very confusing at the beginning and don't take them literally. In the past, I've had to test stuff to see what they actually do. Plus I sometimes figure(or partly figure) out something, then forget it and later have to relearn it. On top of that, I don't have a google account. I may be force to get one someday, but I don't like them trying to link to my youtube account. And some lame stuff they did, when I had google video. If I went and posted "It doesn't always return 'nil'", don't think that would be very useful.
But I can show proof, with an example. You can use that test file I posted above and move the face group up onto the lines group. Then run this script. In the picture, I've selected the 37 edges that were created. You can see in the ruby console, an array was returned with 37 edges.
model = Sketchup.active_model ent = model.entities sel = model.selection face = (ent.to_a.select {|e| e.is_a? Sketchup;;Group and e.name=="face"})[0] lines = (ent.to_a.select {|e| e.is_a? Sketchup;;Group and e.name=="lines"})[0] puts face; puts lines lent = lines.entities fent = face.entities tr = Geom;;Transformation.new ltr = lines.transformation ftr = face.transformation int = fent.intersect_with(true, ftr, ent, tr, false, lines) puts int puts int.class puts int.length
-
I posted an anonymous comment in the API.
Put simply, theentities.intersect_with()
method returns an array of the newly created geometry [faces/edges] or 'nil' if there is none, the guide is wrong as it says it returns 'nil' [always]. -
Thanks, TIG. Lots of times, a beginner is not cofident enough to jump in there and make too many comments, even on this forum. Did you still need a google account, to post that anonymous comment in the API?
-
I do have a Google account... but Google Apps has recently messed around with lots of accounts and settings... so I ended up being 'anonymous' anyway
-
Very interesting experiment and find. I wonder how missleading sometimes the API really is?
And what reference should beginners use if not the API? -
Use the API site but read the notes at the ends, as there are many corrections by users...
If in doubt ask in the Developers' forum - especially if you think you have found something odd.
Test your new tools methods in small steps so you can see what is returned or what is made at each step... -
OK. thanks. I have missed the notes part.
Advertisement