The upside with using the read_default and write_default is that I can piece meal access a particular setting or settings rather than accessing and overwriting the entire JSON file.
But you have complete control, and can be sure that settings are written when you think they should be.
SketchUp freezes and the settings changes don’t get written if you continue to rely upon the API.
Oh, and… since you’ll likely be writing your own plugin specific JSON files to a plugin specific folder, they can be broken up into smaller sets of options.
For webdialogs, stress that going the JSON route … think OpenStruct on the Ruby side, and JavaScript Object on the browser side.
It’s a pipe character (if it’s not the cursor,) and does not belong there.
But I wonder what happens when in Ruby when JSON.parse() encounters an unexpected character like this. It is actually in the expected position of the next key string.
What bugs me though is the other global settings are being read and written to just fine from all indications however when the user goes to set the serial number it doesn’t take. There must be something I am missing.
This is the piece of code that writes the new serial number:
@Pluginserial_existing = Sketchup.read_default "MEDEEK_TRUSS_PLUGIN", "PLUGIN_SERIAL"
this_dir=File.dirname(__FILE__)
# Fix for ruby 2.0
if this_dir.respond_to?(:force_encoding)
this_dir=this_dir.dup.force_encoding("UTF-8")
end
Sketchup.load(File.join(this_dir,"MEDEEK_UPDATE.rbs"))
if @Pluginserial_existing
if (@Pluginserial_existing == @Pluginserial_new)
else
if (@Pluginserial_new =~ /^MDKPLG1\d{2}8\d{10}$/)
#########################################
#
# Register Plugin Serial Number
#
#########################################
Medeek_Engineering_Inc_Extensions::MedeekTrussPlugin::Update::MedeekMethods.registrationlog @Pluginversion, @Pluginserial_new
end
end
else
if (@Pluginserial_new =~ /^MDKPLG1\d{2}8\d{10}$/)
#########################################
#
# Register Plugin Serial Number
#
#########################################
Medeek_Engineering_Inc_Extensions::MedeekTrussPlugin::Update::MedeekMethods.registrationlog @Pluginversion, @Pluginserial_new
end
end
######
@Pluginserial_write_result = Sketchup.write_default "MEDEEK_TRUSS_PLUGIN", "PLUGIN_SERIAL", @Pluginserial_new
Is my regexp flawed? One thing I have noticed is that when a user enters in leading or trailing white spaces it rejects the serial number so I should probably put in some code that cleans all the white spaces out of the entry first before processing it.
Just for completeness here is the registrationlog method called in the block of code above:
def registrationlog (pluginversion, pluginserial)
@Plgversion = pluginversion
@Plgserial = pluginserial
@Suversion = Sketchup.version
@Locale = Sketchup.get_locale
@Platform = Sketchup.platform
@Su64bit = Sketchup.is_64bit?
@Supro = Sketchup.is_pro?
@Macaddr1 = "0001"
@Macaddr2 = "0002"
####################
#
# Send Registration Data
require 'open-uri'
@Install_data_url = "http://design.medeek.com/calculator/sketchup/DATA/medeektrusspluginregister.pl?action=REGISTERDATA&key=jw53pt22&version=#{@Plgversion}&license=#{@Plgserial}&suversion=#{@Suversion}&locale=#{@Locale}&platform=#{@Platform}&su64bit=#{@Su64bit}&supro=#{@Supro}&macaddr1=#{@Macaddr1}&macaddr2=#{@Macaddr2}&winhostname=#{@Win_Hostname}&winphysicaladdr=#{@Win_Physicaladdress}&winadapter=#{@Win_Adapter}"
begin
open(@Install_data_url) { |io|
url_response = io.read
if /Status: OK/.match(url_response)
# Data transmitted successfully
# UI.messagebox ("Registration with Medeek Server was successful, Click OK to proceed.")
UI.messagebox("Thank-you for registering the Medeek Truss Plugin.\nYour licensed copy is registered with Serial Number: #{@Plgserial}")
else
UI.messagebox ("Registration with Medeek server was unsuccessful, Click OK to proceed.")
end
}
rescue StandardError => e
UI.messagebox ("Unable to connect to Medeek server for registration, Click OK to proceed.")
end
end