This code finally worked π
UI.menu("Plugins").add_item('Assesment') { Inspection.color }
require 'mysql'
module Inspection
def self.color
dbh = Mysql.real_connect("localhost", "root", "***", "test",3306)
dbh.query("drop table if exists inspection")
dbh.query("create table inspection(component varchar(20), ID int(4), rating int(1))")
dbh.query("insert into inspection values('deck',2345,2),('Substructure',2349,1),('Superstructure',2353,3)")
res = dbh.query("SELECT rating FROM inspection where id = '2345'")
while row = res.fetch_row do
xx = row[0]
printf "%s\n", xx
end
res1 = dbh.query("SELECT rating FROM inspection where id = '2349'")
while row = res1.fetch_row do
xy = row[0]
printf "%s\n", xy
end
res2 = dbh.query("SELECT rating FROM inspection where id = '2353'")
while row = res2.fetch_row do
yy = row[0]
printf "%s\n", yy
end
Sketchup.active_model.entities.to_a.each{|e|
if e.get_attribute('dynamic_attributes','id','')=='2345'&& xx=='1'
e.set_attribute('dynamic_attributes','rating','1')
elsif e.get_attribute('dynamic_attributes','id','')=='2345'&& xx=='2'
e.set_attribute('dynamic_attributes','rating','2')
elsif e.get_attribute('dynamic_attributes','id','')=='2345'&& xx=='3'
e.set_attribute('dynamic_attributes','rating','3')
end
}
Sketchup.active_model.entities.to_a.each{|e|
if e.get_attribute('dynamic_attributes','id','')=='2349'&& xy=='1'
e.set_attribute('dynamic_attributes','rating','1')
elsif e.get_attribute('dynamic_attributes','id','')=='2349'&& xy=='2'
e.set_attribute('dynamic_attributes','rating','2')
elsif e.get_attribute('dynamic_attributes','id','')=='2349'&& xy=='3'
e.set_attribute('dynamic_attributes','rating','3')
end
}
Sketchup.active_model.entities.to_a.each{|e|
if e.get_attribute('dynamic_attributes','id','')=='2353'&& yy=='1'
e.set_attribute('dynamic_attributes','rating','1')
elsif e.get_attribute('dynamic_attributes','id','')=='2353'&& yy=='2'
e.set_attribute('dynamic_attributes','rating','2')
elsif e.get_attribute('dynamic_attributes','id','')=='2353'&& yy=='3'
e.set_attribute('dynamic_attributes','rating','3')
end
}
Sketchup.active_model.entities.to_a.each{|e|
if e.get_attribute('dynamic_attributes','rating','')=='1'
e.set_attribute( 'dynamic_attributes', 'material', 'black')
e.set_attribute( 'dynamic_attributes', '_material_formula', '"black"')
$dc_observers.get_latest_class.redraw_with_undo(e)
elsif e.get_attribute('dynamic_attributes','rating','')=='2'
e.set_attribute( 'dynamic_attributes', 'material', 'blue')
e.set_attribute( 'dynamic_attributes', '_material_formula', '"blue"')
$dc_observers.get_latest_class.redraw_with_undo(e)
elsif e.get_attribute('dynamic_attributes','rating','')=='3'
e.set_attribute( 'dynamic_attributes', 'material', 'red')
e.set_attribute( 'dynamic_attributes', '_material_formula', '"red"')
$dc_observers.get_latest_class.redraw_with_undo(e)
end
}
end
end
Thanks to all.