How to show lines one by one when I use 'add_line' to add them into a model

hi, guys! I am a newcomer. I’m trying to draw lines with Sketchup Ruby API. I met two problem. 1) when I use ‘add_line’ to add lines into a model. I want them shown in Sketchup one by one. But, they are always shown together after the final ‘add_line’. 2) how to set color of the lines. It seems that ‘material’ can not work when attach a material with color to the lines. And i’m confused that it can work when attach it to a face. Does anyone have any idea how to approach these or give me any tips? thk.

Ruby blocks the main SketchUp engine while it executes, so SketchUp is not able to update the view until Ruby pauses. A Tool will pause each time it returns control to the user, awaiting another event callback. That technique relies on the user to determine when the next edge is drawn. You can also use UI.start_timer to force Ruby to pause. If you use a repeating timer, you will need to be careful to program a stopping condition else it will repeat forever and lock up SketchUp!

You can assign a material to an Edge, but whether this color shows in the model is determined by the active Style, which must have color->By Material set via the Edge properties panel in the Styles window. In Ruby code, you do the equivalent by changing Sketchup.active_model.rendering_options[“EdgeColorMode”]. The default of 0 means “All Same”, 1 means “By Material”, and 2 means “By Axis”. If you want to retain this setting in the current Style, invoke Sketchup.active_model.styles,update_selected_style.

1 Like

Add “Sketchup.active_model.active_view.refresh;sleep(1)” after each .add_line statement.

1 Like

@slbaumgartner, you got the order wrong, it differs from the GUI…

Sketchup.active_model.rendering_options["EdgeColorMode"] = 0 # By Material

Whoops! 0 → By Material, 1 → All Same, 2 → By Axis

1 Like

Yes, that works well, nice idea! sleep() causes Ruby to relinquish control to SketchUp.

When I use “sleep(secs)” after each .add_line, Stechup crashes. Instead ,I use "timer_id = UI.start_timer(secs,true){ # do .add_line } " to show the lines one by one .

john_drivenupthewall is right.

Thanks all.

This topic was automatically closed after 91 days. New replies are no longer allowed.