Hi,
I have a code that i can use to report beams (c-profiel) When i want to add this to a toolbar it doesn’t work.
I discovered that it has something to do with “DATALINE”
Does anyone have a solution to get this to working in a toolbar?
This is the code:
def Rfile.main
model = Sketchup.active_model
model.start_operation "Rfile"
definition = Sketchup.active_model.definitions["C-profiel"]
number = definition.count_instances
instance = definition.instances[0]
name = instance.name
#get a path:
path = UI::savepanel("Save Report As...","report.txt")
if path
# Create a data format string with newline:
DATALINE = "%-20s %-25s %-8s %-8s %-8s %-s\n"
dictionary_name = "dynamic_attributes"
# Set Report Captions:
@report = format( DATALINE, "ONDERDEEL", "ARTIKEL", "AANTAL", "LENGTE", "HOOGTE", "KLEUR")
@report << format( DATALINE, "", "", "" , "", "", "" )
# Iterate the found component definitions:
dname = "C-profiel"
deflist = Sketchup.active_model.definitions
matches = deflist.find_all {|d|
!d.group? && !d.image? && d.name =~ /\A(#{dname})/
}
total = 0
matches.each {|definition|
number = definition.count_used_instances
total += number
attribute = definition.get_attribute(dictionary_name, 'lenx').to_f.to_mm/25.4
height = Sketchup.format_length( attribute )
@report << format( DATALINE, definition.name, name, number, height, "-", "-" )
}
# Save the Report:
File::write( path, @report )
end
end
end
toolbar = UI::Toolbar.new "Rfile"
cmd = UI::Command.new("Rfile") { Rfile.main}
cmd.small_icon = "ToolPencilSmall.png"
cmd.large_icon = "ToolPencilLarge.png"
cmd.tooltip = "Rfile"
cmd.status_bar_text = "Rfile"
cmd.menu_text = "Rfile"
toolbar = toolbar.add_item cmd
toolbar.show