sketchucation logo sketchucation
    • Login
    1. Home
    2. Sketcheldar
    3. Best
    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
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 2
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: [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```
      posted in Plugins
      SketcheldarS
      Sketcheldar
    • 1 / 1