by niccah » Wed Dec 19, 2012 8:09 pm
You helped me a lot! Thanks!!!! Now, my current (but not yet perfectly working result): - Code: Select all
group = projectGroup.entities.add_group
model.selection.each do |tmp| if tmp.is_a?(Sketchup::ComponentInstance) || tmp.is_a?(Sketchup::Group) getEntities(tmp, nil, group) elsif tmp.is_a?(Sketchup::Face) newFace = tmp.copy(group.entities, nil) end end
- Code: Select all
class Sketchup::Face def copy(ents, trans) vec = Geom::Vector3d.new 0,0,0 dist = 0
ov=[] vec.length = dist if dist != 0 self.outer_loop.vertices.each do |v| if dist != 0 ov.push(v.position.offset(vec)) else if (!trans.nil?) ov.push(v.position.transform(trans)) else ov.push(v.position) end end end outer_face = ents.add_face ov outer_face.material = "green"
inner_faces = [] if self.loops.length > 1 il = self.loops il.shift il.each do |loop| ov=[] loop.vertices.each do |v| if dist != 0 ov.push(v.position.offset(vec)) else if (!trans.nil?) ov.push(v.position.transform(trans)) else ov.push(v.position) end end end inner_face = ents.add_face ov inner_faces.push(inner_face) end inner_faces.each do |f| f.erase! end end return outer_face end end
- Code: Select all
def getEntities(element, trans, group) entitiesArray = Array.new()
if (element.is_a?(Sketchup::ComponentInstance)) elementEnts = element.definition else elementEnts = element end
elementEnts.entities.each do |entity| if entity.is_a?(Sketchup::ComponentInstance) || entity.is_a?(Sketchup::Group) if (!trans.nil?) trans = trans * entity.transformation else trans = entity.transformation end getEntities(entity, trans, group) elsif entity.is_a?(Sketchup::Face) newFace = entity.copy(group.entities, trans) end end end
Oh my goodness - lots of stuff  So, copying all the faces into the group "group" is successful. Problem: At the end, the position of "group" is different then the original one... so, the transformation doesn't work. Do you understand my Ruby code and, with a little bit of luck - can you find a mistake using the transformation? I'm not quite sure about trans = trans * entity.transformationThanks again for all your help!!! EDIT: Oh, why the tabs in the code are not shown? Now, the code looks not very clear... 
Last edited by thomthom on Wed Dec 19, 2012 8:27 pm, edited 1 time in total.
Reason: Change [ruby] tags to [code=php] tags.
-
niccah
-
- Posts: 90
- Joined: Tue Jan 03, 2012 8:26 pm
- Name: niccah
by thomthom » Wed Dec 19, 2012 8:29 pm
Regarding your modification of the Sketchup::Face class: please don't release this code in a public plugin. Modifying base classes can easily conflict with other plugins. More info: http://www.thomthom.net/thoughts/2012/0 ... velopment/
-

thomthom
- PluginStore Author

