sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Followme in ruby not working as expected

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 446 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.
    • J Offline
      JohnRees
      last edited by

      My first post! I'm trying to write a sketchup importer that reads coordinates of walls from a text file then draws a line using the coordinates and draws the wall using followme.

      The reason I want to use followme rather than just drawing faces is I want to draw the external brick leave and then the internal block wall and have corners drawn neatly.

      Here is some example code (similar to how the importer will work)

      ` mod = Sketchup.active_model # Open model
      ent = mod.entities # All entities in model
      sel = mod.selection # Current selection
      wallGroup = ent.add_group

      #face points
      pt1 = [0,0,0]
      pt2 = [0,10,0]
      pt3 = [0,10,100]
      pt4 = [0,0,100]

      #line points
      lpt1 = [0,0,0]
      lpt2 = [150,0,0]
      lpt3 = [100,150,0]
      lpt4 = [0,100,0]

      face = ent.add_face pt1, pt2, pt3, pt4
      line = ent.add_line lpt1, lpt2
      line = ent.add_line lpt2, lpt3
      #the line below doesn't work with follow me
      #line = ent.add_line lpt3, lpt4

      #line = ent.add_line lpt4, lpt1

      status = face.followme line`

      follow me seems to be inconsistent in its behavior. If I draw the first two lines and use followme it works exactly how I want and the wall looks like this.

      https://dl.dropboxusercontent.com/u/3806610/2014-06-20_1620.png

      If however I try drawing three lines then followme I get this.

      https://dl.dropboxusercontent.com/u/3806610/2014-06-20_1620_001.png

      Can anyone explain where I'm going wrong? Any help is appreciated!

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        Draw the 3 edges in one go thus:
        face = ent.add_face(pt1, pt2, pt3, pt4) lines = ent.add_edges(lpt1, lpt2, lpt3, lpt4) status = face.followme(lines)

        Incidentally you set ent=model.entities - it would be better to refer to the active entities in case the user is in an edit mode...
        ent=model.active_entities

        You also make a group and do not use it ?
        wallGroup = ent.add_group
        Why not add the new geometry directly to that? Thus:
        ents=wallGroup.entities
        then refer to that ents rather than ent, thus:
        face = ents.add_face(pt1, pt2, pt3, pt4) lines = ents.add_edges(lpt1, lpt2, lpt3, lpt4) status = face.followme(lines)

        TIG

        1 Reply Last reply Reply Quote 0
        • J Offline
          JohnRees
          last edited by

          Thanks TIG! Will give that a go.

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            Is this what you are after?

            mod = Sketchup.active_model # Open model
            ent = mod.entities # All entities in model
            sel = mod.selection # Current selection
            wallGroup = ent.add_group
            
            #face points
            pt1 = [0,0,0]
            pt2 = [0,10,0]
            pt3 = [0,10,100]
            pt4 = [0,0,100]
            
            #line points
            lpt1 = [0,0,0]
            lpt2 = [150,0,0]
            lpt3 = [100,150,0]
            lpt4 = [0,100,0]
            
            path = []
            
            face = ent.add_face pt1, pt2, pt3, pt4
            path.push ent.add_line lpt1, lpt2
            path.push ent.add_line lpt2, lpt3
            #the line below doesn't work with follow me
            path.push ent.add_line lpt3, lpt4
            
            #line = ent.add_line lpt4, lpt1
            
            status = face.followme path
            
            

            2014-06_125.png

            Hi

            1 Reply Last reply Reply Quote 0
            • J Offline
              JohnRees
              last edited by

              Hi Jim,

              Yes that's exactly what I wanted! Thank you. I've managed to get the code to draw the internal leaf as well. The only small problem now is I'm repeating myself in the code to get this result, which seems wrong.

              Is there anyway to get this result without have almost identical code running twice? Is there anyway to push two faces along the same path at the same time to give the result below?

              https://dl.dropboxusercontent.com/u/3806610/2014-06-23_1143.png

              fyi this is how the code looks now.

              ` mod = Sketchup.active_model # Open model
              ent = mod.entities # All entities in model
              sel = mod.selection # Current selection
              wallGroup = ent.add_group

              #face points
              pt1 = [0,0,0]
              pt2 = [0,10,0]
              pt3 = [0,10,100]
              pt4 = [0,0,100]

              pt5 = [0,20,0]
              pt6 = [0,30,0]
              pt7 = [0,30,100]
              pt8 = [0,20,100]

              #line points
              lpt1 = [0,0,0]
              lpt2 = [150,0,0]
              lpt3 = [100,150,0]
              lpt4 = [0,100,0]

              path = []

              face = ent.add_face pt1, pt2, pt3, pt4

              path.push ent.add_line lpt1, lpt2
              path.push ent.add_line lpt2, lpt3
              path.push ent.add_line lpt3, lpt4

              #line = ent.add_line lpt4, lpt1

              status = face.followme path

              path = []

              face= ent.add_face pt5, pt6, pt7, pt8

              path.push ent.add_line lpt1, lpt2
              path.push ent.add_line lpt2, lpt3
              path.push ent.add_line lpt3, lpt4

              status = face.followme path`

              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