ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
  • Determining Corner Points

    4
    0 Votes
    4 Posts
    665 Views
    TIGT
    Are the original pt1 and pt2 created in the model.active_entities context ? If pt1 is always the ORIGIN then you really only need pt2 ? Why not use a transformation ? You can store the initial truss.transformation.to_a as an attribute with the truss. Then... when you next need to assess the current truss location/rotation just get the current truss.transformation and then modify [transform!] it OR even the saved point [or 2 points] - having adjusted it by the transformation that was stored as it was created - recreated from the attribute array back into a transformation. http://www.sketchup.com/intl/en/developer/docs/ourdoc/transformation
  • [PLEASE HELP] materials

    5
    0 Votes
    5 Posts
    2k Views
    T
    Hi people, Able to replace the texture of a object without upsetting the Mapping. But if I duplicate that object, I am unable to assign a different/separate/unique texture where each object can be assigned a different texture image jpeg. I am unable to DE-LINK the image textures of the two objects. Pls Note: I am able to do this only by applying the texture image as a fresh unmapped material and then fix the mapping all over again.
  • Storing Bounding Points

    3
    0 Votes
    3 Posts
    475 Views
    G
    I like to keep my data in a structure and I like to save structures to disk and / or store them as a complete record in a dictionary. So you can either parse the file / or parse the dictionary in the same exact way. Actually very simple and extremely future proof as they are key pairs. New versions that introduce new fields (elements) need only provide a reasonable default. I can provide you with examples if you want to PM me.
  • Send mail from Sketchup

    3
    0 Votes
    3 Posts
    606 Views
    Dan RathbunD
    And to have an email form filled out, but not automatically sent: UI;;WebDialog;;new( "Email...",true,nil,200,100,300,200,false ).instance_eval { email = "mailto;//someone@example.com"<< "?subject=This%20is%20the%20subject"<< "&cc=someone_else@example.com"<< "&body=This%20is%20the%20body" set_html( "<!DOCTYPE html>\n<html>\n <head>\n </head>\n"<< " <body>\n <br/>"<< " <a id='elink' href='#{email}'>Firing an email!</a>\n"<< " </body>\n"<< "</html>" ) show() { execute_script("elink.click();") } } http://en.wikipedia.org/wiki/Mailto But there must be a registered email client for the system. Ie, it does not work on my machine because I use browser based gmail, and never registered any email client application on this machine. (So for me two error messages popup stating there is no registered email client.)
  • Top Level Component or Group

    4
    0 Votes
    4 Posts
    623 Views
    K
    Thanks that worked and after seeing it correct it makes sence. KeitH
  • How to reduce Sketchup

    4
    0 Votes
    4 Posts
    696 Views
    TIGT
    You can't do it wholly within Ruby. But you could probably make a set of 'system' calls in Ruby to do it [it'll differ between MAC & PC].
  • Compute Rotation and Scale from Transform Object

    26
    0 Votes
    26 Posts
    5k Views
    TIGT
    An olde typo - use 1 for the second test...
  • Towards a complete extension: Good Practices

    5
    0 Votes
    5 Posts
    539 Views
    hsmyersH
    @dan rathbun said: Then you'll need to follow: http://extensions.sketchup.com/en/developer_center/ew_developer#rbz I've read through same and I plan to do so again more thoroughly again after I get this next layer of magic nailed down. I think I now understand the two file format well enough to give it a spin in a bit but am momentarily busy prepping prototype parts for shapeways. Its been tool, prototype, tool, proto in a kind of recursive spiral! Need one for the other and round about we go...
  • UI.inputbox with Web Dialog

    5
    0 Votes
    5 Posts
    1k Views
    hsmyersH
    @thomthom said: https://github.com/thomthom/SKUI Could you add version to README.md? Pretty please with a cookie?
  • How to run a frame change observer

    8
    0 Votes
    8 Posts
    938 Views
    Dan RathbunD
    Example: appspy_w_fco.rb # encoding; UTF-8 module Author   module PluginName        class AppSpy < Sketchup;;AppObserver       @@attached = false unless defined?(@@attached)       def self.attached?()         @@attached ? true ; false       end       def attach()         detach() if @@attached         Sketchup;;add_observer(self)       end       def detach()         Sketchup;;remove_observer(self)         @@attached = false       end       def initialize()         @fco = nil         @watched = []         @@attached = attach()         return self       end       def expectsStartupModelNotifications         return true       end       def frameChange(fromPage, toPage, percent_done)         # Actual code here.       end       def ignore_frames()         if @fco           Sketchup;;Pages;;remove_frame_change_observer(@fco)           @fco = nil         end         @watched.keep_if {|model| model.valid? rescue false }       end       def ignore_model(model)         @watched.delete(model)         ignore_frames() if model == Sketchup.active_model       end       def watch_frames(model)         ignore_frames() if @fco         @fco = Sketchup;;Pages;;add_frame_change_observer(self)         @watched << model unless @watched.include?(model)       end       def watching?(model)         @watched.include?(model)       end       # AppObserver Callbacks here can call the above methods.       def onActivateModel(model) # Mac only         if watching?(model)           watch_frames(model)         else           ignore_frames()         end       end       def onNewModel(model)         watch_frames(model)       end       def onOpenModel(model)         watch_frames(model)       end       def onQuit()         ignore_frames()       end       def onUnloadExtension(extension_name)         ignore_frames()       end     end # AppSpy     PluginSpy = AppSpy;;new unless AppSpy.attached?      end # extension module end # toplevel module  
  • Module depth: Good Practices

    5
    0 Votes
    5 Posts
    680 Views
    G
    I use a modified template that Dan Rathburn created. I also use his file naming convention for the loader etc. You could strip this down. But I like to place my plugins in a shared folder so I can test a single plugin on 6 versions of Sketchup SU7 through SU2016 require('extensions.rb') module YourCompany # Proprietary TopLevel Namespace; No Trespassing! module ThisPlugin # Namespace for THIS plugin # Create an entry in the Extension list that loads script called; # "gkware_doormaker_loader.rb" APP_VERSION = '1.0.1' @plugin = SketchupExtension.new('Company Plugin Description', File.join('PluginName', 'Company_PluginName_loader')) @plugin.creator = 'Your Name' @plugin.copyright = '(c)2013-2016 by YourCompany' @plugin.version = APP_VERSION @plugin.description = 'Plugin does something - optional url to your website' unless @plugin.class.method_defined?(;path) # # Define a singleton method for @plugin to access the @path attribute. # (... because the API did not do it in extensions.rb !!) # def @plugin.path() instance_variable_get(;@path) end end # unless # Create local path and filename constants; PATH = @plugin.path() LOADER_SUFFIX = '_loader' LOADER = File.basename(PATH) tmp = LOADER.split('_') RBSFILE = tmp[0] + '_' + tmp[1] + '.rbs' # RELDIR is relative to Plugins dir, OR the dir from # the $LOAD_PATH array that require used to find it. RELDIR = File.dirname(PATH) ROOT = $LOAD_PATH.find(false) do |abspath| Kernel.test(?d, File.join(abspath, RELDIR)) end if ROOT ABSDIR = File.join(ROOT, RELDIR) else # assume the target dir is directly below, the dir that THIS file is in. ABSDIR = File.join(File.dirname(__FILE__), RELDIR) end # Register this extension with the Sketchup;;ExtensionManager Sketchup.register_extension(@plugin, true) end # module YourCompany;;ThisPlugin end # module YourCompany
  • Object or No: Good Practices

    4
    0 Votes
    4 Posts
    538 Views
    G
    I've been coding all the way back to my assembler days (pre 1980). Various flavors of (Basic, Cobol, C, C++, Pascal, C#, Java), many database scripting languages such as (dBase, MSAcces, Paradox), other scripting languages such as javascript, jquery, PHP, Ruby, CSS, SQL. AWK, TCL ... I usually go with the flow. Borland built a very good library called the VCL (Visual Components Library), which makes use of an absolutely excellent object oriented set of classes. Easy to follow and very consistent stylisticly. This library is used by Delphi (object oriented pascal) and by C++ Builder. Microsoft built a terrible interface called MFC (Microsoft Foundation Classes). So when I had to use Microsoft for various early mobile devices I skipped it and used the Win API. With Sketchup I use a mix of both Classes (for tools) and simple reusable methods for helper functions. Even though I prefer using pointers with C, C++ etc. it just isn't possible with ruby (although under the hood most everything is passed as a reference). Having said all that - Ruby is quite good - although there are a few too many ways to do anything. This just means it is often a bit slower reading other code as the programmer often chooses a different way to do things. So I'm a bit more formal and like to use terse syntax where possible. ! instead of not, || instead of or, immediate if = ? :, parenthesis for all methods, lots of white space etc. For me it is all about readability so I can come back and speed read code I wrote months or years ago. But I do like some of Ruby's ways. "#{var}" the use of if after an assignment etc.
  • What is the safest 3d format?

    5
    0 Votes
    5 Posts
    698 Views
    deaneauD
    yes I will try... i would wish skp would be a format only visible in the viewer as suggestion SKV sketchup viewer file
  • Obtaining selected face vertices

    2
    0 Votes
    2 Posts
    653 Views
    Dan RathbunD
    @deanby7 said: I know I'm missing something basic here but trying to get the vertices of a selected face.... @mod = Sketchup.active_model > sel = @mod.selection > verts = sel.grep(Sketchup;;Face) {|f|f.vertices} > v = verts.position > Doesn't give me an array of 3d point values as expected? Interrogate the Ruby documentation for each method used. The Sketchup::Selection class (as well as most other API collection classes,) mix in the Enumerable library module. This is where grep() comes from. Enumerable#grep() http://ruby-doc.org/core-2.0.0/Enumerable.html#method-i-grep The grep() method always returns an array, either of the collection members matching the pattern, or the results of the block (if given.) It is similar to using a combination of find_all(), followed by map(). Your pattern was all Sketchup::Face objects, and you used a block which passed each face into the block in turn. Your block then called Sketchup::Face#vertices() upon each, which always returns an Array of Sketchup::Vertex objects. So at the very least, your verts reference could point to an empty array (if no faces were grep'ed, and therefore the block is never called.) If the collection does hold face references, there will be a nested array of vertices, for each face found. Now, there is a difference between a vertex and a point. Sketchup::Vertex objects are model entity objects (and subclass of Sketchup::Drawingelement, which is subclass of Sketchup::Entity.) Meaning they are entities that are saved within the model geometric database. They, in turn have a position property. Accessing that, returns a Geom::Point3d object, which in a virtual geometry "helper" object. Anyway, if you want points, then call position upon the vertices, within the block: point_arys = sel.grep(Sketchup;;Face) {|f| f.vertices.map{|v| v.position } } ... which now gives you an array of nested arrays of points (for each face.) Or, ... access the points in two steps: vert_arys = sel.grep(Sketchup;;Face) {|f| f.vertices } for face_verts in vert_arys face_points = face_verts.map {|v| v.position } # do something with the array of face_points end
  • Preventing add_curve curves exploding...

    3
    0 Votes
    3 Posts
    475 Views
    D
    I'll post the code here, because it's where I searched for a solution first and couldn't find one... [image: 8ARS_working_edges_centre.gif] I striped out the colouring but left the selection add, as a progress bar substitute... # with Tig's advice from PM ... model = Sketchup.active_model sel = model.selection ents = model.active_entities view = model.active_view mats = model.materials # cylindrical sine wave pair on a unit radius with 24 sides... wave = [[1.0, 0.0, 0.0], [0.9659258262890683, 0.25881904510252074, 0.050799999999999984], [0.8660254037844387, 0.49999999999999994, 0.08798818102449896], [0.7071067811865476, 0.7071067811865475, 0.1016], [0.5000000000000001, 0.8660254037844386, 0.08798818102449898], [0.25881904510252096, 0.9659258262890682, 0.05080000000000003], [6.123233995736766e-17, 1.0, 1.2442411479337108e-17], [-0.25881904510252063, 0.9659258262890683, -0.05079999999999998], [-0.4999999999999998, 0.8660254037844388, -0.08798818102449893], [-0.7071067811865475, 0.7071067811865476, -0.1016], [-0.8660254037844385, 0.5000000000000003, -0.087988181024499], [-0.9659258262890682, 0.258819045102521, -0.050800000000000047], [-1.0, 1.2246467991473532e-16, -2.4884822958674216e-17], [-0.9659258262890684, -0.25881904510252035, 0.05079999999999989], [-0.8660254037844388, -0.4999999999999998, 0.08798818102449892], [-0.7071067811865479, -0.7071067811865471, 0.1016], [-0.5000000000000004, -0.8660254037844384, 0.08798818102449903], [-0.25881904510252146, -0.9659258262890681, 0.05080000000000014], [-1.8369701987210297e-16, -1.0, 3.267705224142925e-17], [0.2588190451025203, -0.9659258262890684, -0.050799999999999915], [0.4999999999999993, -0.866025403784439, -0.08798818102449889], [0.7071067811865475, -0.7071067811865477, -0.1016], [0.8660254037844384, -0.5000000000000004, -0.08798818102449901], [0.9659258262890681, -0.2588190451025215, -0.05080000000000014], [1.0, 0.0, -0.0]] # waves have an additional point to complete the circle... segments = wave.length - 1 # single undo model.start_operation('wave') # Make the empty 'container' group. container = ents.add_group() cont_ents = container.entities # add the empty surf_grp() to cont_ents surf_grp = cont_ents.add_group() surf_ents = surf_grp.entities # Add Surface soft edges and faces using offset points... i = 0 segments.times do f = surf_ents.add_face(ORIGIN, wave[i], wave[i + 1]) view.refresh f.edges.each{|e| e.soft="true" e.smooth="true" sel.add(e) } i += 1 view.refresh end # add the wave to cont_ents... cont_ents.add_curve(wave) # and explode the surface faces... surf_grp.explode sel.clear model.commit_operation EDIT: after getting the other working using add_face I made a few adjustment to this code... john
  • Code to calculate Catenary curves?

    21
    0 Votes
    21 Posts
    6k Views
    Didier BurD
    Hi, Check this one by Aerilius: http://rhin.crai.archi.fr/rld/plugin_details.php?id=990
  • Observer or Event when Changing Model

    5
    0 Votes
    5 Posts
    533 Views
    fredo6F
    @dan rathbun said: But that was a bug in older SketchUp versions, wasn't it ? I remember it happened when saving the model (most often.) But I thought it was fixed. Maybe, although I am not sure. But as you know, supporting older versions is also a requirement, so that, as long as the old tricks work, you finally leave it as it is. Fredo
  • From AutoLisp to Ruby

    14
    0 Votes
    14 Posts
    2k Views
    Dan RathbunD
    @deanby7 said: I'm running Version 8 Sketchup. ... which runs Ruby v1.8.6-p287 on PC, and v1.8.5-p0 on OSX. @deanby7 said: I'm getting an error.... Error: #<NoMethodError: private methodclass_variable_get' called for SaM::Pick_Points:Class>` For some reason Ruby 1.8 had made class_variable_get() and class_variable_set() to be private methods. In SketchUp v14+ using Ruby 2.0+, they were changed to be public methods.
  • Assigning a default material.

    6
    0 Votes
    6 Posts
    1k Views
    Dan RathbunD
    @tig said: Another way to set it by ' display_name' [i.e. what you can read] would be... mats = model.materials name = 'Brick_Antique' mat = nil mats.each{|m| if m.display_name == name mat = m break end } oface.material = mat Still another way: mats = model.materials name = 'Brick_Antique' mat = mats.find {|m| m.display_name == name } oface.material = mat
  • Volume of Multiple Groups

    13
    0 Votes
    13 Posts
    4k Views
    F
    Thankyou Dan!

Advertisement