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!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Drawing line based on fed coordinates

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 586 Views 2 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
      jderekito
      last edited by

      Hello,
      I am somewhat new to SketchUp but am quite excited about the possibilities of it. Here is my question and hopefully someone can help. My goal is to write a ruby script to draw a line between two defined points. I have created a new blank model and drawn a rectangle on the x and y axis. I am testing this by locating one of the the x,y,z coordinates of the rectangle by using the text tool to show the points (e.g. ~ 0.79m, ~ 0.60m, 0.00m). So I just trying to start at that corner and draw a line straight up the Z axis programmatically. However, it is being draw somewhere way closer to the origin of the model around 0.02m, ~ 0.02m, 0.00m. I was hoping someone could point me in the write direction with doing this. Thanks ahead of time.

      require 'sketchup.rb'

      def draw_simple
      pt1 = Geom::Point3d.new(0.79, 0.60, 0.00)
      pt2 = Geom::Point3d.new(0.79, 0.60, 1.00)
      model = Sketchup.active_model
      new_face = model.entities.add_line(pt1, pt2)
      new_face.pushpull 10
      end #def draw_spacetimepath

      UI.menu("PlugIns").add_item("simple") { draw_simple }

      Thanks,
      Derek

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

        Units in points, lengths etc always default to SUp's base units, which is "inches": if you want to use metric dimensions use the format 0.79.m or 79.cm or 790.mm etc... Then it'll be as expected...

        Also, I see you have a pushpull that needs a face - and a face need at least three [coplanar] edges etc...

        TIG

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

          Thanks TIG,
          The defaulting to inches explains it. For now I am just trying to draw a single line. If I just drawing a single line does it still need the face and edges. Thanks again for you assistance as I am still learning my way around SU.

          Derek

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

            @jderekito said:

            Thanks TIG,
            The defaulting to inches explains it. For now I am just trying to draw a single line. If I just drawing a single line does it still need the face and edges. Thanks again for you assistance as I am still learning my way around SU.

            Derek

            'Line' and 'Edge' are interchangeable in this context...
            A line [edge] is just a line.

            edge=entities.add_line(pt1,pt2)
            

            for one line,

            edges=add_edges(pt1,pt2,pt3); edge0=edges[0]; edge1=edges[1]
            

            for multiple lines [edges] strung between the list of points - if you use .add_edges you get an array of edges - if there's only one you still need to use edges[0] to find it, if you .add_line you get just the one edge [line].
            A face needs at least 3 edges with common vertices. More edges also have to be coplanar.

            face=entities.add_face(xxxxx)
            

            takes a 'list/array of points', it then makes new edges with a new face,
            or a 'list/array of edges', or a 'closed-curve' - it then makes a new face to these existing edges
            So there are several ways:
            Make the points and then make the edges and face in one go - probably what you want -

            face=entities.add_face(pointsList)
            

            Make the edges from the points and add the face to them - useful if some edges pre-exist -

            edges=entities.add_edges(pointsList); face=entities.add_face(edges)
            

            Make the edges and then 'find_faces' that they can have - useful if it's a set of 3D edges -

            edges=entities.add_edges(pointsList); edges[0].find_faces
            
            • it returns only the number of faces that it's made - if you want to find the face itself then you then need to use
            face=edges[0].faces[0]
            

            additionally...

            TIG

            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