I’m finding my way to dynamic components and have created quite a bunch of them. Now I would like to add a description to the DC’s, that’s visible in the dynamic components tray. I tried Ruby script, but I’m new to that. I tried AI, which came up with:
require ‘sketchup.rb’
module DCDescription
def self.set_description
model = Sketchup.active_model
selection = model.selection
if selection.length != 1 || !selection.first.is_a?(Sketchup::ComponentInstance)
UI.messagebox("Selecteer precies één component.")
return
end
comp = selection.first
defn = comp.definition
prompts = ["Voer description in:"]
defaults = [defn.description.to_s]
input = UI.inputbox(prompts, defaults, "Component Description")
if input
defn.description = input[0]
UI.messagebox("Description opgeslagen.")
end
I just copy and pasted your ‘mess’ into a new Ruby script, getting rid of smart “.” etc and # out the button icon lines as of course I don’t have those. It worked as expected although I don’t understand Dutch very well ! So what is your problem ?
Thank you for responding. My problem is that it worked once. Every next time I use it, it says it worked, but the description is not added. Could you please share the cleaned script you used? I’m new to Ruby, so not shure what is “mess” and what should stay
I didn’t keep it, sorry. However I didn’t do much except making sure all of the quotes were ordinary ones " " or ' '
not ‘smart’
“.” or ‘.’
And make sure the images are available for the toolbar buttons.
When you post code on the forum please make sure you use the formatting tool in the bar </> icon, from start to finish - currently you miss out the end and some lines in the middle, so the ‘command’ line has smart-quotes again, the 2-space indents are lost and e.g. _FILE_ auto-formats to bold - that it will break SketchUp when you try and paste it into a Ruby file… ryan beat me to it…