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

    Posts

    Recent Best Controversial
    • RE: How to make a component-placer tool?

      Hmm, I suppose I could distribute a component library with my plugin and allow users to use the built-in component panel. I could observe the definition so that I can hook into when it's placed, but I won't know when they BEGIN to place it.

      It seems to me that writing a custom tool for this would be difficult. Someone please tell me I wouldn't have to use onMouseMove to make the component follow the cursor while being placed!

      posted in Developers' Forum
      D
      draftomatic
    • How to make a component-placer tool?

      I need to write a simple plugin that will allow a user to place a pre-defined object in the same way they can place one from the Components panel.

      So, user clicks my menu item, my component appears on their cursor, they decide where to place it, click, and then it's in the model. I'll want to do some behind-the-scenes processing before and after, naturally.

      Can someone give me advice on this? I've never made Tool's before... is that what I need here?

      posted in Developers' Forum
      D
      draftomatic
    • RE: How to store an Entity between sessions?

      Thanks TIG πŸ˜ƒ

      posted in Developers' Forum
      D
      draftomatic
    • RE: How to store an Entity between sessions?

      @tig said:

      You have to give the entity an enduring attribute like a 'guid' based on say Time.now.to_f+rand ...
      As it's a group you can iterate all definitions using .group? and break once you have a match...

      Yea, I've done this in the past... number of groups should be WAY less than number of entities. Sure there's no other way?

      posted in Developers' Forum
      D
      draftomatic
    • RE: How to store an Entity between sessions?

      Hmm I suppose since I will be grouping the Entity, I could iterate all the groups in the model to find it... less intense than iterating entities, but still not ideal...

      This seems like it must be a common problem. Plugins will inevitably have special geometry that they want to tag and keep track of. Some of the messier models I've worked with have been >100MB and iterating model.entities isn't acceptable.

      posted in Developers' Forum
      D
      draftomatic
    • RE: How to store an Entity between sessions?

      @jim said:

      Using Attributes is about the only way - what isn't working about them?

      m = Sketchup.active_model
        #<Sketchup;;Model;0xdc02f80>
      m.set_attribute("mydict", "mykey", m.selection[0])
        #<Sketchup;;Face;0xe286438>
      m.get_attribute("mydict", "mykey")
        nil
      
      posted in Developers' Forum
      D
      draftomatic
    • How to store an Entity between sessions?

      I would like to be able to store an entity or a reference to an entity between sessions, and retrieve the entity quickly (i.e. without iterating every entity in the model). Is there a way? Entity.entityID doesn't last between sessions, and placing entities in attribute dictionaries isn't working for me.

      posted in Developers' Forum
      D
      draftomatic
    • RE: Is there a plugin to draw face normals?

      Oh and also I just wanted a line coming out one side of the face. Easy enough by changing line 108 to:
      pt2 = bary

      posted in Plugins
      D
      draftomatic
    • RE: Is there a plugin to draw face normals?

      Wow, thanks Fredo! This is exactly what I needed.

      Can I tear your code apart and put it in mine? My plugin is free but will be packaged with commercial software. You have a disclaimer at the top but I don't see any explicit copyright notice. It also looks like you copied the header from some other code. I'll be happy to include any copyright information in my code, but maybe you want to update what's currently there?

      Thanks again!

      posted in Plugins
      D
      draftomatic
    • Is there a plugin to draw face normals?

      Seems like someone must have done this before. I need an edge drawn on a face to display its normal, preferably at the centroid.

      Oh, and arbitrary faces! Any orientation in space, possibly concave, with holes. πŸ˜ƒ

      posted in Plugins
      D
      draftomatic
    • RE: Best way to get all Face's in model?

      One more question - I see you're messing with a transformation - if I ask a nested instance for, say, it's Face's vertices locations (assuming it's just a rectangle or something simple), will it give me the (globally) correct coordinates, or something relative to the Component's origin?

      I guess ComponentDefinitions have entities, so I can ask for their locations. But ComponentInstances are transformed somewhere... I don't have much experience with transformations...

      EDIT: Ah nevermind, I see now that you're carrying the transformation through each nesting of an instance. Gotcha.

      Thanks again Tom

      posted in Developers' Forum
      D
      draftomatic
    • RE: Best way to get all Face's in model?

      😍 😍 😍 😍

      face_count_diff_works.JPG

      Your code had a few lil typos; this one works:

        def process_model()
          return walk_faces( Sketchup.active_model.entities )
        end
      
        def walk_faces( entities, transformation = Geom;;Transformation.new )
          faces = []
          entities.each { |e|
            if e.is_a?( Sketchup;;Face )
              faces << e
            elsif e.is_a?( Sketchup;;Group )
              faces.concat( walk_faces( e.entities, transformation * e.transformation ) )
            elsif e.is_a?( Sketchup;;ComponentInstance )
              faces.concat( walk_faces( e.definition.entities, transformation * e.transformation ) )
            end
          }
          return faces
        end
      

      Thanks Tom, you're the best!

      posted in Developers' Forum
      D
      draftomatic
    • RE: Best way to get all Face's in model?

      Closer, but still not working:

      face_count_diff2.JPG

      Here's the get_face_count() method I'm using:

        def get_face_count()
          count = 0
          @model.entities.each { |e|
            if (e.is_a?(Sketchup;;Face))
              count +=1
            end
          }
          
          @model.definitions.each { |d|
            next if d.image?
            next if d.count_instances == 0
            count += d.entities.select { |e|
              e.is_a?(Sketchup;;Face)
            }.length * d.count_instances
          }
          return count
        end
      
      posted in Developers' Forum
      D
      draftomatic
    • RE: Best way to get all Face's in model?

      @thomthom said:

      @draftomatic said:

      Bah, I should've realized the instances issue... So your code in the 2nd post isn't quite right πŸ˜ƒ

      It depends what you do with it...
      If you need to count the faces you need to take into account all instances.

      But if you need to just iterate over all faces you only need to process model.entities and the entities of each definition, even if a definition has multiple instances, a face in that definition is the same in each instance. It just exist in multiple locations.

      As you saw a few minutes ago, I'm writing an exporter, and it doesn't keep Component information. I need every Face.

      posted in Developers' Forum
      D
      draftomatic
    • RE: Best way to get all Face's in model?

      @thomthom said:

      Oh, wait - you actually need arrays of all the face entities?

      Well, I really just needed to iterate through all the Faces in the model... the array thing is just useful for testing.

      Bah, I should've realized the instances issue... So your code in the 2nd post isn't quite right πŸ˜ƒ

      posted in Developers' Forum
      D
      draftomatic
    • RE: Best way to get all Face's in model?

      @exvion said:

      This code work:

       model = Sketchup.active_model
      >     faces = []
      >     faces.concat( model.entities.select{|e| e.is_a?( Sketchup;;Face ) }    )
      >     model.definitions.each { |d|
      >       next if d.image?
      >       faces.concat( d.entities.select{|e| e.is_a?( Sketchup;;Face ) } )
      >     }
      

      It doesn't seem to be working for me. I put it as a method called get_face_array() inside a class called Tester:
      face_count_diff.JPG

      This is a 68.2MB model.

      posted in Developers' Forum
      D
      draftomatic
    • RE: Recursive print_group_tree() help

      @honoluludesktop said:

      Tom, didn't know that a method can call itself. Boy I've got a lot to learn. What happens to the variables? Guess they are they recreated each time the method is called.

      Look up "Recursion" =). Each call has its own scope.

      Link Preview Image
      Recursion (computer science) - Wikipedia

      favicon

      (en.wikipedia.org)

      One of the best examples is computing the Fibonacci sequence.

      posted in Developers' Forum
      D
      draftomatic
    • RE: Recursive print_group_tree() help

      @thomthom said:

      I mean, the code traverses the model tree, but from the code I don't see any reason to do a tree traversal. A flat traversal of model.definitions would be the same?

      I'm writing an XML exporter that exports the Group tree along with the rest of the model... XML = tree.

      Obviously my real code is doing more than just printing names. But it's top-secret! πŸ˜ƒ

      posted in Developers' Forum
      D
      draftomatic
    • RE: Recursive print_group_tree() help

      Thanks thomthom... is this better?

        def print_group_tree()
          @model.entities.each { |e|
            if (e.is_a?(Sketchup;;Group))
                puts e.name
                recurse_group(e)
            end
          }
        end
        
        def recurse_group(group)
          group.entities.each { |e|
            next unless e.is_a?(Sketchup;;Group)
            puts e.name
            recurse_group(e)
          }
        end
      
      posted in Developers' Forum
      D
      draftomatic
    • RE: Recursive print_group_tree() help

      @thomthom said:

      1. You're getting a tree of the entities in a model - would it not be better to start with model.entities instead of scanning model.definitions for instances with parent that is model?

      Seems wasteful to iterate all of the entities when all I want is the Group tree. There will normally be less Definitions/Groups than Entities, no?

      @unknownuser said:

      1. Your code makes the assumption that all instances has instances, this might not be the case.

      What if I purge the model before I run this code?

      @model.definitions.purge_unused
      

      @unknownuser said:

      1. You can not assume groups are all unique - group definitions often has group instances. At least from what I observe from the models at our office and the warehouse.

      I'm using this routine to make all Groups unique before I run this code:

      
          @model.definitions.each { |d|
            if (d.group?())
              d.instances.each { |i|
                i.make_unique
              }
            end
          }
      
      
      posted in Developers' Forum
      D
      draftomatic
    • 1 / 1