sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    โš ๏ธ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    Offset top face only...need help!

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 340 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.
    • renderizaR Offline
      renderiza
      last edited by

      Hi, bellow is an attempt to offset the top face lines but I am running into some issues.

      model = Sketchup.active_model
      ents = model.active_entities
      faces = ents.grep(Sketchup;;Face)
      sel = model.selection
      
      faces.each do |face|
      
        if face.normal.z == 1
          
          edges = face.edges
          edges.to_a.each do |e|
      
            p1 = e.start.position
            p2 = e.end.position
            
            x1 = p1.x
            x2 = p2.x
            y1 = p1.y
            y2 = p2.y
            
            length =  Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) 
            
            offset = 10.0
            
            x1p = x1 + offset * (y2-y1)/length #/
            x2p = x2 + offset * (y2-y1)/length #/
            y1p = y1 + offset * (x1-x2)/length #/
            y2p = y2 + offset * (x1-x2)/length #/
            
            newedges = ents.add_line([x1p,y1p,p1.z+5],[x2p,y2p,p2.z+5])
           
            sel.add newedges
          end
      
        end
      
      end
      

      Where do I start ๐Ÿ˜• ...

      Notice that when I add the line, the z coordinates have +5 added because if I make it same height as face the new edges break the next edge that it will offset and mess the result.

      You can see what I mean if you replace "p1.z+5" to "p1.z" & "p2.z+5" to "p2.z". You need to have a face that where z axis = 1.

      What I had in mind was to elevate the edges by 5 and somehow abstract the vertex position where the new edges intersect. Problem is they don't produce any vertex.

      Not sure if I am explaining myself but all I want is to offset the top face. Any help will be appreciated as always.

      Thanks!

      [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

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

        Read my SmartOffset code to see how I offset the edges of a given face...

        TIG

        1 Reply Last reply Reply Quote 0
        • tt_suT Offline
          tt_su
          last edited by

          Side note - Ruby is very slow. You'll find using the SketchUp API's .distance method much faster than doing your own length calculation. At least if you do this for a somewhat large set of entities.

          1 Reply Last reply Reply Quote 0
          • renderizaR Offline
            renderiza
            last edited by

            @tig said:

            Read my SmartOffset code to see how I offset the edges of a given face...

            ๐Ÿ‘Š ๐Ÿ˜ฎ ๐Ÿ˜ฒ ๐Ÿ˜• ๐Ÿ˜ž ๐Ÿ˜ข
            That is by no means an easy task but I will try to understand what you wrote. Isn't there a 1st grader version? ๐Ÿ˜†

            @tt_su said:

            Side note - Ruby is very slow. You'll find using the SketchUp API's .distance method much faster than doing your own length calculation. At least if you do this for a somewhat large set of entities.

            That is good to know thanks!

            [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

            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