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

    Posts

    Recent Best Controversial
    • OnUserText

      I have several custom tools that implement the onUserText callback, and they work correctly. If the user keys in text, I get it and can process it. But I am working on a new tool, and tried to implement onUserText the same way as in other tools, and for some reason it is not working. I put a simple "puts text" in the onUserText method, and it doesn't get called. Is there any kind of known problem that would cause this? Maybe some combination of settings that causes it not to work? I thought I saw something about this on a SU blog somewhere, but I can't find it now.

      Thanks for any help

      posted in Developers' Forum
      S
      spring.freediver
    • Model Hierarchy

      I don't know if something like this has been posted before. If so, here's yet another one:

      This script prints a diagram of the model hierarchy to the Ruby Console.

      TIG and Thomas: line 46 of the script is to compensate for instance names being blank. The reason I though there was a bug is that in the Outliner window, the instance has a name.

      Thomas: Can you try this on a model that has the Group.parent bug in it? I wasn't sure if I needed to use the real_parent work-around since this is traversing the hierarchy as instances rather than groups.

      
      require 'sketchup.rb'
      
      if (not file_loaded?("PrintHierarchy.rb"))
          UI.menu("Plugins").add_item("PrintHierarchy") { printHierarchy  }
      end
      file_loaded("PrintHierarchy.rb")
      
      def printHierarchy
         answer = UI.messagebox("Print Hierarchy to Ruby Console?", MB_YESNO)
         if (answer == 6)
            model = Sketchup.active_model
            #Sketchup.send_action "showRubyPanel;"
            h = ModelHierarchy.new(model)
            h.pdint(model)
            print("-------------------------------------------\n")
         end
      end
      
      class ModelHierarchy
      # Class to hold the model hierarchy, and example method to print diagram
      # Jeff RIchardson, October 2010
         attr_accessor ;definition, ;children, ;polygons
      
         def initialize(model)
            @definition = {}
            @children = {}
            @polygons = {}
            
            model.definitions.each do |comp|
               @polygons[comp] = 0
               comp.entities.each {|e| @polygons[comp] += 1 if (e.is_a?(Sketchup;;Face))}
               comp.instances.each do |inst|
                  @definition[inst] = comp
                  parent = inst.parent
                  @children[parent] = [] if (!@children.has_key?(parent))
                  @children[parent].push(inst)
               end
            end
         end
         
         def pdint(key, level=0)
            printf("Model %s [%d polygons]\n", key.title, key.number_faces) if (key.is_a?(Sketchup;;Model))
            if (@children.has_key?(key))
               @children[key].each do |k|
                  name = k.name
                  name = sprintf("Instance of %s", @definition[k].name) if (name.empty?)
                  print("|   "*level)
                  printf("|---%s(%s) [%d polygons]\n", name, k.typename, @polygons[@definition[k]])
                  pdint(@definition[k], level+1)
               end
            end
         end
         
      end
      
      
      posted in Developers' Forum
      S
      spring.freediver
    • RE: Entity.parent gives wrong type

      Yes, but the Instance.name method is returning an empty string. The Definition.name method returns a name like "Group#5".

      This code is traversing the model hierarchy. For most groups and instances, it gets the correct name. But for one particular group, the name method returns an empty string. That is why I thought it might be a known bug.

      posted in Developers' Forum
      S
      spring.freediver
    • RE: Entity.parent gives wrong type

      I have also noticed that the Instance.name method sometimes returns an empty string. In the outliner, I see the correct name, but when I traverse the instances in Ruby, and print out each instances name, I get a blank string for one of the groups. And I get the blank string whether I refer to it as an instance or a group (I assume that calls to Group.name and Instance name are actually the same.)

      Is this a known bug? Is there any kind of work-around?

      posted in Developers' Forum
      S
      spring.freediver
    • RE: Entity.parent gives wrong type

      Wow, that is even stranger. Especially the part about changing a group in Ruby is different that changing one in Sketchup.

      Before I read your post, I had written a script to loop through the model.definitions and report how many instances each had. I saw that after copying a group, the corresponding definition had multiple instances. But then I changed the geometry of each of the copies, and re-wrote the definition list. There were now separate definitions for each of the copies, with one instance each. So Sketchup does the "make unique" as soon as it sees you make a change to one of the copies of a group.

      So it seems that Sketchup really doesn't have a unique entity that is a group. It just has component definitions and instances, and a special flag on the definition that says to make it "act" like a group. And if any instances of the definition get changed (interactively), it makes a new definition and instance, so it is still just another component with a "group" flag on it.

      posted in Developers' Forum
      S
      spring.freediver
    • RE: Entity.parent gives wrong type

      Thomas,

      Your description that group component definitions can have multiple instances does not make sense to me. I think that when you make copies of a group, each copy has it's own definition. That is what allows you to change the geometry in one copy, and the change is not seen in the other copies. Each group has it's own set of entities.

      But with components, there are multiple instances that refer to a single component definition, and share a set of entities. So if you change any of the entities in the component definition, the change is seen in all of the instances.

      That is why it surprised me to learn that groups are actually component instances inside the Sketchup model. But I assumed that meant that they are "special" components that can only have one instance. And the group? method tells you that this is the case. If group? is false, then it is a "normal" component, which can have multiple instances, which led to my question about how to figure out which instance a given entity came from. I am starting to believe that it is not possible to tell if you only have an entity address, and that is why you must use a PickHelper.

      Thanks again for your help... You are truely a Sketchup Pro

      posted in Developers' Forum
      S
      spring.freediver
    • RE: Entity.parent gives wrong type

      TIG,

      If I get a face (or edge) from an inputpoint, and see that it's parent is a ComponentDefinition, I can use parent.group? to see if it is actually a group, and then know that there is only one instance, in parent.instances[0].

      But, if parent.group? is false, I then know that it really is a component, and there may be multiple instances. Is there a way to find out which instance the selected face came from, and therefore what transformation needs to be applied? Is this a case where the PickHelper must be used because it is the only way to get the information?

      posted in Developers' Forum
      S
      spring.freediver
    • RE: Entity.parent gives wrong type

      Thanks Thomas, that's very helpful.

      I've seen several scripts lately with a reload method. That seems like a good idea too. What calls the reload? Do you have some sort of "master" script that calls the various reloads?

      posted in Developers' Forum
      S
      spring.freediver
    • RE: Entity.parent gives wrong type

      Thomas,

      Does the PickHelper.transformation_at give the tranformation to transform back to model coordinates, or do you have to apply the transforms for each level?

      posted in Developers' Forum
      S
      spring.freediver
    • RE: State of Observers — 28 February 2010

      Does the View.remove_observer method work in SU7.1?

      I have a tool that needs to turn a ViewObserver on and off.

      In tool methods that receive a view argument:
      I use "@observer = view.add_observer(MyViewObserver.new)" to turn it on;
      and "view.remove_observer(@observer)" to turn it off.

      view.remove_observer returns false, and the observer is not removed.

      I tried changing @observer to a class variable (@@observer), and it still did not work.

      Any ideas?

      posted in Developers' Forum
      S
      spring.freediver
    • RE: Entity.parent gives wrong type

      Thanks very much guys. I didn't know that groups were actually components. Nor that the group? method existed.

      posted in Developers' Forum
      S
      spring.freediver
    • Entity.parent gives wrong type

      Is there a known bug with the Entity.parent method (in SU7.1)?

      I use the InputPoint.face method to get the face a user picks, then the face.parent method to get the Group the face is in. But the API returns a Sketchup::ComponentDefinition object rather than a Group. I am sure that the face I am selecting is in a Group, not a Component. In fact, my model has no components at all.

      AM I doing this wrong?

      posted in Developers' Forum
      S
      spring.freediver
    • RE: Trouble with .position_material method

      It should be in most Computer Graphics books, and some online. I'm an old guy, the book I use was published in 1976 and is now out of print.

      posted in Developers' Forum
      S
      spring.freediver
    • RE: Ruby system call

      Yes, that works. Thanks Jim.

      posted in Developers' Forum
      S
      spring.freediver
    • RE: Ruby system call

      Tom,

      To set the command path, I use the $: system variable to get a path to the Plugins directory, and then tack on the rest of the path to the executable. No special characters. Before doing the system call, I print out both the cmd and file strings, and they look correct.

      Jim,

      The backquotes I am using are supposed to run the command in the quotes, and return the command output as a string. I wanted that returned string to go to a messagebox, which it did... the error message I showed in my original post.

      Thanks for the help.
      Any more suggestions?

      posted in Developers' Forum
      S
      spring.freediver
    • Ruby system call

      Does the system function work in SketchUp Ruby?

      Any tips on how to use it?

      I am passing in two args, the full path to a .exe file (cmd), and the full path to a file I want the executable to process (file). I get nothing.

      I also tried (UI.messagebox cmd file, using the backtick syntax, but it interpreted the arguments literally, saying:

      Error: #<Errno::ENOENT: No such file or directory - cmd file>

      Do I need to use some special quoting technique?

      Thanks,
      Jeff

      posted in Developers' Forum
      S
      spring.freediver
    • RE: Trouble with .position_material method

      Hey Tom.

      This is "jeff99" from the Beta forums. I followed your link to this thread and was reviewing the discussions here. I wish I had seen this a few days ago!

      Thanks again for your observations regarding this. You are very tenacious at attacking a problem!

      By the way, the "H" is for "Homogeneous", not "Height". Although it can be thought of as a scale factor.

      posted in Developers' Forum
      S
      spring.freediver
    • Problem with UVHelper

      When I try to experiment with UVHelper using this code"
      ` require 'sketchup.rb'

      def uvhelp

      face=Sketchup.active_model.selection[0]
      
      tw = Sketchup::TextureWriter.new
      uvHelp = face.get_UVHelper true, true, tw
      pts = []
      i = 0
      face.outer_loop.vertices.each do |vert|
        pts[i] = vert.position
        pts[i+1] = uvHelp.get_front_UVQ(vert.position)
        i = i+2
      end
      prompt = ["P1","UV1",
            "P2","UV2",
            "P3","UV3",
            "P4","UV4"]
      defaults = [pts[0], pts[1], pts[2], pts[3], pts[4], pts[5], pts[6], pts[7]]
      results = inputbox prompt, defaults, name
      

      end

      if( not file_loaded?("UVHelper.rb") )
      UI.menu("Plugins").add_item($exStrings.GetString("UVHelper")) { uvhelp }
      end
      file_loaded("UVHelper.rb")`

      I get this error message:
      Error: #<TypeError: wrong argument type (expected Sketchup::TextureWriter)>
      C:/Program Files/Google/Google SketchUp 6/Plugins/UVHelper.rb:8:in get_UVHelper' C:/Program Files/Google/Google SketchUp 6/Plugins/UVHelper.rb:8:in uvhelp'
      C:/Program Files/Google/Google SketchUp 6/Plugins/UVHelper.rb:26
      C:/Program Files/Google/Google SketchUp 6/Plugins/UVHelper.rb:26:in `call'

      It doesn't even like the call to face.get_UVHelper, which is straight from the examples.

      posted in Developers' Forum
      S
      spring.freediver
    • 1 / 1