Sorry for the delayed response. It looks fine, thanks again!
Posts
-
RE: How to cut from object
-
RE: How to cut from object
Yeah, you're right, but I meant black lines in rectangular blocks (rather, all lines).
-
RE: How to cut from object
It seems that it works too. Thanks!
But black lines are still there.
You have there "]", I think, it should be "}"? -
RE: How to cut from object
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
-
RE: How to cut from object
No, they aren't. I know it's a problem and if I will do drill into 2 blocks, they need to be in the same group. But for now, the problem is first image. It looks like, pushpull tools pushpull the block and not cylinder(drill/notch).
It works!! I had a little bug in my input file.
So final code isgroup = nil 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 group = g end } } gents = group.entities active_faces = gents.grep(Sketchup;;Face) circle_group = gents.add_group; cge = circle_group.entities edges = cge.add_circle(center, dir, radius) circle_group.explode circle_face = (gents.grep(Sketchup;;Face) - active_faces)[0] circle_face.pushpull(-depth) togos = [] edges.each{|edge| togos << edge unless edge.faces[0] } model.active_entities.erase_entities(togos) if togos[0]
Many many many thanks to both!
Maybe a question about the second image, is it possible do it somehow?
i.e.: Even if they are 4 blocks next to each (2x2 matrix) and create a hole in the middle.
It occurred to me, try to apply this method twice (or more, if there will be more blocks next to each other).
Or maybe 2nd solution, make a temporary group with all common groups/faces where will be a hole.Edit:
So, I edited itgroups = [] 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 active_faces = gents.grep(Sketchup;;Face) circle_group = gents.add_group; cge = circle_group.entities edges = cge.add_circle(center, dir, radius) circle_group.explode circle_face = (gents.grep(Sketchup;;Face) - active_faces)[0] next if circle_face == nil circle_face.pushpull(-depth) togos = [] edges.each{|edge| togos << edge unless edge.faces[0] } model.active_entities.erase_entities(togos) if togos[0] end
It "works", but there is a problem, if I need do a drill over 3 (more) blocks.
Or when I have 4 blocks, etc..I found that after this
circle_face = (gents.grep(Sketchup::Face) - active_faces)
, there are two faces, so I tried ".last", it helped, but still don't work at well.Aby ideas?
-
RE: How to cut from object
It almost works, but the result is
def notch(x, y, z, radiuses, depths, directions) model = Sketchup.active_model countOfNotch = x.length.to_i countOfNotch.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 group = nil 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 group = g end } } gents = group.entities active_faces = gents.grep(Sketchup;;Face); circle_group = gents.add_group; cge = circle_group.entities; edges = cge.add_circle(center, dir, radius); circle_group.explode; circle_face = (gents.grep(Sketchup;;Face) - active_faces)[0]; circle_face.pushpull(-depth) end end
It works only if the cylinder's face is whole on the block.
It "works", if I have two blocks on each other
-
RE: How to cut from object
So there are 2 solutions for this (I think)
- save somewhere the group where will be notch
- find that group somehow
because, when I do a dril, I'm using this
group = nil face = nil 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 f.classify_point(center) == Sketchup;;Face;;PointInside then group = g face = f end } }
2.) Exist a way how to find "my" group, where is the rectangular block, when the center point is outside that block?
-
RE: How to cut from object
Hmm, I have one main method, one method for rectangle blocks and next method for cylinders, but in every of those methods I have
group = Sketchup.active_model.active_entities.add_group() entities = group.entities
so then i.e.
circle = entities.add_circle(center, dir, radius)
or
entities.add_line(ptA, ptB) etc bottom = entities.add_face(ptA, ptB, ptC, ptD)
So this is the wrong solution?
If I understand correctly, I need havegroup = Sketchup.active_model.active_entities.add_group()
only in main method and then passed as a variable to other methods? -
RE: How to cut from object
I had never defined the group in this method previous.
This is what I have now:def notch(x, y, z, radiuses, depths, directions) model = Sketchup.active_model countOfNotch = x.length.to_i countOfNotch.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 gents = group.entities active_faces = gents.grep(Sketchup;;Face);### modified circle_group = gents.add_group; cge = circle_group.entities;### new edges = cge.add_circle(center, dir, radius);### modified circle_group.explode;### new circle_face = (gents.grep(Sketchup;;Face) - active_faces)[0];### modified circle_face.pushpull(-depth) end end
Of cource, I define a group in method, where I draw a rectangel block, but it's independently. So first I call this method, it'll draw several blocks, and then, if is necessary (according to input file) I'll call a method for notch.
-
RE: How to cut from object
I am slightly confused now
because before you said
@unknownuser said:
You don't need to add the edges to a new group.
raw it directly over the face in the active_entities.
edges = Sketchup.active_model.active_entities.add_circle(center, dir, radius, segs)So what should I do?
If I understood Sam correctly, I need sth like
group = Sketchup.active_model.active_entities.add_group() gents = group.entities active_faces = model.active_entities.grep(Sketchup::Face) edges = gents.add_circle(center, dir, radius) group.explode circle_face = model.active_entities.grep(Sketchup::Face) - active_faces
.. and then?
I'm not sure what is meant by "add a group inside the original group".By the way, thanks Sam, or, thanks to both.
-
RE: How to cut from object
237:
new_edges[0].faces.each{|f|fac = f unless f.loops[1]}
-
RE: How to cut from object
Thanks for comprehensive answer, I'll try it.
In first point you describe, when the rectangular exist, is it good way?, or is better to do fillet while drawing?About notches
active_edges = model.active_entities.grep(Sketchup;;Edge) edges = Sketchup.active_model.active_entities.add_circle(center, dir, radius) new_edges = model.active_entities.grep(Sketchup;;Edge) - active_edges togos = [] ### empty array new_edges.each{|edge| togos << edge unless edge.faces[0] } model.active_entities.erase_entities(togos) if togos[0] fac = nil new_edges[0].faces.each{|f|fac = f unless f.loops[1]} fac.pushpull(-depth)
It's not a whole code, but the rest is the same (see above).
But still is there a problem. -
RE: How to cut from object
Now I've it in Plugins->Extensions, so then I only "delete" this manually run script and it should work automatically.
I suppose that this API can be used as a script.
I only need save itanother work will do a C# program, then it's easy.
About notches, can you help with that? I'm a bit lost how to proceed now.
Two more questions:
- is possible do a fillet (radius) on rectangel blocks?
- Exist a way, how to secure script, I think sth like non-readable, *.rb is possible open in whatever and *.rbz is just a "zip", so..
-
RE: How to cut from object
Yes, radius, depth and direction are arrays with the float numbers.
In another part of code I only read txt file line by line and split it into this arrays.I've two arrays, in first array are "drills" (coordinates, depth, etc), that are whole on the face, and second array, where I don't know if the imaginary center of notch is on the face or not.
So, function for drill works fine, but still I've problem with notches.The whole code has 460 lines, so .. if you want, I can send it via PM.
Thanks for the advice of the name.
In future
if it will work, I wanna buy Pro version and do sth like client-server. This script will run on the server, and i.e. you like a client send points (These can be generated from the C# program) and send to server. He process them, sent back Sketchup model to the client and client can open it with Sketchup View.
So I've one more question. Is this possible?, I think the part where Pro version can automaticaly open ruby script and save the model. -
RE: How to cut from object
I know, that the circle's radius is not an array, but that's not a whole code.
def notch(x, y, z, radius, depth, direction) countOfNotch = x.length.to_i countOfNotch.times do |i| model = Sketchup.active_model center = [x[i], y[i], z[i]].map(&;to_f) case direction[i] 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 active_edges = model.active_entities.grep(Sketchup;;Edge) edges = Sketchup.active_model.active_entities.add_circle(center, dir, radius[i]) new_edges = model.active_entities.grep(Sketchup;;Edge) - active_edges togos = [] ### empty array new_edges.each{|edge| togos << edge unless edge.faces[0] } model.active_entities.erase_entities(togos) if togos[0] fac = nil new_edges.faces.each{|f|fac = f unless f.loops[1]} fac.pushpull(-depth) end end
Is it necessary set the seg?, I think there is a default value.
So I add circle into active_entities.For point a) I've a separate code (the above code) - make drill; I use it, when I know, that the drill (circle) intersects fully with the face (i.e. block).
-
RE: How to cut from object
Yeah, you're right, I don't get it completely.
-
save now active edges
active_edges = model.active_entities.grep(Sketchup::Edge)
-
make a new group and add there circle
group = Sketchup.active_model.active_entities.add_group() gents = group.entities edges = gents.add_circle(center, dir, radius[i])
-
select edges, which makes this circle
new_edges = model.active_entities.grep(Sketchup::Edge) - active_edges
-
erase the unwanted edges
togos = [] ### empty array new_edges.each{|edge| togos << edge unless edge.faces[0] } model.active_entities.erase_entities(togos) if togos[0]
-
now last step, that you said; find the face associated with any new edges which I just added and which have a face
fac = nil new_edges.faces.each{|f|fac = f unless f.loops[1]} fac.pushpull(-10)
Is it correct now? I'd like to learn it (understand it), not only copy and paste the code.
-
-
RE: How to cut from object
So, is this correct? Now just pushpull the new face (which?) and it should be done.
active_edges = model.active_entities.grep(Sketchup;;Edge) group = Sketchup.active_model.active_entities.add_group() gents = group.entities edges = gents.add_circle(center, dir, radius[i]) first = edges[0].faces[0] puts first new_edges = model.active_entities.grep(Sketchup;;Edge) - active_edges togos = [] ### empty array new_edges.each{|edge| togos << edge unless edge.faces[0] } model.active_entities.erase_entities(togos) if togos[0]
-
RE: How to cut from object
active_edges = model.active_entities.grep(Sketchup;;Edge) group = Sketchup.active_model.active_entities.add_group() gents = group.entities edges = gents.add_circle(center, dir, notchRadius[0]) first = edges[0].faces[0] new_edges = model.active_entities.grep(Sketchup;;Edge) - active_edges
Now, should I delete those in new_edges which have no faces, but I'm not sure, how to find them. And you said, thath I need to check its edges for their faces , what do you mean there?
Thanks
-
RE: How to cut from object
I rewrote your code to do a drill and it looks fine (works
)
def drill(x, y, z, radius, depth, direction) countOfDrills = x.length.to_i countOfDrills.times do |i| model = Sketchup.active_model entities = model.entities case direction[i] 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 center = [x[i], y[i], z[i]].map(&;to_f) group = nil face = nil 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 f.classify_point(center) == Sketchup;;Face;;PointInside then group = g face = f end } } gents = group.entities edges = gents.add_circle(center, dir, radius[i]) ### note axis fac = nil edges[0].faces.each{|f|fac = f unless f.loops[1]} normal = face.normal other_entities = face.all_connected reversed_normal = normal.reverse circleface = nil for other in other_entities if other.typename == "Face" and other.classify_point(center) == Sketchup;;Face;;PointInside then circleface = other end end for other in other_entities if other.valid? and other.typename=="Face" then if reversed_normal.samedirection? other.normal then point_on_other_face = center.project_to_plane other.plane if other.classify_point(point_on_other_face) == Sketchup;;Face;;PointInside then dist = point_on_other_face.vector_to(center).length end end end end if depth[i] != 0 then dist = depth[i] end fac.pushpull(-dist) end return end
But still, I'm not sure how to do a notch.
I can't add a inputbox for user, because all of my input data are from txt file - there I have x y z positions of imaginary center then radius, depth and if I need to know direction also. -
RE: How to cut from object
Thanks for a reply.
Yes, I have all rectangular blocks grouped, radius and depth are fixed (from a txt file).
I'm not sure, but that code do a drill in center of some rectangular block, but what I need to do is make a notch (like in pic in my prev post) - the center position of this imaginary cylinder may not be on that block.
Do you know what I mean?