#----------------------------------------------------------------------------- # # Copyright 2005, CptanPanic # Heavily Based on ComponentReporter.rb, Copyright 2005, TIG # # Permission to use, copy, modify, and distribute this software for # any purpose and without fee is hereby granted, provided something the above # copyright notice appear in all copies. # # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # #----------------------------------------------------------------------------- # # Name : CutList.rb # # Type : Tool # # Description : Makes a cutlist based on all components in mode. # # Menu Item : Plugins -> Generate CutList # Context-Menu: None # # Author : CptanPanic # # Usage : Call script using Plugins menu, and file name *-CutList.cvs is created in the model's # folder. It is readable by text editors, and cutlist programs like CutList Plus. # # Date : December 2005 # # Version : 1.0 Initial Release. # #----------------------------------------------------------------------------- require 'sketchup.rb' ### do class class Reporter ### do def def Reporter::components model = Sketchup.active_model ### start undo... model.start_operation "undo" entities = model.entities mname = model.title ### show VCB and status info... Sketchup::set_status_text(("CUTLIST PLUS..." ), SB_PROMPT) Sketchup::set_status_text(" ", SB_VCB_LABEL) Sketchup::set_status_text(" ", SB_VCB_VALUE) ### check model... mpath = Dir::pwd if mpath == "" UI.beep UI.messagebox("You must save the 'Untitled' new model \nbefore making a Component Report !\nExiting... ") return nil end ### setup list... clist = [] for c in model.definitions if c.count_instances > 0 and c.group? != true ###v1.3 boundingBox = c.bounds dims = [ boundingBox.height, boundingBox.width, boundingBox.depth ] dims.sort! clist = clist.push([c.name, c.count_instances.to_s, dims[0].to_s, dims[1].to_s, dims[2].to_s]) end#if end#for c clist = clist.sort ### ### if no components exit... if not clist[0] UI.beep UI.messagebox("No Components available to make a Component Report !\nExiting... ") return nil end#if ### ### write to csv file... namecsv = mpath + "/" + mname + "-CutList.csv" file = File.new(namecsv,"w") file.puts("Part #,Description,Copies,Thick,Width,Length\n") ### title i = 1 for c in clist file.puts(i.to_s+","+c[0]+","+c[1]+","+c[2]+","+c[3]+","+c[4]) i = i + 1 end#for c file.close UI.messagebox("CutList written into: \n\n" + namecsv + "\n") ### ### commit undo... model.commit_operation end#def components end#class ### do menu if( not file_loaded?("CutList.rb") ) add_separator_to_menu("Plugins") UI.menu("Plugins").add_item("Generate CutList") { Reporter.components } end#if file_loaded("ComponentReporter.rb") ###