SketchUcation Premium Membership

 

 

Mysterious Bug [followme related]

Mysterious Bug [followme related]

Postby Chris88 » Tue Jan 17, 2012 1:35 pm

Hi all,
i have this code (i know it looks confusing, because i don't know
how to program the 'followme'-function, but it's not the problem)

Code: Select all
 module LineA
  def LineA.create_line
  unless Sketchup.active_model;
    until Sketchup.active_model.active_entities
    end
  end
 
    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
    entities2 = group.entities
#--------------------------------------------------------------------------
    @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   
#--------------------------------------------------------------------------
  end # def
end # module

LineA.create_line



When i execute it in SU there's no error, but if i load it in the plugins of SU,
the hole SU break down and show me a 'Bug Splat', however no significant error message.
I hope you can help me.
Thanks
Chris88
 
Posts: 29
Joined: Wed Nov 02, 2011 5:11 pm

Re: Mysterious Bug

Postby thomthom » Tue Jan 17, 2012 1:42 pm

Code: Select all

unless Sketchup
.active_model;
        until Sketchup.active_model.active_entities
        end
      end

What is this strange loop?

Is it that you try to make it run when SU starts? I see you have this line at the end: LineA.create_line

Why do you have that strange loop?
Have you tried without it?

I'd be very surprised if that lop doesn't block up all processing of SketchUp.


If that isn't the issue - have you tried commenting out blocks of your code to see when it does not crash? When it doesn't then you know the offending line is within that block and you can narrow down further.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17568
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Mysterious Bug

Postby Chris88 » Tue Jan 17, 2012 2:10 pm

the strange loop ist an advice of TIG... http://forums.sketchucation.com/viewtopic.php?f=180&t=41767,
it makes sure that all services of SU are loaded succesfully.
it runs also without this loop.

And i have commenting out all loops and many lines, but i didn't found the failure.
It's strange that i can run the script succesfully in SU, this bug is only when loading the script out of the plugins or starting SU per cmd with the script as parameter.

(P.S. i have SU 8 free version)
Chris88
 
Posts: 29
Joined: Wed Nov 02, 2011 5:11 pm

Re: Mysterious Bug

Postby thomthom » Tue Jan 17, 2012 2:14 pm

Chris88 wrote:this bug is only when loading the script out of the plugins

What you explain what you mean by this?

Chris88 wrote:It's strange that i can run the script succesfully in SU

I'm confused - is it when the script is located in another location? Or if you load the script manually via the Ruby Console?
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17568
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Mysterious Bug

Postby TIG » Tue Jan 17, 2012 2:17 pm

I can't start to guess why you might want always to do this weirdness at every startup - for example, why make geometry that might clash with existing stuff etc... why not simply load a premade component, or make a new template containing the desired stuff as the default for your new SKPs ???
Also do you have require 'sketchup.rb' at the very start of the script ?
It might be needed somewhere in your code :?

Your [my :oops: ] code
Code: Select all
unless Sketchup.active_model
  until Sketchup.active_model.active_entities
  end
end
is wrong.
It waits until the model.active_entities exist before continuing, BUT it only does the pause if there is NOT an active_model ?
Therefore it never pauses because the active_model always exists as it is loading the script's code, although the active_entities might not [on a MAC for example]...
Try
Code: Select all
until Sketchup.active_model
  until Sketchup.active_model.active_entities
    ### wait
  end
end
which WILL wait until there's both an active_model and it has active_entities...

ALSO , as I suggested in that other thread... why not encapsulate your 'loose' code in a 'timer' which waits a few seconds before kicking off, like this:
UI.start_timer(2.0, false){LineA.create_line}
This lurks for 2.0 seconds after the script loads before doing its dirty deeds...
Then most things will have 'passed' before it works...
http://code.google.com/apis/sketchup/do ... tart_timer
TIG
User avatar
TIG
Global Moderator
 
Posts: 13950
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Mysterious Bug

Postby Chris88 » Tue Jan 17, 2012 2:40 pm

@thomthom: i can start successfully the script in SU per Ruby Code Editor or per Sketchup Bridge in RDE to test it. The error appears when i copy my script in the plugin-folder, load it from ruby console in SU or start SU per cmd and assign my script as parameter in the cmd.

@TIG: thanks for your corrected code and suggestion, but it doesn't solve the bug. And i don't 'understand' your first lines: "make a new template containing the desired stuff as the default" ... and it shouldn't be premade components (that's was my first attempt :( )
Chris88
 
Posts: 29
Joined: Wed Nov 02, 2011 5:11 pm

Re: Mysterious Bug

Postby TIG » Tue Jan 17, 2012 2:55 pm

Why make all of the complex geometry in a new group every time ?
Make it as a SKP, load that as a component, and add an instance of it inside a new group's entities, and explode the instance, then erase all of the just loaded component's definition's entities and it is removed from the model [provided there's a start/commit_operation around the actions]... That way you don't need to 'code' the making of the object and it's still inside a group as you have now AND there's no new component been added to the model...
IF you explained what it is you are attempting to 'automate' then we might have more insight... :?
TIG
User avatar
TIG
Global Moderator
 
