sketchucation logo sketchucation
    • Login
    1. Home
    2. icehuli
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 6
    • Posts 41
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: Colored faces

      little benchmark: windows 8, sketchup 2013 maker, cpu 4900mq

      code:

      require 'benchmark'
      mod = Sketchup.active_model # Open model
      ent = mod.entities # All entities in model
      sel = mod.selection # Current selection
      arr = ent.to_a
      print "sel;",sel.to_a.size,"  ==  ent;",ent.to_a.size
      puts "",arr
      
      Benchmark.bm(20) do |x|
        x.report("ent.greb")         { 100000.times { faces =  ent.grep(Sketchup;;Edge) } }
        x.report("ent.select,is_a?") { 100000.times { faces =  ent.select{|e| e.is_a?  Sketchup;;Edge } } }
        x.report("ent.select,class") { 100000.times { faces =  ent.select{|e| e.class==Sketchup;;Edge } } }
        x.report("ent.each,is_a?")   { 100000.times { faces=[];ent.each{|e|faces << e if e.is_a?  Sketchup;;Edge} } }
        x.report("ent.each,class")   { 100000.times { faces=[];ent.each{|e|faces << e if e.class==Sketchup;;Edge} } }
        
        x.report("sel.greb")         { 100000.times { faces =  sel.grep(Sketchup;;Edge) } }
        x.report("sel.select,is_a?") { 100000.times { faces =  sel.select{|e| e.is_a?  Sketchup;;Edge } } }
        x.report("sel.select,class") { 100000.times { faces =  sel.select{|e| e.class==Sketchup;;Edge } } }
        x.report("sel.each,is_a?")   { 100000.times { faces=[];sel.each{|e|faces << e if e.is_a?  Sketchup;;Edge} } }
        x.report("sel.each,class")   { 100000.times { faces=[];sel.each{|e|faces << e if e.class==Sketchup;;Edge} } }
        
        x.report("arr.greb")         { 100000.times { faces =  arr.grep(Sketchup;;Edge) } }
        x.report("arr.select,is_a?") { 100000.times { faces =  arr.select{|e| e.is_a?  Sketchup;;Edge } } }
        x.report("arr.select,class") { 100000.times { faces =  arr.select{|e| e.class==Sketchup;;Edge } } }
        x.report("arr.each,is_a?")   { 100000.times { faces=[];arr.each{|e|faces << e if e.is_a?  Sketchup;;Edge} } }
        x.report("arr.each,class")   { 100000.times { faces=[];arr.each{|e|faces << e if e.class==Sketchup;;Edge} } }
      end
      
      

      result:

      
                                user     system      total        real
      ent.greb              0.672000   0.000000   0.672000 (  0.681000)
      ent.select,is_a?      1.329000   0.000000   1.329000 (  1.328000)
      ent.select,class      1.437000   0.000000   1.437000 (  1.445000)
      ent.each,is_a?        1.266000   0.000000   1.266000 (  1.264000)
      ent.each,class        1.390000   0.000000   1.390000 (  1.391000)
      
      sel.greb              0.657000   0.000000   0.657000 (  0.655000)
      sel.select,is_a?      1.343000   0.000000   1.343000 (  1.330000)
      sel.select,class      1.469000   0.000000   1.469000 (  1.452000)
      sel.each,is_a?        1.250000   0.000000   1.250000 (  1.260000)
      sel.each,class        1.375000   0.000000   1.375000 (  1.386000)
      
      arr.greb              0.391000   0.000000   0.391000 (  0.401000)
      arr.select,is_a?      0.735000   0.000000   0.735000 (  0.740000)
      arr.select,class      0.860000   0.000000   0.860000 (  0.873000)
      arr.each,is_a?        0.953000   0.000000   0.953000 (  0.960000)
      arr.each,class        1.078000   0.000000   1.078000 (  1.090000)
      
      

      data:

      sel;28  ==  ent;28
      #<Sketchup;;Edge;0x18cf0054> 
      #<Sketchup;;Edge;0x18cf0018>
      #<Sketchup;;Edge;0x18cf0090>
      #<Sketchup;;Edge;0x18ceffdc>
      #<Sketchup;;Face;0x18cf00cc>
      #<Sketchup;;Group;0x18ce5e4c>
      #<Sketchup;;Edge;0x18eacf64>
      #<Sketchup;;Edge;0x18eacfdc>
      #<Sketchup;;Edge;0x18eacf28>
      #<Sketchup;;Edge;0x18eacfa0>
      #<Sketchup;;Face;0x18ead018>
      #<Sketchup;;Edge;0x18bd1254>
      #<Sketchup;;Edge;0x18bd11dc>
      #<Sketchup;;Edge;0x18bd1218>
      #<Sketchup;;Edge;0x18bd11a0>
      #<Sketchup;;Face;0x18bd1290>
      #<Sketchup;;Edge;0x18bd0bb0>
      #<Sketchup;;Edge;0x18bd0b74>
      #<Sketchup;;Edge;0x18bd0b38>
      #<Sketchup;;Edge;0x18bd0afc>
      #<Sketchup;;Face;0x18bd0bec>
      #<Sketchup;;Edge;0x18bcefb8>
      #<Sketchup;;Edge;0x18bcee8c>
      #<Sketchup;;Edge;0x18bcef7c>
      #<Sketchup;;Edge;0x18bceec8>
      #<Sketchup;;Edge;0x18bcef40> 
      #<Sketchup;;Edge;0x18bcef04>
      #<Sketchup;;Face;0x18bceff4>
      
      posted in Developers' Forum
      icehuliI
      icehuli
    • Are Dynamic Components very slow? Why?

      Hi all,

      I tried to use dynamic components to explore parametric modelling possibility with sketchup. But for me they seem very slow. It takes sometime to update the model. It is only a small model, the "Grid Example".
      Is there a way to make it behaves run-timely? I mean make the updating happens without notice?
      Is there a better way than using DC?

      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: Offset-function per ruby (simple)

      @artmusicstudio said:

      @slbaumgartner said:

      @artmusicstudio said:

      hi,
      is there an equivalent for the skp-function "offset" in ruby for simple forms like square or circle ?
      thanx stan

      Were you looking to move objects, per Dan's replies, or for a Ruby equivalent to the offset tool (i.e. to create a "parallel" shape inside or outside the original)?

      hi, slbaumgartner,
      yes , you got it,
      what i look for here (though dan's advice is also helpful for other things)
      is in deed the offset-function, creating a parallel shape (only simple forms like rectangles or circles).

      stan

      you can try this:
      http://www.smustard.com/script/Offset
      simply works for faces(polygons) and polylines

      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: 1001 Bit Tools Crashing

      @unknownuser said:

      @unknownuser said:

      Not quite sure how to do that.

      Normally
      Just renamme the original "Plugins" folder in any name you want
      Create a new folder named Plugins
      Copy past inside all 1001bit files from the original

      When your test is finished
      Kill this new Plugin folder ans rename the temporay folder in "Plugins"

      That's all 😄

      I tried this and it again crashed....

      Windows 8, Sketchup 2013 free

      posted in Extensions & Applications Discussions
      icehuliI
      icehuli
    • RE: How to create a face with a hole touching its edge?

      Some observations.....
      The sketchup offset tool is not consistent. It does not always provide the same result....sometime gives the left, sometime gives the right.
      They are slightly different.
      Both results have two faces, a bigger face and a small one(the hole).
      The bigger face is selected in both results, while the small one is not selected.
      On the left, the small one is separated from the bigger face, i.e. the bigger face contains a hole.
      On the right, the small one is overlapped with the bigger face, i.e. the bigger face does not contain a hole.
      .......


      offset_diff.PNG

      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: How to create a face with a hole touching its edge?

      @tig said:

      Try making the inner face then using find_faces on the added outer edges, rather than making that face directly.
      Then the inner face should then be retained for erase!, and the outer one remains as a loop.

      The reason your API 'offset' leaves a hole and SketchUp doesn't is [I suspect] along these lines too...

      GREAT!!!! You are the Jedi!!! 😍

      so the code is:
      e = Sketchup.active_model.entities f1 = e.add_face [1,1,0],[8,1,0],[4,5,0] f2 = e.add_face [2,2,0],[7,2,0],[4,4,0] ed = f1.edges[0] f1.erase! ed.find_faces; f2.erase!

      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: How to create a face with a hole touching its edge?

      @tig said:

      Try making the inner face then using find_faces on the added outer edges, rather than making that face directly.
      Then the inner face should then be retained for erase!, and the outer one remains as a loop.

      The reason your API 'offset' leaves a hole and SketchUp doesn't is [I suspect] along these lines too...

      Hi TIG,

      I am not sure I understand you well. Could you post the code, that how exactly should I do it? Thanks in advance!

      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: How to create a face with a hole touching its edge?

      strong dark force !!! 😡

      Another case does not work!

      I can not get the correct offset of the left polygon. The hole is not empty in Sketchup.


      twofaces_erased.PNG

      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: How to create a face with a hole touching its edge?

      @tt_su said:

      @icehuli said:

      But this does not work.

      How does it not work? Errors? Unexpected result?

      Got a snippet of what you got so far?

      I executed the following code:

      When f2 does NOT touch f1, I get the face with a hole as I expected, see the attached new figure
      e = Sketchup.active_model.entities f1 = e.add_face [1,1,0],[8,1,0],[4,5,0] f2 = e.add_face [2,2,0],[%(#0000FF)[**6**],2,0],[4,4,0] f2.erase!

      When f2 does touch f1, I can not get the face with a hole. A hole is not subtracted from f1.
      e = Sketchup.active_model.entities f1 = e.add_face [1,1,0],[8,1,0],[4,5,0] f2 = e.add_face [2,2,0],[%(#0000FF)[**7**],2,0],[4,4,0] f2.erase!


      twofaces_erased.PNG

      posted in Developers' Forum
      icehuliI
      icehuli
    • How to create a face with a hole touching its edge?

      Does anyone has know how to create a face with a hole in it, while vertices of the hole may touch the edge of the face. See the attached figure f2 touches f1 at point P. I tried to create f1 and f2, then call f2.erase!. But this does not work.


      update:
      I tried the plugin 2d-simplex-bool
      http://extensions.sketchup.com/en/content/2d-simplex-bool
      It seems not working neither.


      one working code from TIG's idea:
      e = Sketchup.active_model.entities f1 = e.add_face [1,1,0],[8,1,0],[4,5,0] f2 = e.add_face [2,2,0],[7,2,0],[4,4,0] ed = f1.edges[0] f1.erase! ed.find_faces; f2.erase!


      twofaces.PNG

      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: Webdialogs for SketchUp ......RIP!

      @thomthom said:

      @icehuli said:

      I think the same method can be applied for c++ gui, e.g. qt, as well. A new thread need to start for the GUI to avoid it being frozen while ruby scripts are being evaluated.

      Isn't the work being done in the work being done in the new thread while the main thread remains control over the UI?

      (Though this would not work in SU if the "work" is manipulating entities.)

      The idea is to control the UI in a separate thread, so no matter what operation is being processed in the main thread or another thread the UI will not be frozen.

      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: Webdialogs for SketchUp ......RIP!

      @jolran said:

      That doesent confuse me less 😄

      About threads, I was under the impression Sketchup threads was a bit shaky ? Although I can't really tell the outcome from this topic.

      http://sketchucation.com/forums/viewtopic.php?f=180&t=51701&p=467287&hilit=threads#p467287

      Sorry, I can not see the post:
      "The requested topic does not exist."

      The issue for thread is that, Sketchup uses ruby version 1.8.6 (1.8.5 on mac), which does not implement native threads. It means they are not actually "parallel", only one thread is actually running at once, ruby controls the switch. I once tried to open a new thread in ruby to do the operation and check if the operation has finished within a loop in another thread. However the result is not reliable. One can not tell when it does the checks.

      In my case my operations are independent from Sketchup. So when open it in another thread in c/c++ it does not freeze the webdialog. If the operations are Sketchup things, e.g. drawing, modification, etc. it will not help. In that case it's better to have the GUI in a new thread different from the ruby thread.

      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: Webdialogs for SketchUp ......RIP!

      @jolran said:

      Aha, interesting. Will chew on it a little..

      My brother is a .net developper with quite a bit of knowledge of C++, so I could probably get a big kickstart and set up. Otherwise I woulden't even consider trying..

      Anyway, thanks again! I'll keep an eye on you projects 😉

      Actually you can still use WebDialog without being frozen by heavy operations. The way is similar. Just put all the heavy operations to a new thread that started in the c++ code. The trick part is communication between threads (that's the point I started to look into .net, since it is much easier to handle multithreading‎ thing with .net libraries ).

      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: Webdialogs for SketchUp ......RIP!

      @jolran said:

      Many thanks for the valuable information, really 👍
      And the link too, much appreciated.

      Looks like you know what youre talking about.

      I'm probably not gonna dig into this just yet. Maybe if I reach a dead end with the Webdialog class.

      I wan't to build an opinion if it's worth the effort first.

      😄
      I reached the dead end a year ago, when I implemented heavy optimization operations. I tried ruby thread, which is a fake in ruby 1.8. It did not solve my problem so I looked into c++ and than realize the extension can be compiled with /clr that opens the door to the wide .NET world.

      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: Webdialogs for SketchUp ......RIP!

      @jolran said:

      @unknownuser said:

      I think the same method can be applied for c++ gui, e.g. qt, as well. A new thread need to start for the GUI to avoid it being frozen while ruby scripts are being evaluated.

      Great! It's just the small detail of learning c++ then 😄

      Seriously though, I was under the impression these kinds of 2 way Communication was not possible outside webdialog-World.

      I would really like to know more.

      In windows C++ should be not much more difficult thanks to visual studio and .net. However in mac os it is more difficult since the default system gui library is cocoa, which require object-c. Once upon a time, one can use carbon to build cocoa GUI, but it is deprecated since OS X 10.8. Automatic Reference Counting, or ARC makes things more complicated. I am not familiar with other c++ or c libraries. If one does, one can try to use multithreading‎ tech. I tried qt yesterday. It is just not straight forward, since in qt every gui needs to be created and maintained in the main thread. And only one QApplication is allowed, thus multiple plugins using qt may cause problems.

      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: Webdialogs for SketchUp ......RIP!

      @jolran said:

      @unknownuser said:

      A new thread need to start for the GUI to avoid it being frozen while ruby scripts are being evaluated

      So, the dialog does not freeze during Ruby operations ?

      How about window modal behavior. I mean how do one activate a dialog through Ruby plugin, must the C# program or whatever being used already be up and running?
      I assume you already have tried this in practice.

      Sorry bout the noob questions 😳

      Yes, one can activate a dialog through ruby plugin. The c# thread is started within the plugin. I have tried something already. check out https://github.com/icehuli/suWpfExt.
      Although it is a alpha version, it should give you a hint how to do the trick. It currently uses swig, which is not necessary. I am working on a version without swig. The plugin is separated in several dlls.

      1. myExtMain.dll is the main dll in c++, compiled with /clr, so it can load .net dlls.
      2. suWpfUI.dll is the UI dll in c#, witch implements the WPF GUI.
      3. suExtMainWrapper.dll is the wapper linked by the GUI to call c++ functions in myExtMain.dll. (This one seems not necessary, the reason to have it is that c# can not be linked to with myExtMain directly. However one can use P/Invoke in c# code
        using VALUE = System.Int32; using ID = System.Int32; [DllImport("msvcrt-ruby18", CallingConvention = CallingConvention.Cdecl)] private static extern VALUE rb_funcall_(VALUE recv, ID mid, int argc, __arglist);
        to directly call ruby functions, thus the suExtMainWrapper is not necessary.)
        Another issue is that suWpfUI and suExtMainWrapper are not explicitly loaded by ruby require so it needs to be placed inside Sketchup.exe directory. I haven't figure out how to avoid this.
      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: Webdialogs for SketchUp ......RIP!

      @jolran said:

      Oh, I wish I'd taken up on C or C++...

      Anyway, I gather Windows only ?

      Both plattforms ought to be provided to keep people happy.

      I think the same method can be applied for c++ gui, e.g. qt, as well. A new thread need to start for the GUI to avoid it being frozen while ruby scripts are being evaluated.

      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: Webdialogs for SketchUp ......RIP!

      One can use c# wpf or winform for the GUI. One can create another thread for the GUI. And use dispatcher for the calling, something like:
      in the ruby thread do
      wpfWindow.Dispatcher.BeginInvoke((Action)(() =>
      {
      wpfWindow.Show();
      wpfWindow.Activate();
      }), System.Windows.Threading.DispatcherPriority.ContextIdle, null);
      to open the window and call other functions in the gui.

      and in gui thread do
      using VALUE = System.Int32;
      ruby_extension.BeginInvoke(DispatcherPriority.Input,
      (Action)(() =>
      {
      VALUE state = 0;
      VALUE rb_mKernel = rb_eval_string_protect("Kernel", ref state);
      rb_funcall(rb_mKernel, rb_intern("puts"),
      rb_eval_string_protect(Encoding.UTF8.GetBytes("Hello, World!" + '\0'), ref state));
      }));
      to call ruby functions or evaluate ruby scripts.

      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: Math-problem

      if 20.0 and 30.0 are the edges, 20.0/30.0 is already the tangent value. You should use Math.atan to get the angel out of it.
      so in short:

      angel = (Math.atan(@lwidthplus/@run)).radians

      posted in Developers' Forum
      icehuliI
      icehuli
    • RE: Math-problem

      try

      @run = 30.0
      @lwidthplus = 20.0

      p.s. are you sure that you are using Math.tan instead of Math.atan ?

      posted in Developers' Forum
      icehuliI
      icehuli
    • 1
    • 2
    • 3
    • 2 / 3