sketchucation logo sketchucation
    • Login
    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

    Dynamic component, Ruby and MySQL

    Scheduled Pinned Locked Moved Developers' Forum
    2 Posts 2 Posters 461 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

      [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
      • TIGT Offline
        TIG Moderator
        last edited by

        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
        • First post
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement