sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Add_face from edges??

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 3 Posters 521 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W Offline
      wawmsey7
      last edited by

      Hi, I'm pretty new to ruby coding in sketchup so i'm just trying to get my head around a few bits of basic code. I'm trying to make a face from two straight edges and a curve.... the edges are drawing fine but i'm getting an error when I try to make a face from the edges??

      this is my code atm...

      %(#004080)[radius =10
      startangle =90.degrees
      endangle =0.degrees

      centerpoint = Geom::Point3d.new
      vector = [0,0,1]
      vector2 = [1,0,0]
      vector3 = vector.normalize!
      model = Sketchup.active_model
      entities = model.active_entities
      curve = entities.add_arc centerpoint, vector2, vector3, radius, endangle, startangle

      edge1 = entities.add_edges [0,0,0],[0,radius,0]
      edge2 = entities.add_edges [0,0,0], [radius,0,0]
      face = entities.add_face (edge1,curve,edge2)]

      In the API documentation it says I should be able to make a face from a bunch of edges...

      %(#0000BF)[entities.add_face(edge1, edge2, edge3, ...)
      entities.add_face(edgearray)
      entities.add_face(pt1, pt2, pt3, ...)
      entities.add_face([pt1, pt2, pt3,...])
      entities.add_face(curve)]

      😕

      Does anyone know why this won't work?

      Thanks in advance

      Matt

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        @wawmsey7 said:

        Hi, I'm pretty new to ruby coding in sketchup so i'm just trying to get my head around a few bits of basic code. I'm trying to make a face from two straight edges and a curve.... the edges are drawing fine but i'm getting an error when I try to make a face from the edges??

        this is my code atm...

        %(#004080)[

        radius =10
        > startangle =90.degrees
        > endangle =0.degrees
        > 
        > centerpoint = Geom;;Point3d.new
        >  vector =  [0,0,1]
        >  vector2 =  [1,0,0]
        >  vector3 = vector.normalize!
        >  model = Sketchup.active_model
        >  entities = model.active_entities
        >  curve = entities.add_arc centerpoint, vector2, vector3, radius, endangle, startangle
        > 
        > edge1 = entities.add_edges [0,0,0],[0,radius,0]
        > edge2 = entities.add_edges [0,0,0], [radius,0,0]
        > face = entities.add_face (edge1,curve,edge2)
        

        ]

        In the API documentation it says I should be able to make a face from a bunch of edges...

        %(#0000BF)[entities.add_face(edge1, edge2, edge3, ...)
        entities.add_face(edgearray)
        entities.add_face(pt1, pt2, pt3, ...)
        entities.add_face([pt1, pt2, pt3,...])
        entities.add_face(curve)]

        😕

        Does anyone know why this won't work?

        Thanks in advance

        Matt

        The problem is that you have a mixture of edges and an edge array. It will work if you combine them into a single array

        face = entities.add_face (edge1+curve+edge2)
        
        

        For future reference, always use a code block to simplify the selecting and copying.

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • W Offline
          wawmsey7
          last edited by

          thanks for your quick response, that worked perfectly!

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            You should also be able to use Ruby's parameter expansion operator *.
            It expands arrays into parameter lists:

            face = entities.add_face(edge1,*curve,edge2)

            Also, do not put a space between the method name and the opening parenthesis when making method calls. (Ruby 2.0 will generate an error, whereas Ruby 1.8 just spit out a warning.)

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • W Offline
              wawmsey7
              last edited by

              Thanks.

              Just another quick one...

              I'm also struggling to make a simple rotation on an edge

              my code atm is...

               model = Sketchup.active_model
               entities = model.active_entities
              edge1 = entities.add_edges [0,0,0], [0,10,0]
              
              tr = Geom;;Transformation.rotation([0,0,0],[0,1,0],40.degrees)
              edge1.transform!(tr)
              
              

              again the edge draws fine but my rotation code throws up an error!

              anyone got any ideas?

              Thanks again
              Matt

              1 Reply Last reply Reply Quote 0
              • sdmitchS Offline
                sdmitch
                last edited by

                @wawmsey7 said:

                Thanks.

                Just another quick one...

                I'm also struggling to make a simple rotation on an edge

                my code atm is...

                 model = Sketchup.active_model
                >  entities = model.active_entities
                > edge1 = entities.add_edges [0,0,0], [0,10,0]
                > 
                > tr = Geom;;Transformation.rotation([0,0,0],[0,1,0],40.degrees)
                > edge1.transform!(tr)
                > 
                

                again the edge draws fine but my rotation code throws up an error!

                anyone got any ideas?

                Thanks again
                Matt

                rotation of an edge on the Y axis around the Y axis makes no sense.

                .transform! is for groups,components,vectors,points,etc. but not edges.

                model = Sketchup.active_model
                entities = model.active_entities
                edge1 = entities.add_edges [0,0,0], [0,10,0]
                #tr = Geom;;Transformation.rotation([0,0,0],[0,1,0],40.degrees)#rotation around Y axis?
                tr = Geom;;Transformation.rotation([0,0,0],[0,0,1],40.degrees)
                #edge1.transform!(tr)#transform! not allowed for edge.
                entities.transform_entities(tr,edge1)
                

                Nothing is worthless, it can always be used as a bad example.

                http://sdmitch.blogspot.com/

                1 Reply Last reply Reply Quote 0
                • W Offline
                  wawmsey7
                  last edited by

                  thanks again for your help - that makes a lot more sense!

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    @wawmsey7 said:

                    
                    > edge1.transform!(tr)
                    > 
                    

                    again the edge draws fine but my rotation code throws up an error!

                    Matt, have the Ruby Console open when testing code, and paste the error message in the post, if your asking about Ruby errors.

                    The first error message line in the backtrace will contain a sub-string like:
                    “filename:lineNo: inmethod'”or “filename:lineNo.”`
                    which tells you exactly what ruby script, it's line number, and possibly the method that it occurred within.

                    The message tells you (usually) exactly what went wrong.
                    For example,
                    Error: #<NoMethodError: undefined methodtransform!' for #Sketchup::Edge:0x00000009e8e690>... tells you that the Sketchup::Edge class has no instance method named " transform!`".

                    So at that point your quickest way to resolve your dilemma, is to go to the API's Method index, and find methods in the "T" category that have to do with transformations.

                    See Exception class, backtrace() method.

                    And more generally dealing with exceptions.

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    Buy SketchPlus
                    Buy SUbD
                    Buy WrapR
                    Buy eBook
                    Buy Modelur
                    Buy Vertex Tools
                    Buy SketchCuisine
                    Buy FormFonts

                    Advertisement