Posts: 13950
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Mysterious Bug

Postby thomthom » Tue Jan 17, 2012 2:55 pm

Maybe we need to take a step back. What is the overall goal of what you are making?
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17568
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Mysterious Bug

Postby Chris88 » Tue Jan 17, 2012 3:12 pm

The course of action of my program, which conduces to woodworking:
in C#:
- read technical values out of xml-files
- generate a rubyscript for every object
(tool, wood, machining line,...) in .txt- format
- replace the wildcards (i.e: width,height,depth of a wooden box)
- put all rubyscripts together an name the file xy.rb
- start Sketchup with the file xy.rb as argument

... and my code is all but finished, when i start SU with the file xy.rb it crashes and SU reports a "bug splat"
http://images.wikia.com/sketchyphysics/images/6/63/BugSplat.png
Last edited by Chris88 on Tue Jan 17, 2012 3:15 pm, edited 1 time in total.
Chris88
 
Posts: 29
Joined: Wed Nov 02, 2011 5:11 pm

Re: Mysterious Bug

Postby Chris88 » Tue Jan 17, 2012 3:14 pm

So because i'm almost at the end of coding my program, i actually don't want to modify the rubyscript, that it loads premade components.
Chris88
 
Posts: 29
Joined: Wed Nov 02, 2011 5:11 pm

Re: Mysterious Bug

Postby thomthom » Tue Jan 17, 2012 3:18 pm

Right. And I understand that it crashes when you start SU with an argument to execute that plugin? Correct?

But not if start SketchUp and use the Ruby Console to load it?

If the plugin is located in the plugin folder - does it crash then?

This is what is unclear to me.

this bug is only when loading the script out of the plugins
<- I don't understand what you mean there. "out of the plugins"?
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17568
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Mysterious Bug

