Alternative to get_element_value method for HtmlDialog

Hi Dan. I have been able to get the UI::htmlDialog to work using your pattern. And I get the appropriate information coming back from the javascript Sketchup.receiveValue(arg1, arg2). That works. The objective of this routine for now is to return a selected directory path. Just before process_value I’m attempting to get a list of directories/files within the path returned, but no matter what method/block/proc/ whatever, it is always returning an error stating that it undefined method.

I’m trying to call a method within the Module namespace that contains the Dir(path). These methods exist outside of the Class which contains the UI.htmlDialog. So how do I reference methods outside of the class methods defined by your example that exist outside of the htmlDialog instance?

Thanks,

Scott.

class MyToolsDialog < UI::HtmlDialog

def attach_callbacks
  add_action_callback('receiveCmd') do |not_used,id,val|
    receiveCmd(id,val)
    UI.messagebox("Inside add_action_callback(receiveCmd, directly from MyTools_Jscript.js")
  end
end

def get_element_value(id)
  #return unless id.is_a?(String)
  execute_script("sendValue('#{id}');")
end

def receiveCmd(htmlCmd,htmlParam)
  UI.messagebox("Inside receiveCmd, directly from add_action_callback()")
  process_value(htmlCmd)
  process_value(htmlParam)
  UI.messagebox("Inside receiveCmd, just before get_dir_list(#{htmlParam})")

THIS IS WHERE IT ERRORS OUT

  get_dir_list(htmlParam)

end

def process_value(id)
  # Do something with @values[id]
  puts id
end


def show(*args)
  attach_callbacks()
  super
end

def show_modal(*args)
  attach_callbacks()
  super
end

end # custom HtmlDialog subclass

def get_dir_list(x_dir)
UI.messagebox(“Inside get_dir_list #{x_dir}”)
puts listFiles(x_dir)
end

def listFiles(x_dir)
UI.messagebox(“Inside listFiles(#{x_dir})”)
xDirList = “”
UI.messagebox(“xDirList initialized…”)
xList = Dir.entries(x_dir)
UI.messagebox(“Dir.entries executed… #{xList}”)
xList.each {|fname|
if (xDirList.length() > 0) then
xDirList = xDirList + “,”
end
xDirList = xDirList + “#{fname}” unless fname.start_with?(‘.’)
}
UI.messagebox(“listFiles: returning xDirList = #{xDirList}”)
return xDirList
end

The first 2 puts prints the values returned from the javascript function.

I was elated to get the communications back into Sketchup

DirList

------------ is the command that I receive the htmlDialog javascript routines

------------ that I want to trigger the Directory List for the returned path

D:/my source directory name/Business Projects/SketchupProjects
Error: #<NoMethodError: undefined method get_dir_list' for MyTools:Module> C:/Users/Owner/AppData/Roaming/SketchUp/SketchUp 2017/SketchUp/Plugins/myRubyTools.rb:62:in receiveCmd’
C:/Users/Owner/AppData/Roaming/SketchUp/SketchUp 2017/SketchUp/Plugins/myRubyTools.rb:47:in block in attach_callbacks' SketchUp:1:in call’

Can you explain what’s happening and why it is not calling the appropriate method?