Group in a group in a group... - transform point to outside?

Re: Group in a group in a group... - transform point to outs

Postby 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

# add selected faces to 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
# Thanks to http://sketchucation.com/forums/viewtopic.php?f=180&t=29138&start=0
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 
# Class Face  


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.transformation


Thanks again for all your help!!!

EDIT: Oh, why the tabs in the code are not shown? Now, the code looks not very clear... :roll:
0
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 
 

Re: Group in a group in a group... - transform point to outs

Postby 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/
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: Group in a group in a group... - transform point to outs

Postby niccah » Wed Dec 19, 2012 8:36 pm

thomthom wrote: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/


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!! :)
0

niccah 
 

Re: Group in a group in a group... - transform point to outs

Postby 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.
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: Group in a group in a group... - transform point to outs

    Postby 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? :roll:
    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!!
    0

    niccah 
     

    Re: Group in a group in a group... - transform point to outs

    Postby 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.
    0
      I'm not here much anymore. But a PM will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      Re: Group in a group in a group... - transform point to outs

      Postby 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.
      0
      Nothing is worthless, it can always be used as a bad example.

      http://sdmitch.blogspot.com/
      User avatar
      sdmitch 
      PluginStore Author
      PluginStore Author
       

      Re: Group in a group in a group... - transform point to outs

      Postby 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.skp

      When you get the right result - this means, I have to look for the problem on an other position... puhh...
      0

      niccah 
       

      Re: Group in a group in a group... - transform point to outs

      Postby 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!? :)
      0

      niccah 
       

      Re: Group in a group in a group... - transform point to outs

      Postby 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!
      0

      niccah 
       

      SketchUcation One-Liner Adverts

      by Ad Machine » 5 minutes ago



      Ad Machine 
      Robot
       



       

      Return to Developers' Forum

      Who is online

      Users browsing this forum: No registered users and 5 guests

      Visit our sponsors: