Good evening
I am a French landscaper.
I want to use the date parameter of sketchup shadows to display my plant components according to the season.
Mr Dan had helped me a lot last year to get the date parameter and create a “season” attribute corresponding to the day of the year (1 - 365).
he even added a context menu.
Today, after a while, I am resuming its development.
All my components will be structured with the same hierarchy:
*Component
*Group “persistent vegetation”
* Group “Annual Vegetation”
* Group “Flowering”
* Group “Fruiting”
The component will receive attributes:
- season (thanks to Dan’s code)
https://forums.sketchup.com/t/set-attribut-date-shadow-dynamic-component/42371
-
annual vegetation date early
-
annual vegetation end date
-
flowering date early
-
flowering end date
-
fructification start date
-
Fruiting end date
-
…
-
Annual vegetation display
-
Flower display
-
Fruit display
-
season OnOFF
The name of the component is variable but not the name of the subgroups.
I wish to have the code to retrieve the name of the component select in variable to use it in a formula for the definition of a hidden attribute for each group
hidden attribute = component name! flower display
here is the code already
# encoding: UTF-8
# Module Définition attributs des végétaux
# Auteur Simon Joubert
### Label Parametres Vegetaux
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_000", "PARAMETRES VEGETAUX"
s.set_attribute "dynamic_attributes", "_vgtx_000_access","VIEW"
s.set_attribute "dynamic_attributes","_vgtx_000_formlabel","***********"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### Nom de la plante
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_001", "Nom de la plante"
s.set_attribute "dynamic_attributes","_vgtx001_units", "STRING"
s.set_attribute "dynamic_attributes", "_vgtx_001_access","TEXTBOX"
s.set_attribute "dynamic_attributes","_vgtx_001_formlabel","Nom"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### Type de plante
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_002", "Arbre"
s.set_attribute "dynamic_attributes","_vgtx002_units", "STRING"
s.set_attribute "dynamic_attributes", "_vgtx_002_access","LIST"
s.set_attribute "dynamic_attributes","_vgtx_002_formlabel","Type de plante"
s.set_attribute "dynamic_attributes","_vgtx_002_options", "Arbre=Arbre&Arbuste=Arbuste&Vivace=Vivace&Grimpante=Grimpante&Aquatique=Aquatique"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### Origine de la plante
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_003", "Existant"
s.set_attribute "dynamic_attributes","_vgtx003_units", "STRING"
s.set_attribute "dynamic_attributes", "_vgtx_003_access","LIST"
s.set_attribute "dynamic_attributes","_vgtx_003_formlabel","Origine"
s.set_attribute "dynamic_attributes","_vgtx_003_options", "Existant=Existant&Fourniture=Fourniture"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### *************************************************
### Label Parametres Saison
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_020", "PARAMETRES SAISON"
s.set_attribute "dynamic_attributes", "_vgtx_020_access","VIEW"
s.set_attribute "dynamic_attributes","_vgtx_020_formlabel","***********"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### Label Parametres Végétation annuelle
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_021", "DATE"
s.set_attribute "dynamic_attributes", "_vgtx_021_access","VIEW"
s.set_attribute "dynamic_attributes","_vgtx_021_formlabel","VEGETATION ANNUELLE"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### Végétation annuelle début
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_022","14"
s.set_attribute "dynamic_attributes","_vgtx022_units", "STRING"
s.set_attribute "dynamic_attributes", "_vgtx_022_access","LIST"
s.set_attribute "dynamic_attributes","_vgtx_022_formlabel","Debut"
s.set_attribute "dynamic_attributes","_vgtx_022_options","aucun=0&janvier=1&mi-janvier=15&fevrier=32&mi-fevrier=45&mars=60&mi-mars=74&avril=91&mi-avril=105&mai=121&mi-mai=135&juin=152&mi-juin=166&juillet=182&mi-juillet=196&aout=213&mi-aout=227&septembre=244&mi-septembre=258&octobre=274&mi-octobre=288&novembre=305&mi-novembre=319&decembre=335mi-decembre=349&fin decembre=365"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### Végétation annuelle fin
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_023","319"
s.set_attribute "dynamic_attributes","_vgtx023_units", "STRING"
s.set_attribute "dynamic_attributes", "_vgtx_023_access","LIST"
s.set_attribute "dynamic_attributes","_vgtx_023_formlabel","Debut"
s.set_attribute "dynamic_attributes","_vgtx_023_options","aucun=0&janvier=1&mi-janvier=15&fevrier=32&mi-fevrier=45&mars=60&mi-mars=74&avril=91&mi-avril=105&mai=121&mi-mai=135&juin=152&mi-juin=166&juillet=182&mi-juillet=196&aout=213&mi-aout=227&septembre=244&mi-septembre=258&octobre=274&mi-octobre=288&novembre=305&mi-novembre=319&decembre=335mi-decembre=349&fin decembre=365"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### Label Parametres Floraison
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_031", "DATE"
s.set_attribute "dynamic_attributes", "_vgtx_031_access","VIEW"
s.set_attribute "dynamic_attributes","_vgtx_031_formlabel","FLORAISON"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### Floraison début
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_032","152"
s.set_attribute "dynamic_attributes","_vgtx032_units", "STRING"
s.set_attribute "dynamic_attributes", "_vgtx_032_access","LIST"
s.set_attribute "dynamic_attributes","_vgtx_032_formlabel","Debut"
s.set_attribute "dynamic_attributes","_vgtx_032_options","aucun=0&janvier=1&mi-janvier=15&fevrier=32&mi-fevrier=45&mars=60&mi-mars=74&avril=91&mi-avril=105&mai=121&mi-mai=135&juin=152&mi-juin=166&juillet=182&mi-juillet=196&aout=213&mi-aout=227&septembre=244&mi-septembre=258&octobre=274&mi-octobre=288&novembre=305&mi-novembre=319&decembre=335mi-decembre=349&fin decembre=365"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### Floraison fin
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_033","196"
s.set_attribute "dynamic_attributes","_vgtx033_units", "STRING"
s.set_attribute "dynamic_attributes", "_vgtx_033_access","LIST"
s.set_attribute "dynamic_attributes","_vgtx_033_formlabel","Fin"
s.set_attribute "dynamic_attributes","_vgtx_033_options","aucun=0&janvier=1&mi-janvier=15&fevrier=32&mi-fevrier=45&mars=60&mi-mars=74&avril=91&mi-avril=105&mai=121&mi-mai=135&juin=152&mi-juin=166&juillet=182&mi-juillet=196&aout=213&mi-aout=227&septembre=244&mi-septembre=258&octobre=274&mi-octobre=288&novembre=305&mi-novembre=319&decembre=335mi-decembre=349&fin decembre=365"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### Label Parametres Fructification
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_041", "DATE"
s.set_attribute "dynamic_attributes", "_vgtx_041_access","VIEW"
s.set_attribute "dynamic_attributes","_vgtx_041_formlabel","FRUCTIFICATION"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### Fructification début
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_042","182"
s.set_attribute "dynamic_attributes","_vgtx042_units", "STRING"
s.set_attribute "dynamic_attributes", "_vgtx_042_access","LIST"
s.set_attribute "dynamic_attributes","_vgtx_042_formlabel","Debut"
s.set_attribute "dynamic_attributes","_vgtx_042_options","aucun=0&janvier=1&mi-janvier=15&fevrier=32&mi-fevrier=45&mars=60&mi-mars=74&avril=91&mi-avril=105&mai=121&mi-mai=135&juin=152&mi-juin=166&juillet=182&mi-juillet=196&aout=213&mi-aout=227&septembre=244&mi-septembre=258&octobre=274&mi-octobre=288&novembre=305&mi-novembre=319&decembre=335mi-decembre=349&fin decembre=365"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### Fructification fin
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_043","274"
s.set_attribute "dynamic_attributes","_vgtx043_units", "STRING"
s.set_attribute "dynamic_attributes", "_vgtx_043_access","LIST"
s.set_attribute "dynamic_attributes","_vgtx_043_formlabel","Fin"
s.set_attribute "dynamic_attributes","_vgtx_043_options","aucun=0&janvier=1&mi-janvier=15&fevrier=32&mi-fevrier=45&mars=60&mi-mars=74&avril=91&mi-avril=105&mai=121&mi-mai=135&juin=152&mi-juin=166&juillet=182&mi-juillet=196&aout=213&mi-aout=227&septembre=244&mi-septembre=258&octobre=274&mi-octobre=288&novembre=305&mi-novembre=319&decembre=335mi-decembre=349&fin decembre=365"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### Végétation annuelle ETAT
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_102", "FALSE"
s.set_attribute "dynamic_attributes","_vgtx_102_units", "BOOLEAN"
s.set_attribute "dynamic_attributes", "_vgtx_102_access","VIEW"
s.set_attribute "dynamic_attributes","_vgtx_102_formlabel","Fleurs"
s.set_attribute "dynamic_attributes","_vgtx_102_formula", "if(OR(vgtx_023,vgtx_022)=0,TRUE,if(vgtx_023>vgtx_022,if(season>=vgtx_022,if(season<=vgtx_023,FALSE,TRUE),TRUE),if(season>=vgtx_023,FALSE,if(season<=vgtx_022,FALSE,TRUE))))"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### Floraison ETAT
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_103", "FALSE"
s.set_attribute "dynamic_attributes","_vgtx_103_units", "BOOLEAN"
s.set_attribute "dynamic_attributes", "_vgtx_103_access","VIEW"
s.set_attribute "dynamic_attributes","_vgtx_103_formlabel","Fleurs"
s.set_attribute "dynamic_attributes","_vgtx_103_formula", "if(OR(vgtx_033,vgtx_032)=0,TRUE,if(vgtx_033>vgtx_032,if(season>=vgtx_032,if(season<=vgtx_033,FALSE,TRUE),TRUE),if(season>=vgtx_033,FALSE,if(season<=vgtx_032,FALSE,TRUE))))"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
### Fructification ETAT
mod = Sketchup.active_model
sel = mod.selection
sel.grep(Sketchup::ComponentInstance).each do |s|
s.set_attribute "dynamic_attributes","vgtx_104", "FALSE"
s.set_attribute "dynamic_attributes","_vgtx_104_units", "BOOLEAN"
s.set_attribute "dynamic_attributes", "_vgtx_104_access","VIEW"
s.set_attribute "dynamic_attributes","_vgtx_104_formlabel","Fruits"
s.set_attribute "dynamic_attributes","_vgtx_104_formula", "if(OR(vgtx_043,vgtx_042)=0,TRUE,if(vgtx_043>vgtx_042,if(season>=vgtx_042,if(season<=vgtx_043,FALSE,TRUE),TRUE),if(season>=vgtx_043,FALSE,if(season<=vgtx_042,FALSE,TRUE))))"
$dc_observers.get_latest_class.redraw_with_undo(s)
end
I understand it as it is but it can surely be simplified. it will surely add debugging but I start in ruby.
The final desire is to have a toolbar with 4 buttons.
1 Define the plants + season attribute
2 update the attributes after changing the date of the shadow parameters
3 redraw the plant components of the model.
4 force the display of all groups season = off
Thanks for your help
I like the idea of going away, but the time I can devote to it is insufficient for my taste and my empty pockets. so thank you for your indulgence, I start.
Thank you for the time you will be able to accommodate me.
Simon