sketchucation logo sketchucation
    • Login
    1. Home
    2. blue_orchid
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    B
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 8
    • Posts 25
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: Display image using Ruby API

      Ya, WebDialog is also fine.

      posted in Developers' Forum
      B
      blue_orchid
    • RE: Display image using Ruby API

      "Directory" means just the folder in your computer.

      What I wanted to do: On clicking dynamic component, image should pop up.

      posted in Developers' Forum
      B
      blue_orchid
    • RE: Display image using Ruby API

      What I wanted to do is display an image after I click the object.

      posted in Developers' Forum
      B
      blue_orchid
    • Display image using Ruby API

      Can anyone tell me how to display an image which is located in other directory using Ruby API in SketchUP?

      posted in Developers' Forum
      B
      blue_orchid
    • Remove color using ruby

      how to remove the material (color) from object using ruby?

      posted in SketchUp Components sketchup
      B
      blue_orchid
    • RE: Color the DC conditioning on its attributes & values (MYSQL

      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.

      posted in Developers' Forum
      B
      blue_orchid
    • RE: Color the DC conditioning on its attributes & values (MYSQL
      UI.menu("Plugins").add_item('Assesment') { Jeny.color }
      require 'mysql'
      module Jeny
          def self.color
      dbh = Mysql.real_connect("localhost", "root", "orange", "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,1),('Substructure',2349,2),('Superstructure',2353,3)")
      
      #printf "%d rows were inserted\n",dbh.affected_rows
      #res = dbh.query("SELECT rating, id FROM inspection")
      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')
      e.set_attribute('dynamic_attributes','rating','xx')
         end
      }
      Sketchup.active_model.entities.to_a.each{|e|
      if e.get_attribute('dynamic_attributes','id','')== "2349"
      e.set_attribute('dynamic_attributes','rating','xy')
      end
      }
      Sketchup.active_model.entities.to_a.each{|e|
      if e.get_attribute('dynamic_attributes','id','') == "2353"
      e.set_attribute('dynamic_attributes','rating','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', 'material', 'red')
           e.set_attribute( 'dynamic_attributes', '_material_formula', '"red"')
           $dc_observers.get_latest_class.redraw_with_undo(e)
      elsif e.get_attribute('dynamic_attributes','id','2345') && xx == "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','id','2349') && xx == "3"
           e.set_attribute( 'dynamic_attributes', 'material', 'green')
           e.set_attribute( 'dynamic_attributes', '_material_formula', '"green"')
           $dc_observers.get_latest_class.redraw_with_undo(e)
           end
           }
      
      Sketchup.active_model.entities.to_a.each{|e|
      if e.get_attribute('dynamic_attributes','id','2349') && xy == "1"
           e.set_attribute( 'dynamic_attributes', 'material', 'red')
           e.set_attribute( 'dynamic_attributes', '_material_formula', '"red"')
           $dc_observers.get_latest_class.redraw_with_undo(e)
      elsif e.get_attribute('dynamic_attributes','id','2349') && xy == "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','id','2349') && xy == "3"
           e.set_attribute( 'dynamic_attributes', 'material', 'green')
           e.set_attribute( 'dynamic_attributes', '_material_formula', '"green"')
           $dc_observers.get_latest_class.redraw_with_undo(e)
      end
           }
      
      Sketchup.active_model.entities.to_a.each{|e|
      if e.get_attribute('dynamic_attributes','id','2353') && yy == "1"
           e.set_attribute( 'dynamic_attributes', 'material', 'red')
           e.set_attribute( 'dynamic_attributes', '_material_formula', '"red"')
           $dc_observers.get_latest_class.redraw_with_undo(e)
      elsif e.get_attribute('dynamic_attributes','id','2353') && yy == "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','id','2353') && yy == "3"
           e.set_attribute( 'dynamic_attributes', 'material', 'green')
           e.set_attribute( 'dynamic_attributes', '_material_formula', '"green"')
           $dc_observers.get_latest_class.redraw_with_undo(e)
                      end
                  }
       
      
      end
      end
      
      
      

      %(#BF4000)[What I did here:
      I set attribute 'rating' for different objects with different names like xx, xy and yy.
      Then I made these attributes 'ratings' equal to result from query for each component/object.
      Finally i selected the color for each component and different values of ratings a color.

      But it still selects only last code i.e. objects color change to green . May be it could not identify the Db values.]
      Now what i want to do that if the rating for a component is 1 in database, then the attribute 'rating' for that component is changed to 1 using DB value. Is it possible?

      posted in Developers' Forum
      B
      blue_orchid
    • RE: Color the DC conditioning on its attributes & values (MYSQL

      i am not at all experienced in any programming language and mysql. Ruby is my first programming language. I have gone through several ruby guide, but still i am having hard time learning it and working on it.

      i am just doing it for a project and i am really having a hard time doing it.

      posted in Developers' Forum
      B
      blue_orchid
    • RE: Color the DC conditioning on its attributes & values (MYSQL

      UI.menu("Plugins").add_item('Assessmenteww') { Jeny.color }

      module Jeny
      def self.color
      require 'mysql'
      dbh = Mysql.real_connect("localhost", "root", "orange", "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,1),('Substructure',2349,2),('Superstructure',2353,3)")
      #printf "%d rows were inserted\n",dbh.affected_rows

      res = dbh.query("SELECT id, rating FROM inspection")
      #while row = res.fetch_row do

      #a=row[0]
      #b=row[1]
      #c=row[2]

      #printf "%s, %s, %s\n", a, b, c
      #end

      #puts a.inspect
      #puts b.inspect
      #puts c.inspect

      Sketchup.active_model.entities.to_a.each{|e|
      this = e.get_attribute('dynamic_attributes','id','') == "2345"
      case this
      when res == '2345' && '1'
      e.material = 'red'
      when res == '2349' && '2'
      e.material == 'green'
      when res == '3'
      e.material == 'blue'
      when '' # empty
      e.material = 'orange'
      else
      e.material = 'yellow'
      end
      }
      end
      end

      
      

      %(#40BF00)[Sketchup.active_model.entities.to_a.each{|e|
      this = e.get_attribute('dynamic_attributes','id','') == "2345"
      case this
      when res == '2345' && '1'
      e.material = 'red'
      when res == '2349' && '2'
      e.material == 'green'
      when res == '3'
      e.material == 'blue'
      when '' # empty
      e.material = 'orange'
      else
      e.material = 'yellow'
      end
      }]

      When I run this script, the component with id '2345' does not change its color, but the other component changes its color to red. Why is this so?

      posted in Developers' Forum
      B
      blue_orchid
    • RE: Color the DC conditioning on its attributes & values (MYSQL

      Dan, I am sorry that I did not understand your question?

      posted in Developers' Forum
      B
      blue_orchid
    • RE: Color the DC conditioning on its attributes & values (MYSQL

      Chris,

      components are colored with ruby script. I did not the paint the component with any color in the sketchup itself.

      I hope i answered your question.

      I also tried the same script in the components which don't have any color. But it didn't work.

      posted in Developers' Forum
      B
      blue_orchid
    • RE: Color the DC conditioning on its attributes & values (MYSQL

      Dan,

      I used the script that you have written.
      No color change in the components.

      posted in Developers' Forum
      B
      blue_orchid
    • RE: Color the DC conditioning on its attributes & values (MYSQL
      while (c=='1'){
      Sketchup.active_model.entities.to_a.each{|e|
      e.get_attribute('dynamic_attributes','id','') == "2345"
              e.material = 'green'
          end}}
      
      

      Dan, I know it's not the correct way to write the code as it failed. I tried.

      posted in Developers' Forum
      B
      blue_orchid
    • RE: Color the DC conditioning on its attributes & values (MYSQL

      @dan rathbun said:

      Jeny, the coloring should go inside your while block that fetches each record from the database.

      Dan, can you show me how to use while block for coloring?

      posted in Developers' Forum
      B
      blue_orchid
    • Color the DC conditioning on its attributes & values (MYSQL
      UI.menu("Plugins").add_item('Assessment') { Jeny.color }
      
      
      module Jeny
          def self.color
      require 'mysql'
      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,1),('Substructure',2349,2),('Superstructure',2353,3)")
      printf "%d rows were inserted\n",dbh.affected_rows
      
      res = dbh.query("SELECT id, rating FROM inspection")
      while row = res.fetch_row do
      
      a=row[0]
      b=row[1]
      c=row[2]
      
      printf "%s, %s, %s\n", a, b, c
      end
      
      puts a.inspect
      puts b.inspect
      puts c.inspect
      
       Sketchup.active_model.entities.to_a.each{|e|
               if e.get_attribute('dynamic_attributes','id','')=="2345"||(b=='2345') || (c=='1')
      then e.material = 'red'
      end
        }
       Sketchup.active_model.entities.to_a.each{|e|
                if e.get_attribute('dynamic_attributes','id','')=="2345"||(b=='2345') || (c=='2')
      then e.material = 'yellow'
      end
        }
       end
      end
      

      In the above code, what I did....
      color the DC
      which has attribute 'ID' = 2345
      b==2345 ( b=id from database)
      c=1(c=rating in database)
      with red color.

      And similarly Dc
      which has attribute 'ID' = 2345
      b==2345 ( b=id from database)
      c=2 (c=rating in database)
      with yellow color.

      Problem is that
      1.it accepts only the last code, so it changes the object to yellow color not to red color.
      .

      I even tried using 'case and when' control structure
      for example
      %(#4000FF)[Sketchup.active_model.entities.to_a.each{|e|
      case e.get_attribute('dynamic_attributes','id','')=="2345"
      when b=='2345' || c=='1'
      then e.material = 'green'
      end }]
      But it didn't work...

      Can anyone tell me what the appropriate control structure is?

      posted in Developers' Forum
      B
      blue_orchid
    • RE: Color components

      It's kind of both.

      The component is assigned 'width' attribute and, also parameter 'width' is pulled out from database.

      I am doing process by process. Right now, i am taking the parameter 'width' from db and coloring each component different colors. Like assigning Component1 with ID 2345 and width 10" a 'red' color, Component2 with ID 2343 and width 12" a 'blue' color and so on......

      posted in Developers' Forum
      B
      blue_orchid
    • RE: Color components

      Thanks to everyone!!!

      What should be the script If I have to add the new parameter like width=='1'? This parameter 'width' is a category from MySQl database.

      Sketchup.active_model.entities.each {|entity|
      if entity.entityID == 2345 and width=='1'
      entity.material = "Blue"
      break
      end
      }

      end
      

      end

      posted in Developers' Forum
      B
      blue_orchid
    • Color components
      ents = Sketchup.active_model.entities[0]
      ents.entityID
      
      Result-2345
      

      Now, I need to assign the color 'red' to this particular component whose entityID is 2345. How should I do it?

      posted in Developers' Forum
      B
      blue_orchid
    • RE: Selection of Dynamic component using ruby

      I just meant that dynamic components have been created in sketchup itself but not with ruby script.

      Can you write the script to select a single DC?

      Thanks for your help!

      posted in Dynamic Components
      B
      blue_orchid
    • Selection of Dynamic component using ruby

      **I need to know how to select the existing dynamic component using ruby.

      Is it same as selection of component?

      Thanks!**

      posted in Dynamic Components sketchup
      B
      blue_orchid
    • 1
    • 2
    • 1 / 2