-
- Posts: 19478
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by niccah » Wed Dec 19, 2012 8:36 pm
Good hint! Thanks a lot! I will try to write everything in a module to avoid problems with other plugins! Thanks for pimping my code style!! 
-
niccah
-
- Posts: 90
- Joined: Tue Jan 03, 2012 8:26 pm
- Name: niccah
by Dan Rathbun » Wed Dec 19, 2012 11:48 pm
thomthom wrote:Regarding your modification of the Sketchup::Face class: please don't release this code in a public plugin.
If you read the new Trimble edition of the API Terms of Use, it can be understood that modifying the API classes is a violation of the terms.
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5042
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by niccah » Thu Dec 20, 2012 9:36 pm
- Code: Select all
Sketchup.active_model.entities.each do |modelEnt| if modelEnt.is_a?(Sketchup::Group) && modelEnt.name == "Model2GCode_project_x"
UI.messagebox modelEnt.transformation.origin.to_s modelEnt.entities.each do |projectEnt| if projectEnt.is_a?(Sketchup::Group) && projectEnt.name.include?("Model2GCode_part_x_")
UI.messagebox projectEnt.transformation.origin.to_s projectEnt.entities.each do |partEnt| if partEnt.is_a?(Sketchup::Face) partEnt.vertices.each do |vertex| UI.messagebox vertex.position.to_s end end end
end end
end end
I solved a lot of problems... but a last one is very tricky... But let me explain a little bit more: I have a group "Model2GCode_project_x". In this group, there is another group "Model2GCode_part_x_y". In this group, there are a lot of faces. The faces inside this inner group start in the coordinates origin of Sketchup. So, at the end, I should get at least one point in (0, 0, 0). But I get very strange points with completly different positions. However, the group.transformations are identity, means the origin of these transformations are (0, 0, 0). At first: Do you understand my problem? And then: Do you have any idea, what's going wrong? I tested a lot, but always the same problem... Thanks a lot for your help!!
-
niccah
-
- Posts: 90
- Joined: Tue Jan 03, 2012 8:26 pm
- Name: niccah
by Dan Rathbun » Thu Dec 20, 2012 11:30 pm
It is not advisable to use UI.messagebox() for debugging. (If the string argument is invalid, then UI.messagebox() either fails silently, or causes a error by itself.)
Use puts() to output inspection strings to the Console instead.
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5042
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by sdmitch » Thu Dec 20, 2012 11:34 pm
I tried to simulate your problem using the code you posted but I got 0,0,0 points for some of the faces as expected. group in a group.png Perhaps if you posted a model just so we are working on the same problem.
-

sdmitch
- PluginStore Author

-
- Posts: 1496
- Joined: Wed Mar 02, 2011 9:21 pm
- Name: sdmitch
- Operating system: Windows
- SketchUp version: 2014
- License type: Free/Make
- SketchUp use: hobby
- Level of SketchUp: Beginner
by niccah » Fri Dec 21, 2012 7:58 am
sdmitch wrote:I tried to simulate your problem using the code you posted but I got 0,0,0 points for some of the faces as expected
Perhaps if you posted a model just so we are working on the same problem.
Oh, that's so nice! Thanks a lot for your help! I uploaded a Sketchupfile: http://arbeitenkannstduspaeter.eu/Sketchup/Test3.skpWhen you get the right result - this means, I have to look for the problem on an other position... puhh...
-
niccah
-
- Posts: 90
- Joined: Tue Jan 03, 2012 8:26 pm
- Name: niccah
by niccah » Fri Dec 21, 2012 11:47 am
Okay, I played a little bit with this problem... My new findings: - when I move the group, the transformation of the outer group change in the right way - but I have still an offset (in my case in -x direction) Perhaps it helps a little bit to find the main problem!? 
-
niccah
-
- Posts: 90
- Joined: Tue Jan 03, 2012 8:26 pm
- Name: niccah
by niccah » Fri Dec 21, 2012 12:15 pm
I think, I solved the problem - but I don't know exactly, what WAS wrong...
I saw, by copiing the selected faces into a new group, not every face has the original direction. So, I changed my Face.copy function (I know, its not good to change the Face.class, but I will solve THIS problem later) in that way:
outer_face = ents.add_face ov outer_face.material = "green" if outer_face.normal != self.normal outer_face.reverse! end
Now, all the faces have the right direction and now the problem with the offset of the points is gone.
But, to be honest, I have realy no idea, how these two problems correlate! And it doesn't help, to change the direction of these faces by hand - the problem stays! Just by copiing all the faces again, the problem of the offset is gone!
Do you have ANY idea what's going on?
I thank you sohhhhh much for all your support!!! You helped my realy a lot!
-
niccah
-
- Posts: 90
- Joined: Tue Jan 03, 2012 8:26 pm
- Name: niccah
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Developers' Forum
|