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

    SketchUp crashing on me with this code...why?

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 4 Posters 353 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.
    • renderizaR Offline
      renderiza
      last edited by

      Hi, here is part of a test I am doing to see if I can get Animatex Plugin to animate multiple faces but SketchUp keep crashing on me. Any particular reason why this happening so I can fix it?...thanks!

      If you don't know what Animatex is here is a link.... http://sketchucation.com/forums/viewtopic.php?f=323&t=52238

      One quick note is the def push_frame(dialog,data) is being updated couple frames a second by the web dialog.

      def push_frame(dialog,data)
      				
      			params = query_to_hash(data) ;  # parse state information 
      			
      			if @animate == true
      			
      		
      					
      				model = Sketchup.active_model
      				ents = model.entities 
      			
      
      				faces = []
      
      
      				ents.each do |e|
      
      					if e.is_a? Sketchup;;Face
      							faces << e 
      					end
      				end
      				
      			
      
      				faces.each do |e|
      
      					mat = e.material
      
      					pt_array = []
      					pt_array[0] = Geom;;Point3d.new(@speed_x,@speed_y,0)
      					pt_array[1] = Geom;;Point3d.new(0,0,0)
      					on_front = true
      					
      					e.position_material mat, pt_array, on_front
      										  
      				end 	
      
      							
      		
      				
      			end
      
      end
      
      

      Any help will be welcome! πŸ‘

      [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

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

        I don't see how I can reproduce anything from this code. Got a complete case for testing?


        Sidenote:

        You indentation appear inconsistent. I'd recommend you keep it consistent with something like 2 or 4 space indentation. Makes it easier to read and debug.

        if @animate == true this doesn't need to be so verbose, You can do just if @animate

        ents = model.entities is that really the context you want to change? Not ents = model.active_entities in case the user opens a group/component. Maybe your crash is related to modifications in the wrong context?

        faces = []
        ents.each do |e|
          if e.is_a? Sketchup;;Face
            faces << e
          end
        end
        

        This is be simplified, and made faster by:

        faces = ents.grep(Sketchup;;Face)
        

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

        1 Reply Last reply Reply Quote 0
        • renderizaR Offline
          renderiza
          last edited by

          Hi,

          There is an attachment with a more complete code but it is still a test code...for example the @speed_x is not increasing in number yet.

          test.rbz

          Note: I am using Notepad++ and for indenting space I use tab but for some reason when I copy & paste code from there to forum it looks like that.

          Again thanks thomthom!

          [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

          1 Reply Last reply Reply Quote 0
          • TIGT Online
            TIG Moderator
            last edited by

            What are @speed_x and @speed_y - if these aren't 'numbers' it'll cause issues.
            Perhaps trap at the code's start up with something like
            @speed_x = 0 unless @speed_x @speed_y = 0 unless @speed_y
            etc...

            Also you should trap that the two points used in the positioning-points' array are != - with something like this...
            return nil if @speed_x == 0 && @speed_y==0 ### because then pts_array[0]==pts_array[1] pt_array = [Geom::Point3d.new(@speed_x ,@speed_y, 0), Geom::Point3d.new(0, 0, 0)] on_front = true
            Note that you do not need to set the positioning-points' array etc multiple times, because it is always the same - do it outside of the 'faces' loop. Unless you intend to increment @speed_x etc inside the loop, then you need to put it in the loop...

            Also, also you are re-positioning every face's material, but if a face's material is the default-material [ nil] it'll probably throw a wobbler ??
            Try something like this near the start of the 'faces' loop...
            next unless mat = e.material
            to skip over any faces that have no material...

            TIG

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

              Yea, as TIG says, check the values of your code. Output the values and add traps to ensure you are using valid data from start to end.

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

              1 Reply Last reply Reply Quote 0
              • AdamBA Offline
                AdamB
                last edited by

                #position_material is quite brittle and will die if you give it anything but clean parameters.

                If memory serves, it will explode with either zero-area or degenerate geometry.

                Adam

                Developer of LightUp Click for website

                1 Reply Last reply Reply Quote 0
                • renderizaR Offline
                  renderiza
                  last edited by

                  Thanks everyone now SketchUp is not crashing! 😍

                  Here is that bit of code again revised...

                  
                  
                  @speed_x = 0 unless @speed_x
                  @speed_y = 0 unless @speed_y
                  
                  def push_frame(dialog,data)
                  				
                    params = query_to_hash(data) ;  # parse state information 
                  			
                    if @animate
                  					
                      model = Sketchup.active_model
                      ents = model.active_entities
                  				
                      faces = ents.grep(Sketchup;;Face)
                  				
                      faces.each do |e|
                  					
                        next unless mat = e.material
                        mat = e.material
                  					
                        return nil if @speed_x == 0 && @speed_y==0 ### because then pts_array[0]==pts_array[1]
                        pt_array = [Geom;;Point3d.new(@speed_x ,@speed_y, 0), Geom;;Point3d.new(0, 0, 0)]
                        on_front = true
                  						
                        e.position_material mat, pt_array, on_front
                  										  
                      end 	
                  
                    end
                  
                  end
                  
                  

                  Again thanks everyone! πŸ‘

                  [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                  1 Reply Last reply Reply Quote 0
                  • renderizaR Offline
                    renderiza
                    last edited by

                    Hi,

                    Thank you guys so much could not do it without you guys!...Here is the latest update for Animatex; http://sketchucation.com/forums/viewtopic.php?f=323&t=52238

                    There is no scrambler for code so you guys can take a peek and will be grateful if you tell me any inefficiency in code so I can keep learning...cheers! πŸ‘

                    New Web Dialog::

                    http://s23.postimg.org/4i96v6fvf/animatex_dlg.jpg

                    [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                    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