Area to text
-
Good day,
I am trying to make a simple plugin to add up the area of selected faces and write them to txt or perhaps xml?
I have no idea where to begin
DOes anyone have a guide or link for me to an example perhaps? will be gladly appreciated!
-
Set up some variables...
@model=Sketchup.active_model @ss=@model.selection
'Collect' the selected faces...
faces=@ss.grep(Sketchup::Face)
add up the areas [in sq"]...
area=0.0 faces.each{|face|area+=face.area}
Now if desired covert to other units [here sqm]...
area=area/1,550.00310000620001
Now add the text [here we'll add it as 'screen-text' aka 'note']
@model.add_note("Area=#{area}sqm", 0.1, 0.1)
Obviously there are many ways to do this, e.g. add text with a leader onto one of the faces...
@model.active_entities.add_text("Area=#{area}sqm", faces[0].bounds.center, [11,11,11]) if faces[0]
Alsosprintf()
can be used to adjust the displayed decimal places etc... -
Pay attention to the shaded "sticky" posts at the top of the list. There are code snippet indexes, etc. to help you.
-
Note that when computing the area of the faces you want to apply the transformation of the parent context in order to get the correct size. The Face.area method accepts and optional transformation argument.
Advertisement