sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Minimum dimension of a component

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 662 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D Offline
      Deanby7
      last edited by

      I'm trying to ascertain the smallest edge at the origin of a component. I think I'm nearly there but something's not right in the code below! Any suggestions would be appreciated : )
      sel.grep(Sketchup::ComponentInstance){|cdi| org = cdi.transformation.origin cents = cdi.definition.entities vert = [0] cents.grep(Sketchup::Vertex).each{|v| vert << v if v == org } thickness = vert.edges.min p thickness }

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        @deanby7 said:

        I'm trying to ascertain the smallest edge at the origin of a component. I think I'm nearly there but something's not right in the code below! Any suggestions would be appreciated : )
        sel.grep(Sketchup::ComponentInstance){|cdi| org = cdi.transformation.origin cents = cdi.definition.entities vert = [0] cents.grep(Sketchup::Vertex).each{|v| vert << v if v == org } thickness = vert.edges.min p thickness }

        Don't think Sketchup::Vertex is "searchable" also, it is not a valid comparison for a Vertex and a Point3d, you need to compare the transformed Vertex.position.

        Here is my solution

        mod = Sketchup.active_model
        sel = mod.selection
        sel.grep(Sketchup;;ComponentInstance){|cdi|
          org = cdi.transformation.origin
          cents = cdi.definition.entities
          trn = cdi.transformation; vert = nil
          cents.grep(Sketchup;;Edge){|e|
            e.vertices.each{|v| vpt=v.position.transform(trn)
            vert = v if vpt == org; }
          }
          unless vert==nil
            thickness = 1e9
            vert.edges.each{|e|
              thickness = [thickness,e.length].min
            }
            puts "Thickness of #{cdi.definition.name} is #{thickness}"
          end
        }
        
        

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • D Offline
          Deanby7
          last edited by

          Many thanks. Works a treat.

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            My solution:

            def thickness(obj)
              ents =( obj.definition.entities rescue obj.entities )
              tran =( obj.transformation rescue IDENTITY )
              edges = ents.grep(Sketchup;;Edge).find_all {|e| 
                e.start.position == ORIGIN || e.end.position == ORIGIN
              }
              if edges.size < 3
                return 0.to_l # not a 3D object or edges array empty
              end
              shortest = edges.min_by {|e| e.length }
              shortest.start.position.transform(tran).distance(
                shortest.end.position.transform(tran)
              )
            end
            
            

            This should work with an argument that is a definition, group or component instance.

            If a ComponentDefinition is passed, the transform will be the IDENTITY transform, otherwise an instance or group will be it's transform (which also might be == IDENTITY.)

            Within the entities the local origin is == ORIGIN, so there is no need to create any temporary point object for comparison, just to select the 3 edges.

            Once we have the shortest (untransformed) edge, we apply the transformation to both it's vertex positions, to account for any rotation and scaling (either uniform or not.)

            Now, this assumes that the shortest definition edge is always to be considered the thickness, even in the instances.

            But what if someone does non-uniform scaling and makes one of the longer edges shorter than the one that is supposed to be the shortest ?

            I suppose, if you control the definitions, you could attach an attribute to the "thickness" edge, and find it by attribute.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement