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

[Plugin] ComponentReporter++ v1.2

Scheduled Pinned Locked Moved Plugins
71 Posts 22 Posters 62.5k Views 22 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.
  • T Offline
    TIG Moderator
    last edited by 23 Jan 2012, 11:03

    IF you want to use the nested component containing the linear info then you can readily add extra code into another column in the CSV. OR make a separate CSV report on linear info.
    Here's how to do it separately.
    The tool runs***, its code finds all components in the model with instances having a name containing 'hedge' and thereby their nested component giving the linear info drawn as a line or curve.
    It takes all edges in this nested component and totals their length.
    It writes a CSV listing the instance-name [e.g. 'c.hedge'], instance's-layer, definition-name, linear total [in meters]
    Sorted in order, with a header line and a total of the minear-meterage.
    Copy/paste this whole set of code into a new file [Notepad.exe] that you make in the Plugins folder named ' TIG-hedgelengths.rb'

    require 'sketchup.rb'
    module TIG
     ###
     unless file_loaded?(File.basename(__FILE__))
       UI.menu("Plugins").add_item("Hedges Length CSV"){self.hedgelengths()}
     end
     file_loaded(File.basename(__FILE__))
     ###
     def self.hedgelengths()
      model=Sketchup.active_model
      if model.path.empty?
        dir=Dir.pwd
    	tit="Untitled"
      else
        dir=File.dirname(model.path)
    	tit=model.title
      end
      ###
      rows=[]
      model.definitions.each{|d|
        next if d.group? or d.image?
    	d.instances.each{|i|
    	  txt=""
    	  if i.name=~/[Hh]edge/
    		txt << i.name+","
    		txt << i.layer.name+","
    		txt << d.name+","
    		lin=0
    		d.entities.each{|c|
    		  if c.class==Sketchup;;ComponentInstance
    		    c.definition.entities.each{|e|
    			  if e.class==Sketchup;;Edge
    			    lin+=e.length
    			  end
    			}
    		  end
    		}
    		txt << sprintf("%.3f", lin.to_m) ### 3d.p.
    	  end
    	  rows << txt
    	}
      }
      rows.dup.each{|e| rows.delete(e) if e.empty? }
      rows.sort!
      ## add total
      rows=["INST-NAME,INST-LAYER,DEFN,LIN.METERS"]+rows
      tot=rows.length.to_s
      rows << "\n,,TOTAL,=SUM(D2;D#{tot})"
      ###
      csv=File.join(dir, tit+"_HedgesLength.csv").tr("\\","/")
      ###
      begin
         file=File.open(csv,"w")
      rescue### trap if open
         UI.messagebox("Report;\n\n  "+csv+"\n\nCannot be written - it's probably already open.\nClose it and try making the Report again...\n\nExiting...")
    	 return nil
      end
      ###
      rows.each{|row| file.puts(row) }
      file.close
      ###
      UI.messagebox("Report;\n"+csv+"\nWritten.")
      UI.openURL("file;///"+csv)
      ###
     end
    end
    

    ***Usage: either type TIG.hedgelengths in the Ruby Console... OR more easily use the Plugins menu item...

    TIG

    1 Reply Last reply Reply Quote 0
    • U Offline
      unearthed
      last edited by 23 Jan 2012, 21:49

      Thanks TIG, that's simply amazing Elegant and simple.

      Now thanks to your plugins I've got the basis for a complete plant counter (areas, individual plants and hedges and shelterbelts - Sketchup has just become a LOT more useful), thanks again.


      output from TIG-hedge.lengths.rb

      Growplan - People ∩ Plants ∩ Place

      windows 7 64b, 4GB RAM, SU 8.0.16846
      Gimp, QGIS, Vectorworks 12, Bricscad 11

      1 Reply Last reply Reply Quote 0
      • S Offline
        samyell77
        last edited by 29 Feb 2012, 17:15

        Hi Tig,
        Great plugin - thanks. Ive used this on several jobs now and wonder if you can help me to make a few tweaks. I've been trying to use this to count components in a selection. I know that the plugin exports 3 csv documents and was wondering if you can help me to tailor the script to get the count Im after - Im afraid Im a total noob to Ruby but am more than happy to have a play with it if you can offer a little advice.

        Id like to be able to generate a count for eithera whole model or for a selection within the model. I know that the script already generates a count for a selection but I'd like to be able to summarize items with the same name -giving me a total number.

        I also wonder if its possible to only display the component name and the count and none of the other information (guid, description, material etc). Im trying to reduce the amount of work I need to do to tidy up the csv files that are generated.

        Ive been playing with this whenever I get some spare time but would love a little advice.

        Any help much appreciated.

        Thanks

        Sam

        SU Pro 2016
        Dell Precision M4800
        PC Windows 10
        Intel Core i7-4900MQ @ 2.80ghz
        Nvidia Quadro K2100M
        16gb RAM

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 8 Oct 2012, 12:19

          Here's v1.2 made MAC compatible... http://sketchucation.com/forums/viewtopic.php?p=147658#p147658

          TIG

          1 Reply Last reply Reply Quote 0
          • S Offline
            sidpickle
            last edited by 22 Oct 2012, 16:55

            Thanks TIG seems to work OK. I'll have a play with it.

            Ted Robbens

            1 Reply Last reply Reply Quote 0
            • Q Offline
              quarch
              last edited by 6 Jan 2013, 14:04

              Unfortunately I am having errors in counts for nested components...
              example...
              3 component 1 in model
              1 component 2 inside component 1...

              Report returns 3 counts of 1 and 1 count of 2 in stead of 3 counts of 1 and 3 counts of 2

              Counts in instances report are correct.

              1 Reply Last reply Reply Quote 0
              • T Offline
                TIG Moderator
                last edited by 6 Jan 2013, 18:53

                @quarch said:

                Unfortunately I am having errors in counts for nested components...
                example...
                3 component 1 in model
                1 component 2 inside component 1...
                Report returns 3 counts of 1 and 1 count of 2 in stead of 3 counts of 1 and 3 counts of 2
                Counts in instances report are correct.
                There ARE 3 instances of compo1.
                There IS 1 instance of compo2.
                You might 'see' 3 of compo2, but these are actually three representations on the same object.
                The different reporting formats are a way of covering various bases...

                If you want it to somehow report things differently, then rework the code as you wish...
                It is 'open source' after all... 😒

                TIG

                1 Reply Last reply Reply Quote 0
                • O Offline
                  Omarian
                  last edited by 4 Apr 2013, 07:53

                  TIG,

                  This is similar to a problem I am having. I want to call up the running length of walls at base (where Y axis would be zero, and which would exclude door openings)or ceiling (which would give total lengths for molding etc). Is it possible to convert the above reporting script into a DCfunction in much the same way as you had created the DCvolume function? You may need specific functions that would take only the sum of lengths of the edges of the outer or inner faces of the wall at the base(ie excluding doors) and at the ceiling (which would include door openings).

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    TIG Moderator
                    last edited by 4 Apr 2013, 09:34

                    It wouldn't be so easy...

                    BUT you can write any custom function you like to add to a DC...

                    So let's say you want the perimeter of all faces that have a normal==Z_AXIS.reverse [facing down - i,e, the bottom of a ceiling slab] inside a DC you do something like:

                    require('sketchup')
                    require('dynamiccomponents.rb')
                    if defined?($dc_observers)
                      # Open Dynamic Component Functions (V1) class, only if DC extension is active
                    class DCFunctionsV1
                     protected
                     # return the perimeter (in inches) of face.normal==Z_AXIS.reverse
                     if not DCFunctionsV1.method_defined?(;perimeter)
                      def perimeter(a) # Usage as DC function; =perimeter()
                    	se = @source_entity
                    	if se.is_a?(Sketchup;;Group)
                    		allfaces = se.entities.grep(Sketchup;;Face)
                    	else #component-instance
                    		allfaces = se.definition.entities.grep(Sketchup;;Face)
                    	end
                    	faces=[]
                    	allfaces.each{|face| faces << face if face.normal==Z_AXIS.reverse }
                    	tr = se.transformation
                    	xs = tr.xscale #***
                    	ys = tr.yscale #***
                    	peri = 0.0
                    	faces.each{|face|
                    		tlen = 0.0
                    		face.outer_loop.edges.each{|e|
                    			elen = e.length # this is an unscaled length
                    			slen = elen*(1) #*** adjust for any X/Y scaling in (1) if needed ?
                    			tlen += slen
                    		}
                    		peri += tlen
                    	}
                        return peri
                      end
                     end 
                    end#class
                    end#if
                    

                    This takes no notice of any scaling applied to the DC object, reporting the original perimeter...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • O Offline
                      Omarian
                      last edited by 5 Apr 2013, 01:31

                      Thanks a million, it worked like a charm.

                      1 Reply Last reply Reply Quote 0
                      • bagateloB Offline
                        bagatelo
                        last edited by 7 Sept 2013, 16:52

                        @TIG

                        I only need The only modification I would like this plugin would measure diagonal objects properly, instead of bounding box ... and to work with groups also...

                        Please take a look to another request made by me:

                        http://sketchucation.com/forums/viewtopic.php?f=323&t=54080&p=490233#p490163

                        While the cat's away, the mice will play

                        1 Reply Last reply Reply Quote 0
                        • nanolinN Offline
                          nanolin
                          last edited by 13 Nov 2013, 03:50

                          @tig said:

                          Here's a version that might do what you want or be adapted easily...[attachment=0:28vg1yda]<!-- ia0 -->TIG-exportDCs2csv.rb<!-- ia0 -->/attachment:28vg1yda TIG 2011
                          Script:
                          TIG-exportDCs2csv.rb
                          Type:
                          TIG.exportDCs2csv
                          in the Ruby Console to run it.
                          Exports all DCs is the model with a Name,LenX,LenY,LenZ,Layer[s]...
                          'CSV' file - in the model's folder and named after the model thus:
                          ModelName.skp >>> ModelNameDCs.csv
                          If a new model is unsaved the current directory receives the new file.
                          All Layers used in the DC are listed by name and visible ones marked
                          thus >>LayerName<<
                          Edit sep="," if something other than separating comma is desired e.g. ';'
                          Make sep="\t" if a TSV file is desired and change ext="csv" to ext="tsv".
                          It uses the current Model Units.
                          Version:
                          1.0 20111104 First issue.
                          🤓

                          TIG

                          I was unable to generate the report. My model is in decimal> millimeters.
                          The dynamic component is in cm. Can you tell me what the problem is.

                          (This returns ruby console)

                          TIG.exportDCs2csv
                          Error: #<ArgumentError: C:/Program Files (x86)/SketchUp/SketchUp 2013/Plugins/TIG-exportDCs2csv.rb:48:in to_l': Cannot convert "23.425196850393703" to Length> C:/Program Files (x86)/SketchUp/SketchUp 2013/Plugins/TIG-exportDCs2csv.rb:48 C:/Program Files (x86)/SketchUp/SketchUp 2013/Plugins/TIG-exportDCs2csv.rb:48:in exportDCs2csv'
                          C:/Program Files (x86)/SketchUp/SketchUp 2013/Plugins/TIG-exportDCs2csv.rb:45:in each' C:/Program Files (x86)/SketchUp/SketchUp 2013/Plugins/TIG-exportDCs2csv.rb:45:in exportDCs2csv'
                          (eval):48

                          thanks

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            TIG Moderator
                            last edited by 13 Nov 2013, 11:23

                            Do you have ',' set as your decimal-separator, instead of '.' ?
                            This might cause issues ??

                            TIG

                            1 Reply Last reply Reply Quote 0
                            • nanolinN Offline
                              nanolin
                              last edited by 13 Nov 2013, 16:14

                              @tig said:

                              Do you have ',' set as your decimal-separator, instead of '.' ?
                              This might cause issues ??

                              TIG

                              I did 2 tests

                              1. drawing from scratch, I think the componet, add option LenX leny, lenz, the report is generated normally.

                              2. If this same component attributes modify a component value (eg 10 cm to 20 cm lenz), then display the error of failing to convert ...

                              thanks

                              pd. I have a component I created and I'm doubling, changing their values ​​to create furniture.
                              This report would be a solution to export cuts grain orientation panel

                              1 Reply Last reply Reply Quote 0
                              • nanolinN Offline
                                nanolin
                                last edited by 15 Nov 2013, 17:37

                                @tig said:

                                Do you have ',' set as your decimal-separator, instead of '.' ?
                                This might cause issues ??

                                TIG

                                With separator "," error occurs.
                                With separator "." export the file, but does not make mm

                                As coidgo would have to call from the menu?

                                It would be so?

                                require 'sketchup.rb'

                                UI.menu("PlugIns").add_item("Tig Export") {
                                exportDCs2csv
                                }

                                Thanks

                                1 Reply Last reply Reply Quote 0
                                • T Offline
                                  TIG Moderator
                                  last edited by 15 Nov 2013, 18:02

                                  The units are probably arriving in SketchUp base units == inches.
                                  So either multiply your columns in Excel by 25.4 to make mm OR when you a 'length' in inches do something like
                                  sprintf("%.1f", length.to_mm)
                                  so 1.0" >> 25.4 ?

                                  TIG

                                  1 Reply Last reply Reply Quote 0
                                  • nanolinN Offline
                                    nanolin
                                    last edited by 16 Nov 2013, 02:51

                                    @tig said:

                                    The units are probably arriving in SketchUp base units == inches.
                                    So either multiply your columns in Excel by 25.4 to make mm OR when you a 'length' in inches do something like
                                    sprintf("%.1f", length.to_mm)
                                    so 1.0" >> 25.4 ?

                                    TIG

                                    Thanks for your help.
                                    the ComponentReporter + + plugins I reported in mm but axes x, y, z
                                    You could modify this plugin to me that report LenX leny, lenz,(dynamic attributes)+ material, definition, of what is selected?
                                    in one csv.

                                    Thanks again, my knowledge of programming are very beginner

                                    1 Reply Last reply Reply Quote 0
                                    • T Offline
                                      TIG Moderator
                                      last edited by 16 Nov 2013, 10:17

                                      This original http://sketchucation.com/forums/viewtopic.php?p=373590#p373590
                                      does some DC attribute data things...
                                      This is a NEWER version...
                                      (c) TIG 2013
                                      Script:
                                      TIG-exportDCs2csv[2].rb
                                      Type into the Ruby Console:
                                      TIG.exportDCs2csv2
                                      OR use
                                      Plugins menu > TIG.exportDCs2csv2
                                      It Exports all Selected DCs' data into a file, as:
                                      Name,LenX,LenY,LenZ,Material,Layer
                                      It uses 'mm' for the XYZ units.
                                      It is a 'CSV' [COMMA separated variable] file - made in the model's folder and named after the model thus:
                                      ModelName.skp >> ModelNameDCs.csv
                                      If a new model is unsaved the current directory receives this new file.
                                      Edit sep="," if something other than separating comma is desired.
                                      Make sep="\t" if a 'TSV' [TAB separated variable] file is desired and change ext="csv" to ext="tsv".
                                      ...


                                      Put into the Plugins folder and restart SketchUp...

                                      TIG

                                      1 Reply Last reply Reply Quote 0
                                      • nanolinN Offline
                                        nanolin
                                        last edited by 16 Nov 2013, 15:37

                                        @tig said:

                                        This original http://sketchucation.com/forums/viewtopic.php?p=373590#p373590
                                        does some DC attribute data things...
                                        This is a NEWER version...
                                        (c) TIG 2013
                                        Script:
                                        TIG-exportDCs2csv[2].rb
                                        Type into the Ruby Console:
                                        TIG.exportDCs2csv2
                                        OR use
                                        Plugins menu > TIG.exportDCs2csv2
                                        It Exports all Selected DCs' data into a file, as:
                                        Name,LenX,LenY,LenZ,Material,Layer
                                        It uses 'mm' for the XYZ units.
                                        It is a 'CSV' [COMMA separated variable] file - made in the model's folder and named after the model thus:
                                        ModelName.skp >> ModelNameDCs.csv
                                        If a new model is unsaved the current directory receives this new file.
                                        Edit sep="," if something other than separating comma is desired.
                                        Make sep="\t" if a 'TSV' [TAB separated variable] file is desired and change ext="csv" to ext="tsv".
                                        ...

                                        Tig

                                        thank you very much, works perfect.
                                        Just an observation. If doubled within skp component and modify its dimensions (eg. LenX) reports all copies with the same value

                                        Deputy model

                                        Thanks


                                        Sin título.skp

                                        1 Reply Last reply Reply Quote 0
                                        • nanolinN Offline
                                          nanolin
                                          last edited by 28 Jan 2014, 00:05

                                          @tig said:

                                          This original http://sketchucation.com/forums/viewtopic.php?p=373590#p373590
                                          does some DC attribute data things...
                                          This is a NEWER version...
                                          (c) TIG 2013
                                          Script:
                                          TIG-exportDCs2csv[2].rb
                                          Type into the Ruby Console:
                                          TIG.exportDCs2csv2
                                          OR use
                                          Plugins menu > TIG.exportDCs2csv2
                                          It Exports all Selected DCs' data into a file, as:
                                          Name,LenX,LenY,LenZ,Material,Layer
                                          It uses 'mm' for the XYZ units.
                                          It is a 'CSV' [COMMA separated variable] file - made in the model's folder and named after the model thus:
                                          ModelName.skp >> ModelNameDCs.csv
                                          If a new model is unsaved the current directory receives this new file.
                                          Edit sep="," if something other than separating comma is desired.
                                          Make sep="\t" if a 'TSV' [TAB separated variable] file is desired and change ext="csv" to ext="tsv".
                                          ...

                                          TIG

                                          ud can have the report grouped plugin components, adding the name of the group in a new column?
                                          thanks post your feedback

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

                                          Advertisement