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

    Mixed Up Data

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 4 Posters 298 Views 4 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.
    • s_k_e_t_c_h_yS Offline
      s_k_e_t_c_h_y
      last edited by

      Hi,
      I'm hoping this post works on the principle of 'as soon as I write it down, I work it out'. I have a class that upon being ran create lots of objects (great). If I move the first objects out of the way and run the program again with different settings the output of the second run is the output of the first run PLUS the second run on top of each other!

       If I select all of the objects (CTRL-A) and delete them after run 1 and then run again the same thing happens. Each run of my class seems to sit on the prior run? I assume I'm doing something bad with the namespace or some such.
      
       The project is quite long so it isn't easy to post snippets..
      

      Ideas...?

      Paul.

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

        It sounds like your output is an @varible not being set to nil at start of the program.
        It will store the values in @variable during the Sketchup session.
        Talking @variables in your module scope here, but since you say your having problem with a Class this might not be it.

        1 Reply Last reply Reply Quote 0
        • s_k_e_t_c_h_yS Offline
          s_k_e_t_c_h_y
          last edited by

          Hmm,
          I'm not sure I do that? Here is a cut-down version of what I'm doing. Hopefully I'm not breaking too many good practice rules, but please let me know.

          Basically I have a lot of class variables (all the @@xyz) which have defaults, but get overridden after the HTML configure() has been ran. When configure() is complete is calls draw() then statistics() to implement the customized design in SketchUp. I use blocking threads to initialize these so that the configure has been finished().

          All of my shapes from draw() get pushed into @@geodesic which is a group so that all sub-shapes from the draw are bound together at the end.

          Insight appreciated...

          # Add a menu item to launch our plug-in.
          UI.menu("PlugIns").add_item("Draw Geodesic") {
            
            #Instantiate and configure the Geodesic
            geo = Geodesic.new
            geo.configure()  
          }
          
          class Geodesic
          	#Main Configuration items
          	@@g_frequency = 3
          	@@g_radius = 150
          	@@g_platonic_solid = 20
          	@@g_fraction = 0.6
          	@@g_center = Geom;;Point3d.new ([0, 0, -@@g_radius + 2 * @@g_radius * @@g_fraction])
          	
          	@@draw_primitive_solid_faces = 0
          	@@primitive_face_material = [rand(255), rand(255), rand(255)]
          
          	@@draw_tesselated_faces = 0
          	@@tesselated_face_material = [rand(255), rand(255), rand(255)]
          	
          	#Metal hub configuration
          	@@draw_metal_hubs = 1
          	@@metal_hub_outer_radius = 2.25
          	@@metal_hub_outer_thickness = 0.25
          	@@metal_hub_depth_depth = 4
          
          	#Wood strut configuration
          	@@draw_wood_struts = 1
          	@@wood_strut_dist_from_hub = 3
          	@@wood_strut_thickness = 1.5
          	@@wood_strut_depth = 3.5
          	@@wood_strut_material = Sketchup;;Color.new(255,215,0)
          
          	#Wood frame configuration
          	@@draw_wood_frame = 1
          	@@frame_separation = 12
          	
          	#Dome reference data is stored in these arrays
          	@@geodesic = Sketchup.active_model.entities.add_group		#Main object everything contributes to
          	@@primitive_points = []
          	@@strut_points = []
          	@@triangle_points = []
          	
          	#Dome shape data is stored in these arrays
          	@@strut_hubs = []
          	@@struts = []
          	@@frame_struts = []
          
          	
          	#tolerance factor to circumvent small number errors
          	@@g_tolerance = 0.5
          	
          	#HTML pop-up menu to configure and create the Geodesic Dome
          	def configure
                     # ... code ...
                  end
          
          	def draw
                     # ... code ...
                  end
          
          	def statistics
                     # ... code ...
                  end
          
                  private
          
                  #lots of support functions here
          
          
          

          SIncerely, Paul.

          1 Reply Last reply Reply Quote 0
          • s_k_e_t_c_h_yS Offline
            s_k_e_t_c_h_y
            last edited by

            Hmmm,
            on further reading i appears I misunderstood @@var class variables. Now to correct the whole class....?

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

              You are not forced to use classvariables just because your in a Class 😄

              I think Ruby Monk has some nice and easy reading about this:

              http://rubymonk.com/learning/books/4-ruby-primer-ascent/chapters/45-more-classes/lessons/113-class-variables

              It says :"class variables can be used to store data that belongs to a class, but not to its instances"

              1 Reply Last reply Reply Quote 0
              • S Offline
                slbaumgartner
                last edited by

                @s_k_e_t_c_h_y said:

                Hmm,
                I'm not sure I do that? Here is a cut-down version of what I'm doing. Hopefully I'm not breaking too many good practice rules, but please let me know.

                Basically I have a lot of class variables (all the @@xyz) which have defaults, but get overridden after the HTML configure() has been ran. When configure() is complete is calls draw() then statistics() to implement the customized design in SketchUp. I use blocking threads to initialize these so that the configure has been finished().

                All of my shapes from draw() get pushed into @@geodesic which is a group so that all sub-shapes from the draw are bound together at the end.

                Insight appreciated...

                # Add a menu item to launch our plug-in.
                > UI.menu("PlugIns").add_item("Draw Geodesic") {
                >   
                >   #Instantiate and configure the Geodesic
                >   geo = Geodesic.new
                >   geo.configure()  
                > }
                > 
                > class Geodesic
                > 	#Main Configuration items
                > 	@@g_frequency = 3
                > 	@@g_radius = 150
                > 	@@g_platonic_solid = 20
                > 	@@g_fraction = 0.6
                > 	@@g_center = Geom;;Point3d.new ([0, 0, -@@g_radius + 2 * @@g_radius * @@g_fraction])
                > 	
                > 	@@draw_primitive_solid_faces = 0
                > 	@@primitive_face_material = [rand(255), rand(255), rand(255)]
                > 
                > 	@@draw_tesselated_faces = 0
                > 	@@tesselated_face_material = [rand(255), rand(255), rand(255)]
                > 	
                > 	#Metal hub configuration
                > 	@@draw_metal_hubs = 1
                > 	@@metal_hub_outer_radius = 2.25
                > 	@@metal_hub_outer_thickness = 0.25
                > 	@@metal_hub_depth_depth = 4
                > 
                > 	#Wood strut configuration
                > 	@@draw_wood_struts = 1
                > 	@@wood_strut_dist_from_hub = 3
                > 	@@wood_strut_thickness = 1.5
                > 	@@wood_strut_depth = 3.5
                > 	@@wood_strut_material = Sketchup;;Color.new(255,215,0)
                > 
                > 	#Wood frame configuration
                > 	@@draw_wood_frame = 1
                > 	@@frame_separation = 12
                > 	
                > 	#Dome reference data is stored in these arrays
                > 	@@geodesic = Sketchup.active_model.entities.add_group		#Main object everything contributes to
                > 	@@primitive_points = []
                > 	@@strut_points = []
                > 	@@triangle_points = []
                > 	
                > 	#Dome shape data is stored in these arrays
                > 	@@strut_hubs = []
                > 	@@struts = []
                > 	@@frame_struts = []
                > 
                > 	
                > 	#tolerance factor to circumvent small number errors
                > 	@@g_tolerance = 0.5
                > 	
                > 	#HTML pop-up menu to configure and create the Geodesic Dome
                > 	def configure
                >            # ... code ...
                >         end
                > 
                > 	def draw
                >            # ... code ...
                >         end
                > 
                > 	def statistics
                >            # ... code ...
                >         end
                > 
                >         private
                > 
                >         #lots of support functions here
                > 
                > 
                

                SIncerely, Paul.

                Presumably you build your data in the various arrays @@primitive_points, @@strut_points, @@triangle_points, @@strut_hubs, @@struts, @@frame_struts by appending elements to the arrays. Do you clear out these arrays at the start of configure or draw? If not, because they are class variables the values will continue to accumulate until you close and restart SketchUp.

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  @jolran said:

                  It says :"class variables can be used to store data that belongs to a class, but not to its instances"

                  This is true.

                  ANY or ALL instances of a class (or of a subclass of the class,) can access and change those class variables!

                  The easiest thing to do is search & replace @@ to @ so as making them instance variables.

                  Also your custom class should be within your OWN author module namespace.

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • s_k_e_t_c_h_yS Offline
                    s_k_e_t_c_h_y
                    last edited by

                    Fixed.
                    Thanks Dan for the reminder for the namespace. Namespace now implemented =-P.

                    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