[Plugin] Edges/Construction Lines Converter V1.3
-
#Corrected code for plugin to work in SU 2024
@@colorx = "Black" @@stipplex = "_" def initialize @endpoints = false @change = false @colorlist = String.new colorlist = Sketchup::Color.names l = colorlist.size l = l - 1 for e in 0..l do @colorlist = @colorlist + colorlist[e].to_s + "|" if e != l @colorlist = @colorlist + colorlist[e].to_s if e == l end cflag = false end def activate @model = Sketchup.active_model @ents = @model.active_entities @sel = @model.selection @lines = [] show_status conversion end def show_status statustext = "Edges into \"" + @@stipplex + "\" construction lines and cline to " + @@colorx + " edges (Command)" if !@change statustext = "Construction lines into \"" + @@stipplex + "\" clines and edges into " + @@colorx + " edges (Command)" if @change statusoption = "; Draw end points (Alt)" if @endpoints statusoption = "; Endpoints not drawn (Alt)" if !@endpoints status_label = statustext + statusoption Sketchup.set_status_text(status_label, SB_PROMPT) end def conversion @model.start_operation "Line Conversion" view = @model.active_view if !@change for e in @sel if e.class == Sketchup::Edge lstart = e.start.position lend = e.end.position if @endpoints @ents.add_cpoint lstart @ents.add_cpoint lend end @ents.add_cline(lstart, lend, @@stipplex) @lines.push(e) elsif e.class == Sketchup::ConstructionLine if e.start && e.end lstart = e.start.position lend = e.end.position if @endpoints @ents.add_cpoint lstart @ents.add_cpoint lend end @ents.add_edges(lstart, lend) @ents[-1].material = @@colorx.to_s @ents[-1].find_faces @lines.push(e) end end # e.class end # for e if !@lines.empty? @lines.each do |e| e.erase! if e.valid? end end elsif @change for e in @sel if e.class == Sketchup::ConstructionLine e.stipple = @@stipplex if e.start && e.end lstart = e.start.position lend = e.end.position if @endpoints @ents.add_cpoint lstart @ents.add_cpoint lend end end elsif e.class == Sketchup::Edge lstart = e.start.position lend = e.end.position if @endpoints @ents.add_cpoint lstart @ents.add_cpoint lend end e.material = @@colorx.to_s end # e.class view.invalidate end # for e end # @change @sel.clear @model.commit_operation end def self.xLine_validate_selection_edge Sketchup.active_model.selection.each {|e| return true if e.class == Sketchup::Edge} return nil end def self.xLine_validate_selection_xline Sketchup.active_model.selection.each {|e| return true if (e.class == Sketchup::ConstructionLine && e.start && e.end)} return nil end def onKeyDown(key, repeat, flags, view) if key == VK_COMMAND ### Cmd toggles stipples and change @change = !@change end if key == VK_ALT ### Alt toggles end points @endpoints = !@endpoints end show_status end def onLButtonDown(flags, x, y, view) ph = view.pick_helper ph.do_pick(x, y) best = ph.best_picked @sel.add(best) if best conversion end def onRButtonDown(flags, x, y, view) cflag = true if @@colorx == "Black" list = ["-|.|-.-|_", @colorlist] prompt = ["XLine Stipple: ", "Color: "] values = [@@stipplex, @@colorx] result = inputbox(prompt, values, list, "Change Parameters") if result @@stipplex = result[0].to_s @@colorx = result[1].to_s if cflag && @model.rendering_options["EdgeColorMode"] != 0 choice = UI.messagebox "The edges color will only be visible if you switch to \"display color by material\". Do you want to do this at this time?", MB_YESNOCANCEL case choice when 6 @model.rendering_options["EdgeColorMode"] = 0 # sets up styles for Color By material cflag = false when 7 cflag = false end end # if cflag end # if result show_status conversion end def deactivate(view) Sketchup.set_status_text("", SB_PROMPT) Sketchup.set_status_text("", SB_VCB_LABEL) Sketchup.set_status_text("", SB_VCB_VALUE) end end if !file_loaded?("XLinem.rb") UI.add_context_menu_handler do |menu| if XLinemTool.xLine_validate_selection_edge menu.add_separator menu.add_item("Convert to XLine") {Sketchup.active_model.select_tool(XLinemTool.new)} elsif XLinemTool.xLine_validate_selection_xline menu.add_separator menu.add_item("Convert to Edge") {Sketchup.active_model.select_tool(XLinemTool.new)} end end end unless file_loaded?(__FILE__) cmd = UI::Command.new("xlinem Convert") {Sketchup.active_model.select_tool(XLinemTool.new)} cmd.small_icon = File.join(File.dirname(__FILE__), "Xlinem", "Xline_SM.png") cmd.large_icon = File.join(File.dirname(__FILE__), "Xlinem", "Xline_LG.png") cmd.tooltip = "Construction Line Conversion" tb = UI.toolbar("Line Conversion") # Fixed string termination tb.add_item(cmd) tb.restore end```
-
@Sketcheldar
Because you haven't formatted your code properly it's unusable.
Use the </> button to add the correct 'Code' formatting...
Which is three ` at the start & end of your code, on a separate line. -
@Sketcheldar Something is wrong with this code...!!??
-
@FlorinAp
That code has never worked.
The code as presented applies to a Class [XLinemTool] which should be inside a Module.
No Class is defined.
There's no RB file to set up the extension as SketchUp loads, and the image PNGs are not in a folder with the main code.
There's also three trailing ` characters.If the missing parts were supplied and the whole lot then packaged in an RBZ file, life would be much easier for every one...
-
@TIG Maybe somebody can do something about it, because right now we have no option to convert construction lines to edges (the reverse it is possible, at least with Curvizard).
I know only one option (DBur Guide Tools) but it can do only one line at a time....
Advertisement