Drawing line based on fed coordinates
-
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_spacetimepathUI.menu("PlugIns").add_item("simple") { draw_simple }
Thanks,
Derek -
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...
-
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
-
@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...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement