sketchucation logo sketchucation
    • Login
    1. Home
    2. blue_orchid
    3. Posts
    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
    B
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 8
    • Posts 25
    • Groups 1

    Posts

    Recent Best Controversial
    • Dynamic component, Ruby and MySQL
      [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.

      posted in Developers' Forum
      B
      blue_orchid
    • Google Sketchup and MySQL

      Hi,

      Is there any way to connect Google Sketchup Pro to MySQL using Ruby?

      posted in Developers' Forum
      B
      blue_orchid
    • RE: Color the component according to dynamic component attribute

      thanks a lot. it worked. You saved my day...

      How do u guys learn ruby for sketchup? What are the basic requirements (computer knowledge) to start ruby?
      I wish i could learn efficiently and quickly.

      Thanks again.

      posted in Newbie Forum
      B
      blue_orchid
    • RE: Color the component according to dynamic component attribute

      I don't know how to execute
      @unknownuser said:

      Material: =if(condition = 1, "Red", "Default" )
      .

      I have edited the previous code and still is not working..

      UI.menu("Plugins").add_item('painting Red') {
        model = Sketchup.active_model
        entities = model.entities.to_a
        entities_def = entities.definition
        
        condition_1 = []
        entities.each{|e|    
          if e.get_attribute('dynamic_attributes','condition','')=="1"
          condition_1 << e
          end
          }
        entities_def.set_attribute 'dynamic_attributes',
          'material', 'red'
        entities_def.set_attribute 'dynamic_attributes',
          '_material_formula', '"red"'
         
        dcs = $dc_observers.get_latest_class
        dcs.redraw_with_undo(entities)
      
      }
      

      here shortcut references are:
      %(#FF0000)[model = Sketchup.active_model
      entities = model.entities.to_a
      entities_def = entities.definition]

      I tried to select all the components with dynamic reference 'condition =1" in following code:
      condition_1 = [
      entities.each{|e|
      if e.get_attribute('dynamic_attributes','condition','')=="1"
      condition_1 << e
      end
      }]

      And, for the above selection, I tried to change the material (of dynamic reference) into red color in following code:
      %(#FF0000)[entities_def.set_attribute 'dynamic_attributes',
      'material', 'red'
      entities_def.set_attribute 'dynamic_attributes',
      '_material_formula', '"red"']

      Actually, I don't know what the codes

      dcs = $dc_observers.get_latest_class
      dcs.redraw_with_undo(entities)
      

      means, but I copied that code form the base file I used from the following code:

      UI.menu("Plugins").add_item('Make Sang Red') {
      
        # Assumes that sang is the 1st entity in model.
        sang = Sketchup.active_model.entities[0]
        sang_def = sang.definition
      
        # Override sang's shirt color to red. ("material"
        # is a special attribute that requires
        # you to set a formula to "take control" 
        # over the default material the user has painted.)
        sang_def.set_attribute 'dynamic_attributes',
          'material', 'red'
        sang_def.set_attribute 'dynamic_attributes',
          '_material_formula', '"red"'
      
        # Add a new configurable option to Sang.
        # (Any attribute that starts with an underscore
        # is a "meta attribute" that describes behavior.)
        sang_def.set_attribute 'dynamic_attributes',
          'weight', '145'
        sang_def.set_attribute 'dynamic_attributes',
          '_weight_label', 'weight'
        sang_def.set_attribute 'dynamic_attributes',
          '_weight_formlabel', 'My Weight'
        sang_def.set_attribute 'dynamic_attributes',
          '_weight_units', 'STRING'
        sang_def.set_attribute 'dynamic_attributes',
          '_weight_access', 'TEXTBOX'
      
        # Change the description that shows
        # up in the configure box with a custom
        # formula.
        sang_def.set_attribute 'dynamic_attributes',
          '_description_formula', 
          '"Sang is now red and weighs " & weight'
      
        # There is a global handle into the plugin that
        # allows you to make the same calls that the
        # plugin does, like so...
        dcs = $dc_observers.get_latest_class
        dcs.redraw_with_undo(sang)
      
      }
      

      Thank you.

      posted in Newbie Forum
      B
      blue_orchid
    • Color the component according to dynamic component attribute

      I am new in ruby programming, and I was trying to execute following code in skectchup but it's not working.

      UI.menu("Plugins").add_item('paint Red') {
        model = Sketchup.active_model
        entities = model.entities.to_a
        attr = []
          if e.get_attribute('dynamic_attributes','condition','')=="1"
          attr << e
          end
        entities_def = entities.definition
        
        entities_def.set_attribute 'dynamic_attributes',
          'material', 'red'
        entities_def.set_attribute 'dynamic_attributes',
          '_material_formula', '"red"'
         
        dcs = $dc_observers.get_latest_class
        dcs.redraw_with_undo(entities)
      }
      

      What I was trying to do is -
      I have many components in sketchup model. All those components have dynamic attributes 'material' and 'condition'. I was trying to assign material color "red" to all the component with attribute condition = 1.

      I took help to write above code from following link:
      http://forums.sketchucation.com/viewtopic.php?f=180&t=24241&p=331242&hilit=select+object+as+per+attribute#p331242

      posted in Newbie Forum sketchup
      B
      blue_orchid
    • 1
    • 2
    • 2 / 2