• Login
sketchucation logo sketchucation
  • Login
ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

Dynamic component, Ruby and MySQL

Scheduled Pinned Locked Moved Developers' Forum
2 Posts 2 Posters 445 Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    blue_orchid
    last edited by blue_orchid 3 Oct 2011, 19:02

    [color=#BF4040]UI.menu("Plugins").add_item('Condition Rating1') { Jeny.paint }
    
    module Jeny
    def self.paint
    require 'mysql'
    dbh = Mysql.real_connect("localhost", "root", "***", "test",3306)
    
    dbh.query("drop table if exists condition_rating")
    dbh.query("create table condition_rating(component varchar(20), rating int(1))")
    dbh.query("insert into condition_rating values('Deck',1),('Superstructure',2), ('Substructure',3)")
    #printf "%d rows were inserted\n",dbh.affected_rows
    
    res = dbh.query("SELECT * FROM condition_rating where rating = '3'")
    while row = res.fetch_row do
    #dbh.query("SELECT * FROM condition_rating")
    
    #printf "%s, %s\n", row[0], row[1]
    a=row[0]
    
    
    b=row[1]
    printf "%s, %s\n",row[0],b
    
    end
            Sketchup.active_model.entities.to_a.each{|e|
                if b=='1'
                    e.definition.set_attribute 'dynamic_attributes', 'material', 'red'
                    e.definition.set_attribute 'dynamic_attributes', '_material_formula', '"red"'
                    $dc_observers.get_latest_class.redraw_with_undo(e)
    
                elsif b=='2'
                    e.definition.set_attribute 'dynamic_attributes', 'material', 'green'
                    e.definition.set_attribute 'dynamic_attributes', '_material_formula', '"green"'
                    $dc_observers.get_latest_class.redraw_with_undo(e)
    
                elsif b=='3'
                    e.definition.set_attribute 'dynamic_attributes', 'material', 'blue'
                    e.definition.set_attribute 'dynamic_attributes', '_material_formula', '"blue"'
                    $dc_observers.get_latest_class.redraw_with_undo(e)
    
               elsif b=='4'
                    e.definition.set_attribute 'dynamic_attributes', 'material', 'yellow'
                    e.definition.set_attribute 'dynamic_attributes', '_material_formula', '"yellow"'
                    $dc_observers.get_latest_class.redraw_with_undo(e)
    
               elsif b==5
                    e.definition.set_attribute 'dynamic_attributes', 'material', 'cyan'
                    e.definition.set_attribute 'dynamic_attributes', '_material_formula', '"cyan"'
                    $dc_observers.get_latest_class.redraw_with_undo(e)
    
               elsif b==6
                    e.definition.set_attribute 'dynamic_attributes', 'material', 'darkorange'
                    e.definition.set_attribute 'dynamic_attributes', '_material_formula', '"darkorange"'
                    $dc_observers.get_latest_class.redraw_with_undo(e)
    
               elsif b==7
                    e.definition.set_attribute 'dynamic_attributes', 'material', 'lightgreen'
                    e.definition.set_attribute 'dynamic_attributes', '_material_formula', '"lightgreen"'
                    $dc_observers.get_latest_class.redraw_with_undo(e)
    
                end
            }
        end
    end[/color]
    
    
    
    
    

    What I did in the script

    1. created the MySQl table and its data using ruby script

    Table contains these two columns which are Component and Rating

    Values of table:
    a.Component:Deck, Rating: 1
    b.Component: Superstructure, Rating:2
    c.Component: Substructure, Rating:3

    I created the ruby saying that if rating is 1, then color that object.

    GoogleSketchup:
    I created model which have dynamic components like deck, superstructure and substructure with an attribute 'rating'. This attribute for each component has values from 1-7.

    My problem: I am unable to connect the dynamic components of sketchup model to the 'component' of MySQL table.

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 3 Oct 2011, 21:40

      This is only going to be accessible to those user who have require 'mysql' accessible...
      Can you be a little more generic in your question ? 😕
      OR perhaps more specific... and change the post's title to say
      ' MySQL, Ruby and Dynamic-Components - HELP!'

      TIG

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      1 / 1
      • First post
        2/2
        Last post
      Buy SketchPlus
      Buy SUbD
      Buy WrapR
      Buy eBook
      Buy Modelur
      Buy Vertex Tools
      Buy SketchCuisine
      Buy FormFonts

      Advertisement