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

    Mysterious Bug [followme related]

    Scheduled Pinned Locked Moved Developers' Forum
    30 Posts 4 Posters 603 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.
    • C Offline
      Chris88
      last edited by

      @thomthom: Correct. And yes, it crashes if it's located in the plugin-folder, too.
      And it doesn't matter, if i load the script with the Ruby Console or if i start SU normally and the script is in the plugin-folder.

      @Dan: Thanks Dan! I will test it in a few minutes...

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

        I tried the code you posted initially. I get no crash. I did however leave out LineA.create_line so that it would not execute when SU loaded.

        I called the method afterwards in SU.

        Tube.png

        Sidenote - it seems that you create the profile for your shape (the circle) many times. Many small segments for what is in reality one single tube. As you can see- you end up with gaps where the straight sides meets the arced corners.

        You would avoid that by making the tube as you would in SU. Making one single path, and one profile - then using follow me only once for the whole shape.

        Should make a cleaner geometry, be faster and simplify the code.

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

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

          Oh yea - as Dan suggested with his code. several operations should be wrapped in .start_operation - .commit_operation so it produces only one undo step. And if you use the disable_ui argument it should run faster.

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

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

            @thomthom said:

            I tried the code you posted initially. I get no crash. I did however leave out LineA.create_line so that it would not execute when SU loaded.

            Yea, it's dangerous to do stuff during SU load, as all the Google extensions are not yet loaded like Dynamic Components.

            I'm not here much anymore.

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

              maybe a wait timer like this is safer...

                # run when file loads
                #
                if Sketchup.active_model &&
                Sketchup.active_model.active_entities
                  UI.start_timer(0.0, false){ LineA.create_line }
                else
                  LineA;;TIMER = UI.start_timer(2.0, true){
                    if Sketchup.active_model &&
                    Sketchup.active_model.active_entities
                      UI.stop_timer(LineA;;TIMER)
                      LineA.create_line
                    end #if
                  }
                end
              
              

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • C Offline
                Chris88
                last edited by

                @Dan: Thank you. Now my code looks like:

                
                require 'sketchup.rb'
                
                module Chris88
                
                  module LineA
                
                    TIMER = nil
                
                    def self.create_line()
                      # delete lines 1-4 with loop
                      #
                       model = Sketchup.active_model
                       entities = model.active_entities
                #--------------------------------------------------------------------------
                       # Add the group to the entities in the model
                       group = entities.add_group
                       # Get the entities within the group
                       # alle Objekte die den entities2 zugeordnet werden, werden automatisch zu einer gemeinsamen Gruppe gemacht
                       entities2 = group.entities
                      
                      begin
                        model.start_operation( 'LineA' )
                        
                        @width_small = 55 # 55  
                        @depth_small = 45 # 45  
                        @height_small = 30 # 30 
                        @width_big = 70 # 70 
                        @depth_big = 60 # 60
                        @height_big = 70 # 40
                    
                        @height_line = (4/3) * @height_small
                        @radius = 1
                        @arcradius = 3        
                #--------------------------------------------------------------------------   
                        @mat_linie=model.materials.add("Material_Linie")
                        @mat_linie.color=Sketchup;;Color.new(124,252,0)  # => LawnGreen
                #--------------------------------------------------------------------------
                        @anzahl_arcs = ((@depth_small-6)/6).to_i
                    
                        @pts =[]
                        @helpvar_depth = 3
                        @helpvar_pts = 1
                        @helpvar_baseline = 1
                        @helpvar_basearc = 1     
                #--------------------------------------------------------------------------
                       1.upto(@anzahl_arcs) do |x|
                        @helpvar2_pts = @helpvar_pts +1
                #--------------------------------------------------------------------------
                       if (x%2 > 0)
                        @pts[@helpvar_pts] = [((@width_big-@width_small)/2)+5.35, ((@depth_big-@depth_small)/2)+@helpvar_depth, @height_line]
                        @pts[@helpvar_pts+1] = [@width_small+((@width_big-@width_small)/2)-5.3, ((@depth_big-@depth_small)/2)+@helpvar_depth, @height_line]
                        # arc_point
                        @pts[@helpvar_pts+2] = [@width_small+((@width_big-@width_small)/2)-5, ((@depth_big-@depth_small)/2)+(@helpvar_depth+3), @height_line]
                          
                        arc_circle_odd = entities2.add_circle @pts[@helpvar_pts+1], X_AXIS, @radius, 42 
                        arc_circle_face_odd = entities2.add_face arc_circle_odd
                        arc_circle_face_odd.material = @mat_linie
                        arc_circle_face_odd.back_material = @mat_linie
                
                        line_circle_odd = entities2.add_circle @pts[@helpvar_pts], X_AXIS, @radius, 42 
                        line_circle_face_odd = entities2.add_face line_circle_odd
                        line_circle_face_odd.material = @mat_linie
                        line_circle_face_odd.back_material = @mat_linie
                
                        @helpvar_baseline_odd = entities2.add_line @pts[@helpvar_pts], @pts[@helpvar_pts+1]
                
                        @helpvar_basearc_odd = entities2.add_arc @pts[@helpvar_pts+2],[0,-1,0],[0,0,1],@arcradius,-5.degrees,185.degrees 
                        
                        arc_circle_face_odd.followme @helpvar_basearc_odd
                        line_circle_face_odd.followme @helpvar_baseline_odd
                        
                #--------------------------------------------------------------------------
                      elsif (x%2 == 0) 
                        @pts[@helpvar2_pts-1] = [((@width_big-@width_small)/2)+5.3, ((@depth_big-@depth_small)/2)+@helpvar_depth, @height_line]
                        @pts[@helpvar2_pts] = [@width_small+((@width_big-@width_small)/2)-5.35, ((@depth_big-@depth_small)/2)+@helpvar_depth, @height_line]
                        # arc_point
                        @pts[@helpvar2_pts+1] = [((@width_big-@width_small)/2)+5, ((@depth_big-@depth_small)/2)+(@helpvar_depth+3), @height_line]
                              
                        arc_circle_even = entities2.add_circle @pts[@helpvar2_pts-1], X_AXIS, @radius, 42 
                        arc_circle_face_even = entities2.add_face arc_circle_even
                        arc_circle_face_even.material = @mat_linie
                        arc_circle_face_even.back_material = @mat_linie
                        
                        line_circle_even = entities2.add_circle @pts[@helpvar2_pts], X_AXIS, @radius, 42 
                        line_circle_face_even = entities2.add_face line_circle_even
                        line_circle_face_even.material = @mat_linie
                        line_circle_face_even.back_material = @mat_linie
                                
                        @helpvar_baseline_even = entities2.add_line @pts[@helpvar2_pts], @pts[@helpvar2_pts-1]
                
                        @helpvar_basearc_even = entities2.add_arc @pts[@helpvar2_pts+1],[0,1,0],[0,0,1],@arcradius,-5.degrees,185.degrees
                        
                        arc_circle_face_even.followme @helpvar_basearc_even
                        line_circle_face_even.followme @helpvar_baseline_even
                        
                      end # if
                #--------------------------------------------------------------------------
                      if (x == @anzahl_arcs)
                        @pts[@helpvar_pts] = [((@width_big-@width_small)/2)+5.35, ((@depth_big-@depth_small)/2)+(@helpvar_depth+6), @height_line]
                        @pts[@helpvar_pts+1] = [@width_small+((@width_big-@width_small)/2)-5, ((@depth_big-@depth_small)/2)+(@helpvar_depth+6), @height_line]
                        
                        @helpvar_baseline_ende = entities2.add_line @pts[@helpvar_pts], @pts[@helpvar_pts+1]
                        
                        line_circle_odd = entities2.add_circle @pts[@helpvar_pts], X_AXIS, @radius, 42 
                        line_circle_face_odd = entities2.add_face line_circle_odd
                        line_circle_face_odd.material = @mat_linie
                        line_circle_face_odd.back_material = @mat_linie
                
                        line_circle_face_odd.followme @helpvar_baseline_ende
                        
                      end # if
                #--------------------------------------------------------------------------
                      @helpvar_depth = @helpvar_depth + 6
                      @helpvar_pts = @helpvar_pts + 3
                #--------------------------------------------------------------------------
                    end # upto - do    
                    
                #--------------------------------------------------------------------------        
                      rescue => e
                        model.abort_operation
                        puts("#{Module.nesting[0].name} Error #<#{e.class.name}; #{e.message}>")
                        puts(e.backtrace)
                      else
                        model.commit_operation
                      end
                    end # def
                
                  end # module LineA
                
                
                  # run when file loads
                  #
                  if Sketchup.active_model &&
                  Sketchup.active_model.active_entities
                    LineA.create_line
                  else
                    LineA;;TIMER = UI.start_timer(2.0, true){
                      if Sketchup.active_model &&
                      Sketchup.active_model.active_entities
                        UI.stop_timer(LineA;;TIMER)
                        LineA.create_line
                      end #if
                    }
                  end
                
                end # module Chris88
                
                

                Is this what do you mean?
                However it doesn't solve the bug.

                @thomthom: Thanks, that could help me. I know this, what you wrote in your sidenode, but it didn't work: When i draw a circle and a path, which starts at the central point of the cricle, Sketchup draw only the lines, but not the curves. This is why i decided alternatively to draw the lines and the curves seperately. Do you think the gaps could be the reason for the bug?

                1 Reply Last reply Reply Quote 0
                • C Offline
                  Chris88
                  last edited by

                  Dan, i have to correct myself: It works, when i load the script from the Ruby Console = step forward! πŸ˜„ [Edit:] i just noticed, this is what thomthom meant. 😒 [/Edit]
                  But it doesn't work yet, when i want to load the script from the plugin-folder by starting SU normally and the script is located in the plugin-folder.

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

                    @chris88 said:

                    Do you think the gaps could be the reason for the bug?

                    Don't think so. Just a sidenote. It is possible to create that shape in one operation.

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

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

                      Alright replace the load loop with this ...

                        # run when file loads
                        #
                        prevdir = Dir.getwd
                        Dir.chdir Sketchup.find_support_file("Tools")
                        tools = Dir["*.rb"]
                        Dir.chdir(prevdir)
                        if ( tools & $LOADED_FEATURES == tools ) &&
                        Sketchup.active_model &&
                        Sketchup.active_model.active_entities
                          UI.start_timer(2.0, false){ LineA.create_line }
                        else
                          timer_LineA = UI.start_timer(2.0, true){
                            if ( tools & $LOADED_FEATURES == tools ) &&
                            Sketchup.active_model &&
                            Sketchup.active_model.active_entities
                              UI.stop_timer(timer_LineA)
                              LineA.create_line
                            end #if
                          }
                        end
                        tools = nil
                      
                      

                      I'm not here much anymore.

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

                        And here's a version that makes sure the Tool Stack is ready ...

                          # run when file loads
                          #
                          prevdir = Dir.getwd
                          Dir.chdir Sketchup.find_support_file("Tools")
                          tools = Dir["*.rb"]
                          Dir.chdir(prevdir)
                          if ( tools & $LOADED_FEATURES == tools ) &&
                          Sketchup.active_model &&
                          Sketchup.active_model.active_entities &&
                          Sketchup.active_model.tools.active_tool_id != 0
                            UI.start_timer(2.0, false){ LineA.create_line }
                          else
                            timer_LineA = UI.start_timer(2.0, true){
                              if ( tools & $LOADED_FEATURES == tools ) &&
                              Sketchup.active_model &&
                              Sketchup.active_model.active_entities &&
                              Sketchup.active_model.tools.active_tool_id != 0
                                UI.stop_timer(timer_LineA)
                                LineA.create_line
                              end #if
                            }
                          end
                          tools = nil
                        
                        

                        I'm not here much anymore.

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

                          Let's step back to the very beginning...
                          Do you need this script to run automatically EVERY time EVERY SKP opens?
                          A. Yes.
                          Why for goodness sake ???
                          A. No.
                          Then what's the problem?
                          If it runs from a menu/toolbar then everything will be loaded by the time you think about using it anyway. Just do NOT include the code that runs it as it loads and everything is cushty!
                          πŸ˜•

                          TIG

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

                            Because he's generating ruby scripts (that build geometry,) from a C# program, which reads XML data.
                            A batch mode use of Sketchup.

                            He's not that good with Ruby, or else he could use Ruby's XML libraries directly.

                            And I do have an API request in for an AppObserver "onReadyState" callback method.

                            I'm not here much anymore.

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

                              Well, I tried the snippet - installed in my Plugins folder - now executing the command. It splatted. But wrapping the command in a timer that delay the operation with two seconds - no splat.

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

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

                                The processing of the Tools dir must complete, so that the menus and toolbars can all be built and displayed.

                                I'm not here much anymore.

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

                                  Isn't he doing it arse-before-face as we say in the UK ?

                                  Open Sketchup.
                                  Start_operation.
                                  Run the external 'tool'...
                                  Load the objects in turn, each one as an individual component.
                                  When all objects are done Export those objects in turn as separate SKPs.
                                  Abort_operation.
                                  Close Sketchup [no save].

                                  That way nothing relies on something else 'opening in time' ?

                                  TIG

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

                                    @tig said:

                                    Isn't he doing it arse-before-face as we say in the UK ?

                                    We'll, he knows C#, and not much of Ruby.

                                    Instead of using Sketchup in a hacked batchmode... he or someone needs to wrap the C++ Interfaces for SKPWriter.DLL for C#. (Likely someone has already done it.) Any way it would be better to directly create skps.

                                    I'm not here much anymore.

                                    1 Reply Last reply Reply Quote 0
                                    • C Offline
                                      Chris88
                                      last edited by

                                      THANKS to all for your efforts!
                                      Now it works!!! it's slower than before, but it runs and that's the main thing!
                                      @Dan: Thank you, you're the best! ^^

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

                                        No problem...

                                        Just a note that the disposal of the tools filename array needs to be inside the conditional true blocks. (Otherwise we might get an error with the & method if tools gets set to nil, prematurely.)

                                          # run when file loads
                                          #
                                          prevdir = Dir.getwd
                                          Dir.chdir Sketchup.find_support_file("Tools")
                                          tools = Dir["*.rb"]
                                          Dir.chdir(prevdir)
                                          prevdir = nil
                                          if ( tools & $LOADED_FEATURES == tools ) &&
                                          Sketchup.active_model &&
                                          Sketchup.active_model.active_entities &&
                                          Sketchup.active_model.tools.active_tool_id != 0
                                            UI.start_timer(2.0, false){ LineA.create_line }
                                            tools = nil
                                          else
                                            timer_LineA = UI.start_timer(2.0, true){
                                              if ( tools & $LOADED_FEATURES == tools ) &&
                                              Sketchup.active_model &&
                                              Sketchup.active_model.active_entities &&
                                              Sketchup.active_model.tools.active_tool_id != 0
                                                UI.stop_timer(timer_LineA)
                                                tools = nil
                                                LineA.create_line
                                              end #if
                                            }
                                          end
                                        
                                        

                                        I'm not here much anymore.

                                        1 Reply Last reply Reply Quote 0
                                        • 1
                                        • 2
                                        • 2 / 2
                                        • First post
                                          Last post
                                        Buy SketchPlus
                                        Buy SUbD
                                        Buy WrapR
                                        Buy eBook
                                        Buy Modelur
                                        Buy Vertex Tools
                                        Buy SketchCuisine
                                        Buy FormFonts

                                        Advertisement