sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Drop-Down List Options

    Scheduled Pinned Locked Moved Developers' Forum
    18 Posts 3 Posters 1.1k Views 3 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.
    • pingpinkP Offline
      pingpink
      last edited by

      Hi everyone ,

       I'm designing a web dialog which contains a drop-down list for creating each layer depending on scheme options. First of all , a user has to select model then pick one of options , and it will put a model into 3 layers. I did this function already and load the def name outside a main program. But I don't understand about how to send data from ruby to html. How can I link option value ?
      
       Many thanks !
      
       Here is in html
      
           Scheme ; 
                    <select name="SchemeLayer" id="SchemeLayer">
                    <option value="No_Scheme">-No-</option>
                    <option value="Scheme_A" >Scheme-A</option> 
                    <option value="Scheme_B">Scheme-B</option>
                    <option value="Scheme_C">Scheme-C</option>
                     
                  </select>
      
       This is in a ruby file 
      
      def myprogram_arch()
      
      my_caption = "CA;Main Program"
      
      wdarch = UI;;WebDialog.new(my_caption, false, my_caption, 200, 200, 200, 200, true)
      
      
      wdarch.add_action_callback('get_data') do | web_dialogarch,action_name |  
      
      
      		#==========================#
      		#   Add Layers of Schemes  #
      		#==========================#
      	
      		if  value = web_dialogarch.get_element_value("SchemeLayer")
      		
      	             puts create_scheme_A # Def function is called outside from an external file.
      		  
      		end
      		   UI.messagebox "Layer created..."
      end
         
      wdarch.set_file($html_patharch)
      wdarch.show()#####################################
      
      return wdarch
      end
      

      A5 copy.jpg

      1 Reply Last reply Reply Quote 0
      • jolranJ Offline
        jolran
        last edited by

        Hi. Some ideas while you are waiting..

        First off, do not use global variables. It will wreck yours and other peoples code in the longrun. Everyone here recommends not to.
        You can substitute it with an instancevariable@ in your module if you need wider scope, or pass variables around as arguments.

        Also all you need to know, really is in here:

        Link Preview Image
        GitHub - thomthom/sketchup-webdialogs-the-lost-manual: Collection of unofficial documentation of SketchUp's WebDialog class.

        Collection of unofficial documentation of SketchUp's WebDialog class. - thomthom/sketchup-webdialogs-the-lost-manual

        favicon

        GitHub (github.com)

        If you only need the values from html select option, I'm not sure you even
        need to do a callback from Javascript ? It's good if you can avoid it, actually..
        Anyway you havent provided any Javascript so we can't see the callback. A la window.location etc..

        If you use @wdarch = UI::WebDialog.new + (your dialog options)

        You can now reach the dialog in other methods in that module, (unless you have different classes that you havent provided here).

        Then you can cache the value like this for ex : myvalue = @wdarch.get_element_value("SchemeLayer")
        And in your case you should get current selected option in <select>.

        edit: Hey wait! Are you asking how to send values from ruby to html select options ?
        (it doesent look like it since you've hardcoded the options...)
        BTW what is your variable value ?
        You are assigning with an if statement πŸ˜•
        you probably meant to do:

        
        my_value = web_dialogarch.get_element_value("SchemeLayer")
        if my_value == "Scheme_A"
          puts create_scheme_A 
          UI.messagebox "Layer created..." 
        end 
        
        
        
        
        
        
        
        
        1 Reply Last reply Reply Quote 0
        • pingpinkP Offline
          pingpink
          last edited by

          Thank you very much Jolran , You are very nice guy ! I learnt from you.
          This is one part of a web dialog.
          After reading your suggestions , I revised my code and added a button 'Select' besides
          a drop-down list. Now it works very okay.

          The process :

          1. Select model entities
          2. Select Scheme option
          3. Click Button " Select "
            Then the model entities will be classified for the Scheme Layers.
          require 'sketchup.rb'
          
          load 'CA/rb/00_Scheme/Create-Layers.rb'
          load 'CA/rb/00_Scheme/Design-Change.rb'
          
          module Architectural
          
          def self.read_data1(web_dialog)
              js_command = "Shell('send from ruby')"
              web_dialog.execute_script(js_command)
          end
          
          
          $html_patharch = Sketchup.find_support_file "CA/html/index_Architectural.html", "Plugins"
          $my_dialogarch = nil
          
          def self.show_hide_program() # << This is a method not to show a web dialog when open a program every time.
          
          	if $my_dialogarch&&$my_dialogarch.visible?
          		$my_dialogarch.close()
          		 $my_dialogarch= nil
          	else
          		$my_dialogarch = myprogram_arch()
          	end
          end
          
          
          def self.myprogram_arch()
          
          my_caption = "CA;Main Program"
          
          wdarch = UI;;WebDialog.new(my_caption, false, my_caption, 200, 200, 200, 200, true)
          
          wdarch.add_action_callback('get_data') do | web_dialog,action_name |  
          
          		#==========================#
          		#   Add Layers of Schemes  #
          		#==========================#
          		
          		
          		my_value = web_dialog.get_element_value("SchemeLayer")
          		if my_value == "Scheme_A" && action_name=="Select"
          		create_scheme_A 
          		UI.messagebox "Layers created for Scheme-A..." 
          		
          		elsif my_value == "Scheme_B" && action_name=="Select"
          		create_scheme_B 
          		UI.messagebox "Layers created for Scheme-B..." 
          		
          		elsif my_value == "Scheme_C" && action_name=="Select"
          		create_scheme_C 
          		UI.messagebox "Layers created for Scheme-C..."
          
          		#==========================#
          		#   Design Change          #
          		#==========================#
          
          		elsif  action_name=="set"
          			ApplyTo.new.getDef 
          		
          
          			
          		else   action_name=="get"
          			ApplyTo.new.applyDef 
          		
          	
          		end
          
          end
             
          wdarch.set_file($html_patharch)
          wdarch.show()#####################################
          
          return wdarch
          end
          
          # Add things to the Plugins menu
          
          unless file_loaded?( "CA_MainProgram.rb" )
          	UI.menu( "Plugins" ).add_item( "CA_Main" ) { Architectural;;myprogram_arch()}
          	file_loaded( "CA_MainProgram.rb" )
          end
          
          end # module
          
          

          layers.jpg


          Scheme.jpg

          1 Reply Last reply Reply Quote 0
          • jolranJ Offline
            jolran
            last edited by

            Well if it works very okay, I guess you are satisfied ?

            I suppose ApplyTo is a class and thats why you using $globals ?
            Otherwise you could simply switch to @instance varibles to avoid future conflicts with other programs.
            There are some other issues but difficult to target without your JS and not related to your posed questions/problems.
            Or maybe your just using onclick event in the html button tag ?
            Like you mentioned, I suppose this part of a bigger code.

            1 Reply Last reply Reply Quote 0
            • pingpinkP Offline
              pingpink
              last edited by

              Thank you so much for guiding me , Jolran ! I'm not specialized in Ruby. I try to learn.

              Yes , ApplyTo is a class linking from other codes.

              I used $globals because I studied the example from a keycuts_popper.rb

              After reading your explanations , I thought about before codes.I had to change $globals name every time due to its conflict and when I click my other Icon on a toolbar to open a web dialog , it doesn't run. Now I come back to change @instance instead of $globals as you said.It's true.

              @html_path = Sketchup.find_support_file "CA_Architect/html/index_Architectural.html", "Plugins"
              @my_dialog = nil
              
              def self.show_hide_program() # << This is a method not to show a webdialog when open a program every time.
              
              	if @my_dialog&&@my_dialog.visible?
              		@my_dialog.close()
              		 @my_dialog = nil
              	else
              		@my_dialog = myprogram_arch()
              	end
              end
              

              In my html , I pasted the reference code on the top :

                /*send action to sketchup ruby*/
                function callRuby(actionName) {
                         query = 'skp;get_data@' + actionName;
                         window.location.href = query;
                }
                /*get action from sketchup ruby*/
                function passFromRubyToJavascript1(value) {
                     var message = "You have " + value + " items selected.";
                     document.getElementById('output').innerHTML = message;
                }
              /* 
              

              On the "Select" button , I have onclick event. It's link to the above reference code :

              <input type="button" onclick="callRuby('Select')" value="Select" />
              
              1 Reply Last reply Reply Quote 0
              • jolranJ Offline
                jolran
                last edited by

                @unknownuser said:

                Thank you so much for guiding me , Jolran ! I'm not specialized in Ruby. I try to learn.

                I'm certainly no Pro in Ruby either, there are other "gurus" around here that have more insight in this. But I'll try to help you as best as I can. πŸ˜„
                Let's see..

                Ah, ok ApplyTo is a class, and I guess now when you changed to @instancevaribles instead of global varibles they don't reach inside the class ?

                A Little sidenote: If you need a Hash for example that needs to travel through classes you can use a Constant inside the module. Like:
                MYHASH = {:key => value }
                But you can(should) not assign it again like [/i]MYHASH = {:someotherkey => othervalue }
                [i]in another place. But use hash methods on the object.
                It's pretty new stuff for me, so I'm not 100% sure about this method's pros and cons yet..

                But if I understand you correctly the problem right now is that the webdialog doesent launch when hitting the Icon in SU ?
                The code you have attached this post does not adress this problem, unless it is almost the same as before...

                What is the myprogram_arch() ? UI::WebDialog.new ?

                EDIT: ok you posted it earlier. It is the webdialog.
                Perhaps with some more code I could assist better..

                1 Reply Last reply Reply Quote 0
                • pingpinkP Offline
                  pingpink
                  last edited by

                  ApplyTo.new.getDef , There's no problem since It is called the Class and function from outside file. About the hash , it's very interesting. I will try it later.

                  My Icon buttons on the Toolbar can launch the WebDialogs when click them.
                  
                  Correct , myprogram_arch() is the WebDialog.
                  
                  But , now I've got some issues for selecting 2 options of component's color (frame colors) , and a face's color (glass colors). I test the webdialog , I want to select 2 options in one time , but it changes only component's color. If I want to change face color , I have to reset the frame colors to be -No-. 
                  
                  How can I set the Values ?
                  
                   
                  
                  		#==========================#
                  		#     Value Variables	   #
                  		#==========================#
                  		
                  		my_value = web_dialog.get_element_value("SchemeLayer")
                  		
                  		frame_color_value = web_dialog.get_element_value("Frame_Colors")
                  		
                  		glass_color_value = web_dialog.get_element_value("Glass_Colors")
                  		
                  		#==========================#
                  		#   Add Layers of Schemes  #
                  		#==========================#
                  
                  		
                  		if my_value == "Scheme_A" && action_name=="Select"
                  		create_scheme_A 
                  		UI.messagebox "Layers created for Scheme-A...?", MB_YESNO
                  		UI.play_sound "Plugins/CA/sound/fins__button.wav"
                  		
                  		elsif my_value == "Scheme_B" && action_name=="Select"
                  		create_scheme_B 
                  		UI.messagebox "Layers created for Scheme-B...?", MB_YESNO
                  		UI.play_sound "Plugins/CA/sound/fins__button.wav"
                  		
                  		elsif my_value == "Scheme_C" && action_name=="Select"
                  		create_scheme_C 
                  		UI.messagebox "Layers created for Scheme-C...?", MB_YESNO
                  		UI.play_sound "Plugins/CA/sound/fins__button.wav"
                  		
                  		#==========================#
                  		#      3D Modeling         #
                  		#==========================#
                  		
                  		#  Aluminium Color Selections	
                  		
                  		elsif frame_color_value == "Clear" && action_name=="Create"
                  		al_Light_Satin
                  		
                  		#  Glass Color Selections	  
                  
                  		elsif glass_color_value == "Clear" && action_name=="Create"
                  		clear
                         
                  
                  
                      
                  
                  

                  options.jpg


                  Comp.jpg

                  1 Reply Last reply Reply Quote 0
                  • jolranJ Offline
                    jolran
                    last edited by

                    @unknownuser said:

                    but it changes only component's color. If I want to change face color , I have to reset the frame colors to

                    I don't understand. Do you have a method that grabs the face material from the Component ?
                    You have to be specific when targeting the face materials.

                    In you code you have: if frame_color_value == "Clear"
                    or glass_color_value == "Clear"
                    Then do al_Light_Satin or clearmethod(?)
                    (You have to rename clear method. It's is reserved Ruby method.)
                    That might cause conflicts in your code..
                    Edit: actually it's Array.clear. But still, might be a sketchy name for a varible.

                    BTW are you on MAC ?

                    I see your targeting 2 "action_name" which I reckon is 2 callbacks with
                    window.location.href = etc ?

                    If you are shooting 2 callbacks directly after each other you might have issues with
                    one callback not being executed.

                    Further Reading:
                    https://github.com/thomthom/sketchup-webdialogs-the-lost-manual/wiki/Asynchronous-versus-Synchronous-Communication

                    Anyway. This will not help you much but I put your code in a case statement.
                    Less comparisons and might be a little easier to read.
                    Don't know if it will work with your code since I don't have the whole lot, but you can try and improve on it. Just a start.
                    Sorry I can't be of more help, but I do not understand what you are trying to achieve, and what your problems are in the code.

                    if action_name == "Select"
                    	case my_value 
                    	when "Scheme_A"
                    		create_scheme_A 
                    		UI.messagebox "Layers created for Scheme-A...?", MB_YESNO
                    		UI.play_sound "Plugins/CA/sound/fins__button.wav"
                          
                    	when "Scheme_B" 
                    		create_scheme_B 
                    		UI.messagebox "Layers created for Scheme-B...?", MB_YESNO
                    		UI.play_sound "Plugins/CA/sound/fins__button.wav"
                          
                    	when "Scheme_C" 
                    		create_scheme_C 
                    		UI.messagebox "Layers created for Scheme-C...?", MB_YESNO
                    		UI.play_sound "Plugins/CA/sound/fins__button.wav"
                    	end
                    elsif action_name == "Create"       
                    	if frame_color_value == "Clear" #  Aluminium Color Selections 
                    		al_Light_Satin
                    		
                    	elsif glass_color_value == "Clear" #  Glass Color Selections 
                    		al_clear_color # ?! renamed this variable...
                    	end
                    end
                    
                    1 Reply Last reply Reply Quote 0
                    • jolranJ Offline
                      jolran
                      last edited by

                      Hi pingpink.

                      Woff!! That's a lot of code to debugg!
                      I don't have the time to go through the whole plugin. But if you can pinpoint down where to look more precisely, it might be easier to help for me or someone else.

                      Tried your plugin and indeed nothing happends when "create-model" button is pressed.

                      I'll have a better peek this evening..

                      Edit: Well I can tell you one thing straight away.
                      On line 135 and forwards in CurtainWallMainprogram.rb you have an "end" in a set of set conditions. And then continue next conditions with "elseif". I suppose you could change elsif action_name=="set" to if action_name=="set" as a quick solution. That whole condition statement-set need some cleaning up..

                      Edit: BTW is the HTML created with a WYSIWYG editor or Visual studio by a chance ?
                      There's a lot of inline code going on, makes the HTML quite hard to read..
                      Don't Think I have the capacity nor time to debugg all that now.

                      <ul> are a little easier to deal with than <tr>, but you've already taken that route, so..

                      1 Reply Last reply Reply Quote 0
                      • pingpinkP Offline
                        pingpink
                        last edited by

                        Thanks ! I should tell you about the background of this project.

                        I'm an architect , and designing a plugin which studied from the process of architects and facade designers.

                        This plugin is for architect's use when doing a schematic design , so we must have to redesign until clients like , then submit 3D model to the facade designers to do material take-off. Thus , we have to do 3D modeling as a real name of component's structure - The mullion and transom with designer's options to have no-cap or cap's features from the lists.
                        I studied from aluminium catalogs from many companies , and summarized that the plugin can contained these kinds of aluminium's style.I created lots of components for the mullion and transom in 1 meter high , saved in a component's file , but I can't share because it's a big file.

                        In Curtain Wall Modeling is the main part that I'm thinking what procedure should I do.
                        I want the process to be :

                        1. Architect provides " Patterned Model data - edges and faces "

                        2. The webdialog have to be defined and then convert pattern faces into 3D model which load components- mullion and transom from my data. But , in the theory , the mullion ( vertical ) can have 90 degrees or random degrees of edge , and the transom ( horizontal ) is 0 degree of edge. I'm still finding the way to solve for many months.I can't find the solution for now. The code is "Place-Face.rb" in a "rb/02_Profile".

                          OR Do I have to select edges manually by users and decide which ones should be mullions or transoms ?. Then the program will load from the selection edges. And apply colors for components and faces later ?.

                          The webdialog now is a test , suppose I created components for aluminium frames and faces for glasses. I choose only 2 selections for now , but it change the color sometimes component's color , and sometimes face's colors , linking from Def- "rb/02_Profile/AluColor" and "rb/01_Glass/GlassColor". If a plugin can change the color in one time , it would be nice.

                          The HTML created with Dreamweaver , I do graphic design and code in it.
                          I just know from you about WYSIWYG editor,never used it before.
                          The Visual studio , I learnt in the past for a basic programming in C#.

                        1 Reply Last reply Reply Quote 0
                        • jolranJ Offline
                          jolran
                          last edited by

                          Thanks for the background explaination, it helps to know the idea behind the code.
                          Sounds interesting.

                          @unknownuser said:

                          1. Architect provides " Patterned Model data - edges and faces "

                          Not sure I understand that. Are you going to use external data or is this going to be drawn in SU ?

                          @unknownuser said:

                          convert pattern faces into 3D model which load components- mullion and transom from my data. But , in the theory , the mullion ( vertical ) can have 90 degrees or random degrees of edge

                          Sounds a little like you are overcomplicating things?
                          Why not just let user select a Square face. Then get face.bounds dimensions (width and height) and just scale the Component to fit.
                          Insert the Component at face.center aligned to face.
                          Assuming your Component is created flat at ORIGIN, to get aligned to face:

                          path = File.join(File.dirname(__FILE__), "mypluginfolder/mycomp.skp") #No need to dig into C;
                          mydefinition = Sketchup.active_model.definitions.load(path)
                          gp = Sketchup.active_model.entities.add_group() # Container group. Not a must..
                          tr = Geom;;Transformation.new(ORIGIN, user_face.normal) #face selected by user
                          inst = gp.entities.add_instance(mydefinition, tr)
                          

                          You can get the scalingfactor for width:

                          scalefactorW = face.bounds.width/inst.bounds.width #(simplified, needs some laboring)
                          

                          and then scale the Component in the correct axis(X or Y).
                          You will have to calculate and scale X & Y individually.
                          Use DC's to avoid stretching of Components, although quite more unstable to use in code/refresh.

                          In case of you want different mullions they can be inserted this way also, aligned to Component. And then grouped together.
                          If you want to rotate Components you should do that at ORIGIN before scaling.
                          And probably rotate inst.entities and refresh bounds with: inst.invalidate_bounds.
                          After doing something like that you will have to update all info regarding bounds properties.

                          Otherwise, if you want to create 1 solid geometry from scratch you have a lot of work to do!
                          It's a combination of Windowizer, Profilebuilder and some more plugins. 😲

                          Theese are just some ideas, I might have missunderstood the goal of your project so do not get discouraged if this is not what you expected as answer.
                          I'll be happy to help more, if it does not take tooo much of my time πŸ˜„

                          Regarding the Webdialog.
                          Dreamweaver IS a WYSIWYG editor.(what-you-see-is-what-you-get-editor)
                          Sometimes they give a little to much inline code(code in tags), and that make the HTML hard to work with. You'll notice when you start working more with Javascript.
                          I did post this question some time ago:
                          http://sketchucation.com/forums/viewtopic.php?f=180&t=37745&p=333644&hilit=wysiwyg#p333644

                          You dialog looks very nice though!

                          I use Jquery to facilitate JS. You don't have to, but it takes care of things that might need advanced knowledge of JS to handle. Like onload.events.
                          Jquery also makes selecting elements and setting/getting values simpler.
                          If you go the Jquery route have a look at Thomthoms code library. He uses Jquery a lot.
                          Some of Aerilius plugins use Javascript without Jquery, which also could be used as an inspiration.
                          They have some quite advanced code in them so it might be better to look elsewhere first.
                          I don't know your knowledge of JavaScript actually.. πŸ˜•

                          1 Reply Last reply Reply Quote 0
                          • pingpinkP Offline
                            pingpink
                            last edited by

                            Hi , Jolran

                             Patterned Model Data-edges and faces , the users have to create and draw by SU.
                             
                             I agree with you now. This idea is complicated to do.
                            
                             And when I read you idea , I can picture about it. Thus , I try to test for a square face I want the width to be transom(horizontal) , and the height to be mullion(vertical). That I can load the each type of components on face.bounds.
                            
                             I did a code from your suggestions by steps. 
                            
                             1. Find face.bounds dimensions - Width and Height
                             2. Conditions before doing load component
                             3. Rotate origin Axis at the start position
                             4. Scaling length
                            
                             I'm not sure how to compare in conditions
                            

                            for loading components around a face.I have a basic of programming.I have been trying to load " Face.load_comp " in a ruby console but it has an error.

                             Thanks for recommending about WYSIWYG editor , I will gradually look about it. I use a free code editor of NotePad ++. 
                            

                            TYPE IN A CONSOLE

                            Face.load_comp

                            require 'sketchup.rb'
                            
                            module Face
                            
                            	def self.load_comp
                            	
                            	        $stdout.write("START-FUNC; Face.load_comp();\n") 
                            				mod = Sketchup.active_model 
                            				sel = mod.selection 
                            				ents = mod.active_entities 
                            			# Grab all the selected faces. 
                            				faces = sel.each{|e| e.typename=='Face'} 
                            			if faces == 0; 
                            				UI.messagebox("Must select at least one face!") 
                                        return 
                                    end 
                                    $stdout.write(" FOR-EACH(face);\n") 
                                    faces.each do |face| 
                                        $stdout.write("  #{face}\n")
                            
                            			    face = face.bounds
                            				puts "Transom = #{face.width.inspect}"
                            				puts "Mullion = #{face.depth.inspect}"
                            
                            		end
                            
                            #=begin		
                            		if 	puts "Transom = #{face.width.inspect}" # for the width , top and buttom
                            	
                            			path = Sketchup.find_support_file "CurtainWall_Architect/Components/00_No_Cap/C-50/Transom/T50X193.2_No-Cap.skp", "Plugins"
                            			#path = File.join(File.dirname(__FILE__), "CurtainWall_Architect/Components/00_No_Cap/C-50/Mullion/T50X193.2_No-Cap.skp") #No need to dig into C;
                            				
                            			mydefinition = Sketchup.active_model.definitions.load(path)
                            			gp = Sketchup.active_model.entities.add_group() # Container group. Not a must..
                            			#tr = Geom;;Transformation.new(ORIGIN, user_face.normal) #face selected by user
                            
                            			inst = gp.entities.add_instance(mydefinition, tr)
                            	
                            			scalefactorW = face.bounds.width/inst.bounds.width #(simplified, needs some laboring)
                            			
                            			tr = Geom;;Transformation.new(ORIGIN,face.normal) #face selected by user
                            
                            			tr = tr*Geom;;Transformation.rotation(ORIGIN, X_AXIS, self.xrotation)
                            
                            			position = entity.transformation.to_a
                            		
                            			pt = edge.start.position
                            
                            			tr = Geom;;Transformation.scaling pt, 1.0, 1.0, xscale
                            
                            			entity.transform!( tr )
                            			# invalidate the view to see the move action
                            			#Sketchup.active_model.active_view.invalidate
                            			
                            			inst.invalidate_bounds
                            			
                            		else puts "Mullion = #{face.depth.inspect}"# for the height of left and right sides
                            		
                            			path = Sketchup.find_support_file "CurtainWall_Architect/Components/00_No_Cap/C-50/Mullion/M50X230.5_No-Cap.skp", "Plugins"
                            			#path = File.join(File.dirname(__FILE__), "CurtainWall_Architect/Components/00_No_Cap/C-50/Mullion/M50X230.5_No-Cap.skp") #No need to dig into C;
                            				
                            			mydefinition = Sketchup.active_model.definitions.load(path)
                            			gp = Sketchup.active_model.entities.add_group() # Container group. Not a must..
                            			#tr = Geom;;Transformation.new(ORIGIN, user_face.normal) #face selected by user
                            
                            			inst = gp.entities.add_instance(mydefinition, tr)
                            	
                            			scalefactorD = face.bounds.depth/inst.bounds.depth #(simplified, needs some laboring)
                            	
                            			tr = Geom;;Transformation.new(ORIGIN,face.normal) #face selected by user
                            
                            			tr = tr*Geom;;Transformation.rotation(ORIGIN, Z_AXIS, self.zrotation)
                            		
                            			position = entity.transformation.to_a
                            
                            			pt = edge.start.position
                            
                            			tr = Geom;;Transformation.scaling pt, 1.0, 1.0, zscale
                            	
                            		
                            			entity.transform!( tr )
                            			# invalidate the view to see the move action
                            			# Sketchup.active_model.active_view.invalidate
                            			
                            			inst.invalidate_bounds
                            
                            			end 
                            			
                            	return Geom;;Transformation.new(tr)
                            #=end
                            
                                    $stdout.write("END-FUNC; load_comp\n")
                                end # def
                            
                            end # module
                            
                            1 Reply Last reply Reply Quote 0
                            • jolranJ Offline
                              jolran
                              last edited by

                              I'll have a peek later, unless someone else have some insights..

                              1 Reply Last reply Reply Quote 0
                              • jolranJ Offline
                                jolran
                                last edited by

                                Ok... Hmm, where do I start, I really feel someone more experienced programmer could dig in and help here.

                                Anyway, I think you have to get back to basics first before dealing with the details, cause are some very basic errors in the conditions you are making.

                                In an if condition there must be a comparison, or a question asked(simply put).
                                The answer should be true or false. And depending on that execute whatever is in the statement. You are doing a puts! Don't Think you'll get a proper answer from that...

                                It looks like you are assigning variables here and there that don't relate to each other.
                                I think I understand what you are trying to do, but don't see the link to the rest of the program.

                                Here's a Quick gobbleup. Don't have time for more right now.
                                Maybe it can give you a few ideas, and you have something to test.
                                You may have to do some tests if using components inside containergroup how transformations and scaling is affecting eachother. I can't remember exactly in which order things go, and havent tested this code..

                                require 'sketchup.rb'
                                
                                module Fitcomponent
                                
                                   def self.load_comp(comp_in, xrotation) # self.xrotation ? better add as argument
                                   
                                		#$stdout.write("START-FUNC; Face.load_comp();\n") 
                                		mod  = Sketchup.active_model 
                                		sel  = mod.selection 
                                		ents = mod.active_entities 
                                		if sel.empty?
                                            UI.messagebox("Must select at least one face!") 
                                            return nil
                                        else
                                			faces = sel.grep(Sketchup;;Face) # Grab all the selected faces. 
                                		end
                                        #$stdout.write(" FOR-EACH(face);\n") 
                                		
                                		#You only should use one face for this if running the plugin 1 face at a time. Otherwise you have to doing some additional coding-
                                		#Make it work with one face first! Then add code...
                                       
                                	   #$stdout.write("  #{face}\n") # I don't know what this doea, so you have to fix it yourself.
                                		
                                		#Depending on the position of the face this is not always accurate! If that is so you have to come up with a method that mesures face accurately. 
                                		face_width = faces[0].bounds.width;   # puts "Transom = #{face_width.inspect}" #debugg
                                		face_height = faces[0].bounds.height; # puts "Mullion = #{face_height.inspect}"  #debugg
                                     
                                		path = File.join(File.dirname(__FILE__), "CurtainWall_Architect/Components/#{comp_in}.skp") #if coming from webdialog .skp is probably not included in name ?
                                		mydefinition = Sketchup.active_model.definitions.load(path)
                                		tr = Geom;;Transformation.new(ORIGIN, user_face.normal) #face selected by user
                                		gp = ents.add_group() # Container group. Not a must..
                                		inst = gp.entities.add_instance(mydefinition, tr)
                                		
                                		#Do the rotation before getting width and height..
                                		tr1 = Geom;;Transformation.rotation(ORIGIN, Z_AXIS, xrotation) #xrotation from argumentlist
                                		inst.entities.transform_entities(tr1, inst.entities.to_a)
                                		inst.invalidate_bounds
                                		
                                		#Now cache the width and height of instance
                                		inst_width  = inst.bounds.width
                                		inst_height = inst.bounds.height
                                		
                                		scalefactorW = face_width/inst_width #(simplified, needs some laboring)
                                		scalefactorH = face_height/inst_height #(simplified, needs some laboring)
                                         
                                		#Scale the component..
                                		tr2 = Geom;;Transformation.scaling(ORIGIN, scalefactorW, scalefactorH, 1) #X,Y,Z  
                                		inst.transform!( tr2 )
                                		
                                		#Assuming you have created and saved the component at Origin with faces up in Z_AXIS flat on ground..
                                		tr3 = Geom;;Transformation.new(ORIGIN, faces[0].normal) #face selected by user
                                		gp.transform!( tr3 ) # In case you need to add different Components, do this manouver last.
                                		
                                	end # load_comp
                                
                                end # module 
                                
                                1 Reply Last reply Reply Quote 0
                                • pingpinkP Offline
                                  pingpink
                                  last edited by

                                  Thank you very much ,Jolran !!! I've tested the codes. There is still having an error about variable of 'xrotation'. I will try all my effort to solve the codes to link my component's folder which I've created 1 meter upright at the axis (0,0,0). This is my first plugin to do from the user's requirement. You are the first person who understand my project and give me an advice in here. I am much appreciated your ideas !. I can bring to sketch my flowcharts. If I can do the codes, I will inform you later. The big task of coding is waiting for me.I'm fighting πŸ’š

                                  1 Reply Last reply Reply Quote 0
                                  • jolranJ Offline
                                    jolran
                                    last edited by

                                    I did not give you such an advanced answer, but glad if it could give you a push in the right direction πŸ˜„

                                    About the 'xrotation', make sure that it is not a string coming from webdialog. You need an integer in your case(90 degrees). Ruby cannot calculate rotation-amount from a string.
                                    So, xrotation = webdialog_string.to_i might do it.
                                    Also be vary about rotations in SU. API internally uses Radians to calculate rotations. So you might have to fiddle some with .radians or .degrees for xrotation.

                                    There's some info on Thomsthoms blogg regarding stringconversion to Sketchup units.
                                    I'd suggest you read that.

                                    Keep fighting and don't give up!

                                    1 Reply Last reply Reply Quote 0
                                    • thomthomT Offline
                                      thomthom
                                      last edited by

                                      @jolran said:

                                      There's some info on Thomsthoms blogg regarding stringconversion to Sketchup units.
                                      I'd suggest you read that.

                                      Link to article: http://www.thomthom.net/thoughts/2012/08/dealing-with-units-in-sketchup/

                                      Thomas Thomassen β€” SketchUp Monkey & Coding addict
                                      List of my plugins and link to the CookieWare fund

                                      1 Reply Last reply Reply Quote 0
                                      • pingpinkP Offline
                                        pingpink
                                        last edited by

                                        Maybe,the problem is about the component , and face color functions . I did it separately in the external files. My webdialog have to be chosen all options and run by clicking. I'm trying to develop the curtain wall structure modeling .I'm not finished all the codes yet.

                                        I use Window , and SU7 to test a program.

                                        I changed all the color_value names which you suggest it would cause the conflict about component's color and face's color. It's looked easier in the code. I've attached the files for you If you would like too see. And If you have any suggestions , I love to read for improvement.

                                        Thank you for helping and teaching me ,Jolran .I keep doing codes every day.I'm trying !
                                        
                                        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