sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Whats these code mean?

    Scheduled Pinned Locked Moved Plugins
    4 Posts 3 Posters 339 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.
    • H Offline
      hebeijianke
      last edited by

      #requires face or faces within a selected group or number of groups
      require 'sketchup.rb'
      class Crack
      	def Crack;;groups
      	  # get the active model
      	  model = Sketchup.active_model
      	  #get currently selected objects
      	  selection_set = model.selection
      		cracks = 0
      		stepbystep = UI.messagebox "Exclude random faces from cracking?", MB_YESNOCANCEL, "Proceed"	#use to validate each face before its drawn
      		if stepbystep == 2
      			return nil
      		end
      		Sketchup.active_model.start_operation "Crack groups"
      		# loop through all the selected faces, and triangulate them
      		selection_set.each {|group|
      			#selection_set.remove group
      			if group.typename == "Group" then
      				maxcracks = group.entities.count * 2
      				group.entities.each {|entity|
      					if cracks > maxcracks then
      						return nil
      					end
      					entities = group.entities
      					if entity.typename == "Face" then #to crack a triangle
      						# get all the vertices for the current face
      						vertices = entity.vertices
      						# find the centroid - equals the average of all vertices, so lets add all coordinates together to divide it
      						centerx = 0
      						centery = 0
      						centerz = 0				
      						0.upto(vertices.length-1) do |vert|
      							centerx = centerx + (vertices[vert].position[0]/vertices.length)
      							centery = centery + (vertices[vert].position[1]/vertices.length)
      							centerz = centerz + (vertices[vert].position[2]/vertices.length)
      						end
      						geomcen = Geom;;Point3d.new(centerx,centery,centerz)
      						#prepare the randomly excluded face crack
      						random_exclusion = rand(vertices.length-1)
      						# insert the edges
      						0.upto(vertices.length-1) do |vindex|
      							if vindex != random_exclusion or stepbystep == 7 then
      								edge = entities.add_edges geomcen,vertices[vindex]
      								cracks = cracks + 1
      							end
      						end
      					end
      				}
      			end
      		}
      		Sketchup.active_model.commit_operation
      	end #def
      end #class
      if( not $cracking_menu_loaded )
        UI.menu("Plugins").add_item("Polygon Cracking") { Crack.groups }
      end
      
      
      
      
      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        Where did you get the code?
        It is unattributed...
        If the whole of the code were in a file called say CrackGroup.rb inside the Plugins folder then it would load.
        The code makes a class 'Crack' def 'group' that 'cracks' faces inside selected groups.
        It adds a new Plugins menu item [NB: it needs to declare the menu is loaded as a last line...] called 'Polygon Cracking'.
        This takes all faces [or all-random_few] in a selected group and 'cracks' them - i.e. if finds the face's center and draws extra edges out to vertices as if the face is 'cracked' [glass etc] - the number of 'cracks' is randomized to a limited extent but that is set to be the same on every face in the group [it could be made random for all of the faces ?].
        It runs its 'cracks' over any nested faces and any 'holes' or reentrant areas [e.g. with L's] in faces.
        It screws up its face divisions because it is written so it affects the very 'entities' it's iterating through and trips itself up - unless that's intentional it is readily fixed by using group.entities.to_a.each{... instead of group.entities.each{... so the added entities aren't considered in the set that's getting processed...
        What is it for ??

        TIG

        1 Reply Last reply Reply Quote 0
        • H Offline
          hebeijianke
          last edited by

          THX
          I got a plugin named Tooling
          It's in The Tooling file
          I upload it


          Tooling.rar

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            The code finds the geometric center of a Face, then adds some Edges from the center to the outside vertexes. "Crack" means break, shatter, fracture, subdivide.

            Hi

            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