Using view.line_width= ?
-
I am trying to understand what view.line_width= does. The documentation is not much help. To me is says the method draws lines of the desired width, but does not tell how. The sample code is no help.
%(#000000)[**View.line_width=**]
[floatr:tdmbx52s]SketchUp 6.0+[/floatr:tdmbx52s]
Theline_width=
method is used to set the line width to use for drawing. The value is a Double indicating the desired width in pixels.This method is usually invoked within the
draw
method of a tool.Arguments:
width - The width in pixels.Returns:
view - a View objectExample:
view.line_width = width
What is not clear from the doc is what "use for drawing" means. I suspect it means the next time the view is refreshed, which could be at a mouse movement. But if it means when I am drawing, then it could apply to some lines and not others.
Has anyone had a use for this method? What does it really do?
Thanks,
August -
It affects the lines you draw using
view.draw
andview.draw2d
. I often use it when I make tools and draw preview and guides on to the viewport. -
Actually, any of the
view.draw*
methods that draw lines. you havedraw_line
,draw_lines
anddraw_polyline
that are aliases forview.draw
, just with variousGL_*
commands. -
What the docs don't make clear at all for new users is that there is a 'draw' method available to a tool that adds temporary lines, points etc to the screen based on what's there or what might be there as you enter parameters or adjust things: e.g. see my EEbyVector or EEbyLathe tools - these preview the shape that will be made as a 'ghost' outline of edges, and as you pick new points the shape changes; or if you enter a new segment count as say 24s that changes too... The various methods available within 'draw' let you change the width, stipple-style and color of the lines etc etc.
These 'drawn things' only last as long as you allow them to - e.g. you can tell the tool to 'draw' them only if certain conditions prevail - often in the formif @state==1 ...
, or 'draw' different things at different stages in the operation...
To add geometry permanently to the model you use theentities.add_...
- as you already know - e.g.entities.add_line(p1,p2)
. If you are adding a large mesh, for example in my EEbyLathe tool, you make the collection of points based on the current cursor or picked locations and 'draw' the parts to shown an outline of what might get made [say as dashed thin scarlet lines, without faces], once the user has double-clicked or cmd-key or whatever the 'enter' action is designed to be - then that set of points - usually saved as an array[s] that updates as you go - and which is finally used to actually make some real geometry in the entities collection at the end... -
Here is a very simple example of how to implement the draw method so you can draw things to the screen. And the line_width method can be called from inside the draw mtheod. Just change the specified width and re-run to see the changes.
class Clf_draw_corners def onMouseMove(flags, x, y, view) @cursor = [x,y] view.invalidate end def draw(view) view.line_width = 5 @pt1 = view.corner(0) @pt2 = view.corner(1) @pt3 = view.corner(2) @pt4 = view.corner(3) view.draw2d GL_LINES, [@cursor, @pt1, @cursor, @pt2, @cursor, @pt3, @cursor, @pt4] end end Sketchup.active_model.select_tool Clf_draw_corners.new
Chris
-
Can you use this method to draw a 3D edge that is thicker in pixels than regular edges? If so, please post an attachment with the ruby script.
-
@unknownuser said:
Can you use this method to draw a 3D edge that is thicker in pixels than regular edges? If so, please post an attachment with the ruby script.
"3D edge" - the edge is 2D but in 3D space.
And Chris' sample in the previous post demonstrates how to draw with these methods. -
@unknownuser said:
Can you use this method to draw a 3D edge that is thicker in pixels than regular edges? If so, please post an attachment with the ruby script.
As explained all of the 'draw' graphics are only 'transitory' - they are used as 'guides' in a tool - they vanish when that stage of a tool's use ends or another tool is invoked...
To change the edge thickness in regular geometry 'edges' you have to use 'trickery' - like my 2D Line Style Tool [which works in 3D too]. You can call up a dialog [right-click] to set your requirements - thickness [50mm etc], color [red etc], line-style [dash/dot/center etc] etc and you then pick the line[s] to 'style' - they are moved to a hidden layer, and an instance with a 'face' the correct width/color/style etc is placed in its stead - it's centered on the line if it's unfaced or coplanar with two faces, or stepped in onto the face if lone faced [if two-faced the face 'squarest' to the camera gets the new edge]... Selecting already Styled Line[s] gives a right-menu lets you Edit it/them and change thickness/color/style as desired... -
@tig said:
To change the edge thickness in regular geometry 'edges' you have to use 'trickery' - like my 2D Line Style Tool [which works in 3D too]. You can call up a dialog [right-click] to set your requirements - thickness [50mm etc], color [red etc], line-style [dash/dot/center etc] etc and you then pick the line[s] to 'style' - they are moved to a hidden layer, and an instance with a 'face' the correct width/color/style etc is placed in its stead - it's centered on the line if it's unfaced or coplanar with two faces, or stepped in onto the face if lone faced [if two-faced the face 'squarest' to the camera gets the new edge]... Selecting already Styled Line[s] gives a right-menu lets you Edit it/them and change thickness/color/style as desired...
I would like to see this plugin. Can you post it?
-
The 2D Tools set is available in the Plugins forum here do a search for it and by author 'TIG'...
I could give you a direct link but it's good that you learn to find things yourself - 'give a man a fish or teach a man to fish' etc...
Advertisement