sketchucation logo sketchucation
    • Login
    1. Home
    2. cjthompson
    3. Posts
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ”Œ Easy Offset | Offset selected faces in SketchUp in positive and negative offsets. Download
    C
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 19
    • Posts 151
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: Multi-threading inside SketchUp

      This gets the best results for me so far. It's really slow, but it seems to be executing on a regular basis.

      
      def testThread(times)
      	timer = UI.start_timer(0,true){Sketchup.active_model.entities}
      	thread = Thread.new{(0...times).each{|num| addBox};UI.stop_timer(timer)}
      end
      
      def addBox
      	group = Sketchup.active_model.entities.add_group
      	face = group.entities.add_face([0,0,0],[1,0,0],[1,1,0],[0,1,0])
      	face.pushpull(-1)
      	group.transformation = Geom;;Transformation.new([rand(500),rand(500),rand(500)])
      end
      
      
      posted in Developers' Forum
      C
      cjthompson
    • RE: Float <-> String - Locale aware?

      Why won't "12,2".to_l.to_f work?

      posted in Developers' Forum
      C
      cjthompson
    • RE: Threads Needed, Waits Wanted

      Is there any reason something like this wouldn't work?

      
      now = Time.now
      UI.start_timer(0,true){
        if(Time.now - now > 0.5)
          puts "Test"
          now = Time.now
        end
      }
      
      
      posted in Developers' Forum
      C
      cjthompson
    • RE: Model.edit_transform for parent

      sorry, I must be really tired today. I meant you can't use a pickhelper outside of the current context. so If you you have two instances in the model, and you double click one, you can't use the pickhelper on it's sibling.

      posted in Developers' Forum
      C
      cjthompson
    • RE: Model.edit_transform for parent

      @thomthom said:

      @cjthompson said:

      Basically, I'm trying to use an input point to iterate up the model to find the component's path, instead of drilling down to find it.

      Get help from a pickhelper?
      http://code.google.com/apis/sketchup/docs/ourdoc/pickhelper.html

      except you can't pick outside of edit mode.

      I solved it by just drilling down the model structure, instead of going up it like the original idea.

      posted in Developers' Forum
      C
      cjthompson
    • RE: Model.edit_transform for parent

      It looks like its inherited from drawing element, so you can use it on faces and edges, too.

      posted in Developers' Forum
      C
      cjthompson
    • RE: What? No Menu?

      I suppose refresh is a better term. I was referring to a frame in animation.

      posted in Developers' Forum
      C
      cjthompson
    • RE: What? No Menu?

      That's because the code is executed all during one frame, which also explains why the one-liner works.

      My guess is that Sketchup creates a new menu , adds the items, and does the validation each frame, instead of just using one menu.

      posted in Developers' Forum
      C
      cjthompson
    • RE: What? No Menu?

      I think it has something to do with the fact that UI.menu() returns a new object each time:

      UI.menu("Plugins")
      #<Sketchup;;Menu;0x5dbf1c0>
      UI.menu("Plugins")
      #<Sketchup;;Menu;0x5dbeff8>
      UI.menu("Plugins")
      #<Sketchup;;Menu;0x5dbee30>
      UI.menu("Plugins")
      #<Sketchup;;Menu;0x5dbec68>
      UI.menu("Plugins")
      #<Sketchup;;Menu;0x5dbeaa0>
      
      posted in Developers' Forum
      C
      cjthompson
    • RE: Writing Readable Ruby

      @martinrinehart said:

      The more Ruby I write, the more readable my Ruby becomes. Odd, but the secret seems to be to do nothing the way the Rubyists In Crowd does things. Here's a useful function:

      
      > def concat( *args )
      >     ret = ''
      >     for a in args do ret += ( a.to_s() ) end
      >     return ret
      > end
      > 
      

      Here's the official, Rubyists-approved-but-don't-show-Monty version of that function:

      
      > def concat(*args)
      >   ret = ''
      >   args.each {|a| ret += a.to_s}
      >   ret
      > end
      > 
      

      personally, I find the second version much more readable, especially when just scanning the code. I takes me about 5 steps to glance at the second version, while it takes about 8-10 steps for the first.

      listing the code in the order I see it:
      version 1:
      ( a.to_s() ) end (line 3)
      concat( *args ) (line 1)
      for a in args (line 3)
      ret = '' (line 2)
      return ret (line 4)
      do ret += (line 3)
      (it usually takes 2 - 3 more steps to put everything together)

      version 2:
      {|a| ret += a.to_s} (line 3)
      concat(*args) (line 1) ( I can usually understand the code by this step)
      ret = '' (line 2)
      args.each (line 3)
      ret end (line 4-5)

      Everything I don't have listed, I skip.

      BTW, my version would be:

      
      def concat(*args)
          return args.join('')
      end
      
      

      πŸ˜„

      posted in Developers' Forum
      C
      cjthompson
    • RE: How do you make Ruby Scripts Pause

      Has anyone figured out how to use threads fluidly, so that ruby and regular sketchup will work at the same time?

      posted in Developers' Forum
      C
      cjthompson
    • RE: Is Point between Points?

      something like this:

      
      def pointBetween(a,b,c)
      	array = [[a.x.to_f,b.x.to_f],[a.y.to_f,b.y.to_f],[a.z.to_f,b.z.to_f]]
      	x = c.x.to_f.between?(*array[0].sort)
      	y = c.y.to_f.between?(*array[1].sort)
      	z = c.z.to_f.between?(*array[2].sort)
      	return x && y && z
      end
      
      

      I'm not saying it will work, I'm just wondering whether it will or not.

      posted in Developers' Forum
      C
      cjthompson
    • RE: Is Point between Points?

      @TIG
      You should probably convert d1 and d2 to float before comparing them:
      0.0001.inch == 0.001.inch #=> true

      BTW, do you have to determine whether the point is on the line, or is it just assumed?

      posted in Developers' Forum
      C
      cjthompson
    • RE: Is Point between Points?

      Do you know why just comparing the individual X,Y and Zs won't work?

      posted in Developers' Forum
      C
      cjthompson
    • RE: Timer &lt; 1.0 seconds ?

      I'm pretty sure a thread "kills" itself after all the code is executed (not sure of the correct terminology).

      By the way, what does & do in front of a variable (&block)?

      posted in Developers' Forum
      C
      cjthompson
    • RE: Quickly finding groups/comps in an Entity Collection?

      this thread reminds me of this:
      http://refactormycode.com/codes/2-ruby-simple-loop
      with each consecutive code sample improving on the last πŸ˜†

      although the only improvement I could possibly add might be:

      
      def miner(ents)
          for e in ents
             if e.class==Sketchup;;Group or e.class==Sketchup;;ComponentInstance
                 miner(e.explode) 
             end
          end
      end
      
      posted in Developers' Forum
      C
      cjthompson
    • RE: Quickly finding groups/comps in an Entity Collection?

      @tig said:

      My version was to explode only groups and instances within a set of entities [which I understood to be the aim] and any groups/instances found within them - definition contents shouldn't change?].

      Since you are exploding bottom to top, the top level definitions will change before they are exploded.

      here is a method that will explode them top to bottom:

      
      def miner(ents)
      	ents.each{|e|
      		if e.class==Sketchup;;Group
      			miner(e.explode)
      		elsif e.class==Sketchup;;ComponentInstance
      			miner(e.explode)
      		end#if
      		}#end each
      end#def
      
      

      EDIT: I just realized that's what the group is for. 😳

      posted in Developers' Forum
      C
      cjthompson
    • RE: Quickly finding groups/comps in an Entity Collection?

      @jim said:

      If I understand what you want to do, you are making it harder than it is.
      The result is that the most deeply nested objects get exploded first, and then works up the hierarchy. The last object exploded is then the first object found.

      wouldn't you want to explode top > down instead of bottom > up? that way, you don't explode definitions of instances in other Entities.

      or was Chris thinking of exploding the whole model?

      posted in Developers' Forum
      C
      cjthompson
    • RE: Lock inference to X, Y or Z_

      well, another thing you could do is to add an edge going along the axis you want, lock the inference from that IP, and delete the edge again.

      You might have the same problems with geometry getting your way, though.

      posted in Developers' Forum
      C
      cjthompson
    • RE: Lock inference to X, Y or Z_

      It looks like it. 😞 although I can't see any way to get an input point from 3d coordinates, so I don't really think it can be avoided.

      posted in Developers' Forum
      C
      cjthompson
    • 1 / 1