Postby Dan Rathbun » Tue Jan 17, 2012 3:20 pm

    Try it like this:

    Code: Select all
    module Chris88

      module LineA

        TIMER = nil

        def self.create_line()
          # delete lines 1-4 with loop
          #
          begin
            model.start_operation( 'LineA' )
            #
            # the rest of your method code
            #
          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


    Your modules need to be wrapped inside your "author" outer module.
    User avatar
    Dan Rathbun
    Top SketchUcator
     
    Posts: 4069
    Joined: Tue Oct 06, 2009 3:06 am
    Location: Florida, USA
    Name: Dan Rathbun
    Operating system: Windows
    SketchUp version: 8
    License type: Pro
    SketchUp use: education
    Level of SketchUp: Advanced

    Re: Mysterious Bug

    Postby Chris88 » Tue Jan 17, 2012 3:29 pm

    @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...
    Chris88
     
    Posts: 29
    Joined: Wed Nov 02, 2011 5:11 pm

    Re: Mysterious Bug

    Postby thomthom » Tue Jan 17, 2012 3:47 pm

    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.
    Please, register (free) to access all the attachments on the forums.
    Thomas Thomassen — SketchUp Monkey & Coding addict
    List of my plugins and link to the CookieWare fund
    User avatar
    thomthom
    Global Moderator
     
    Posts: 17568
    Joined: Tue Nov 13, 2007 12:47 pm
    Location: Trondheim, Norway
    Name: thomthom
    Operating system: Windows
    SketchUp version: 8
    License type: Pro
    SketchUp use: architecture
    Level of SketchUp: Advanced

    Re: Mysterious Bug

    Postby thomthom » Tue Jan 17, 2012 3:48 pm

    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
    User avatar
    thomthom
    Global Moderator
     
    Posts: 17568
    Joined: Tue Nov 13, 2007 12:47 pm
    Location: Trondheim, Norway
    Name: thomthom
    Operating system: Windows
    SketchUp version: 8
    License type: Pro
    SketchUp use: architecture
    Level of SketchUp: Advanced

    Re: Mysterious Bug

    Postby Dan Rathbun » Tue Jan 17, 2012 3:53 pm

    thomthom wrote: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.
    User avatar
    Dan Rathbun
    Top SketchUcator
     
    Posts: 4069
    Joined: Tue Oct 06, 2009 3:06 am
    Location: Florida, USA
    Name: Dan Rathbun
    Operating system: Windows
    SketchUp version: 8
    License type: Pro
    SketchUp use: education
    Level of SketchUp: Advanced

    Re: Mysterious Bug

    Postby Dan Rathbun » Tue Jan 17, 2012 3:57 pm

    maybe a wait timer like this is safer...
    Code: Select all
      # 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
    User avatar
    Dan Rathbun
    Top SketchUcator
     
    Posts: 4069
    Joined: Tue Oct 06, 2009 3:06 am
    Location: Florida, USA
    Name: Dan Rathbun
    Operating system: Windows
    SketchUp version: 8
    License type: Pro
    SketchUp use: education
    Level of SketchUp: Advanced

    Re: Mysterious Bug

    Postby Chris88 » Tue Jan 17, 2012 4:02 pm

    @Dan: Thank you. Now my code looks like:
    Code: Select all
    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?
    Chris88
     
    Posts: 29
    Joined: Wed Nov 02, 2011 5:11 pm

    Re: Mysterious Bug

    Postby Chris88 » Tue Jan 17, 2012 4:10 pm

    Dan, i have to correct myself: It works, when i load the script from the Ruby Console = step forward! :D [Edit:] i just noticed, this is what thomthom meant. :cry: [/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.
    Chris88
     
    Posts: 29
    Joined: Wed Nov 02, 2011 5:11 pm

    Re: Mysterious Bug

    Postby thomthom » Tue Jan 17, 2012 4:21 pm

    Chris88 wrote: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
    User avatar
    thomthom
    Global Moderator
     
    Posts: 17568
    Joined: Tue Nov 13, 2007 12:47 pm
    Location: Trondheim, Norway
    Name: thomthom
    Operating system: Windows
    SketchUp version: 8
    License type: Pro
    SketchUp use: architecture
    Level of SketchUp: Advanced

    Re: Mysterious Bug

    Postby Dan Rathbun » Tue Jan 17, 2012 4:32 pm

    Alright replace the load loop with this ...
    Code: Select all
      # 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
    User avatar
    Dan Rathbun
    Top SketchUcator
     
    Posts: 4069
    Joined: Tue Oct 06, 2009 3:06 am
    Location: Florida, USA
    Name: Dan Rathbun
    Operating system: Windows
    SketchUp version: 8
    License type: Pro
    SketchUp use: education
    Level of SketchUp: Advanced

    Re: Mysterious Bug

    Postby Dan Rathbun » Tue Jan 17, 2012 4:39 pm

    And here's a version that makes sure the Tool Stack is ready ...
    Code: Select all
      # 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
    User avatar
    Dan Rathbun
    Top SketchUcator
     
    Posts: 4069
    Joined: Tue Oct 06, 2009 3:06 am
    Location: Florida, USA
    Name: Dan Rathbun
    Operating system: Windows
    SketchUp version: 8
    License type: Pro
    SketchUp use: education
    Level of SketchUp: Advanced

    Re: Mysterious Bug

    Postby TIG » Tue Jan 17, 2012 4:46 pm

    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
    User avatar
    TIG
    Global Moderator
     
    Posts: 13950
    Joined: Mon Nov 12, 2007 7:24 pm
    Location: Northumbria UK
    Name: TIG
    Operating system: Windows
    SketchUp version: 8
    License type: Pro
    SketchUp use: architecture
    Level of SketchUp: Advanced

    Re: Mysterious Bug

    Postby Dan Rathbun » Tue Jan 17, 2012 4:52 pm

    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.
    User avatar
    Dan Rathbun
    Top SketchUcator
     
    Posts: 4069
    Joined: Tue Oct 06, 2009 3:06 am
    Location: Florida, USA
    Name: Dan Rathbun
    Operating system: Windows
    SketchUp version: 8
    License type: Pro
    SketchUp use: education
    Level of SketchUp: Advanced

    Re: Mysterious Bug

    Postby thomthom » Tue Jan 17, 2012 4:56 pm

    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
    User avatar
    thomthom
    Global Moderator
     
    Posts: 17568
    Joined: Tue Nov 13, 2007 12:47 pm
    Location: Trondheim, Norway
    Name: thomthom
    Operating system: Windows
    SketchUp version: 8
    License type: Pro
    SketchUp use: architecture
    Level of SketchUp: Advanced

    Re: Mysterious Bug

    Postby Dan Rathbun » Tue Jan 17, 2012 5:02 pm

    The processing of the Tools dir must complete, so that the menus and toolbars can all be built and displayed.
    User avatar
    Dan Rathbun
    Top SketchUcator
     
    Posts: 4069
    Joined: Tue Oct 06, 2009 3:06 am
    Location: Florida, USA
    Name: Dan Rathbun
    Operating system: Windows
    SketchUp version: 8
    License type: Pro
    SketchUp use: education
    Level of SketchUp: Advanced

    Re: Mysterious Bug

    Postby TIG » Tue Jan 17, 2012 5:06 pm

    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
    User avatar
    TIG
    Global Moderator
     
    Posts: 13950
    Joined: Mon Nov 12, 2007 7:24 pm
    Location: Northumbria UK
    Name: TIG
    Operating system: Windows
    SketchUp version: 8
    License type: Pro
    SketchUp use: architecture
    Level of SketchUp: Advanced

    Re: Mysterious Bug

    Postby Dan Rathbun » Tue Jan 17, 2012 5:54 pm

    TIG wrote: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.
    User avatar
    Dan Rathbun
    Top SketchUcator
     
    Posts: 4069
    Joined: Tue Oct 06, 2009 3:06 am
    Location: Florida, USA
    Name: Dan Rathbun
    Operating system: Windows
    SketchUp version: 8
    License type: Pro
    SketchUp use: education
    Level of SketchUp: Advanced

    Re: Mysterious Bug

    Postby Chris88 » Wed Jan 18, 2012 8:38 am

    THANKS to all for your efforts!
    Now it works!!! :berserk: it's slower than before, but it runs and that's the main thing!
    @Dan: Thank you, you're the best! ^^
    Chris88
     
    Posts: 29
    Joined: Wed Nov 02, 2011 5:11 pm

    Re: Mysterious Bug

    Postby Dan Rathbun » Fri Jan 20, 2012 2:41 pm

    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.)

    Code: Select all
      # 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
    User avatar
    Dan Rathbun
    Top SketchUcator
     
    Posts: 4069
    Joined: Tue Oct 06, 2009 3:06 am
    Location: Florida, USA
    Name: Dan Rathbun
    Operating system: Windows
    SketchUp version: 8
    License type: Pro
    SketchUp use: education
    Level of SketchUp: Advanced

    SketchUcation One-Liner Adverts

    by Ad Machine » 5 minutes ago

    Keyframe Animation plugin - animate your SketchUp model by adding movement to any object.

    Premium Members get 20% discount!

    Ad Machine
    Robot
     
    Posts: 2012


    Return to Developers' Forum

    cron

    Who is online

    Users browsing this forum: Anton_S, Bing [Bot] and 4 guests