Dynamic component name?
-
Dynamic component name
Hello
In the attributes of a dynamic component:
I am looking for a formula allowing me to recover the name of the dynamic componentObjective: Get the unique name of the component including "# 1" if duplicate component
Is it possible?
Thanks for your help -
within the DC formulas
=_name (underscore name) returns the original name, but no other assign #numbers after the first assignment via the component creatorthis original name for the definition is static, it does not change with any renaming via entity info
Ruby is the alternative to get the data required, then you can pass it into the DC involved
but will need to set an external command to do this (button, right click menu...)it is suggested you consider a holistic approach in using a script to access the component folders, to place, scale and orientate the instance with the updated data, thus doing many of your requirements in one or a few clicks.
Such scripts are custom to your workflow and data required. If you decide on this path, then can help as well as others on this forum will.
-
Thank you for your answer.
In summary,
In the current state of Sketchup Pro, this is not possible.
Except writing a script with the help of RUBY?Did I understand well?
How can I start on RUBY?
Are there any tutorials to learn how to use RUBY? -
Hi
Sorry didn't see reply until todayTo clarify a few points, a component seen on the model interface is a component instance whereas the definition is retained in data even after all the instances are deleted unless the file is purged. Deleting a component definition in the component dialog will delete all instances.
Component instances have their own naming system that matches groups, for dynamic components (DCs) provided you don’t use the “name” attribute, changes in instance name are reflected in the title of the attribute and options dialog of the DC. This may be enough for your workflow in showing some uniformity in outliner, labels, and the DCs options.If this is too limited, then ruby extensions are required, DCs seem to be very low on the sketchup developers priority list, I naively assume that they would get attention on each new release, been 5 years now with little or any visible improvement, so you really need to use ruby in conjunction with your DC program
It would be best if you could give an outline of your intentions with regards DCs, for example I use them to create structural drawings and material lists, so easy excess to my DC folders and a placement, scale and orientation tool is my first ruby, then another to simplify the DC to an inert form…and so on. I now use the “description” attribute as main reference to create reports on materials and the instance name to locate container objects with instance name “WF1” or “WF2”… or “RT2” rather than the DC definition name wallframe# whatever number or rooftruss#103 (no longer important or included in my report)
With regards the ruby API, this is specific to Sketchup and not a ruby learning deposit. To understand ruby you would need to check out some youtube videos, on line books...
However there is nothing like taking the plunge...There a few downloads
Ruby editor:- Of your own choice (I currently use https://sketchucation.com/pluginstore?pln=as_rubyeditor)
- Create and test ruby scripts
tool editor:
https://sketchucation.com/pluginstore?pln=ae_ToolbarEditor- convenience of running snippets
- make buttons toolbar without knowing the ruby required, later you can install your own or a web form for more complex projects
Attribute editor: https://sketchucation.com/pluginstore?pln=ae_AttributeInspector
- to understand the DC behind the scenes attributes (_underscore values)
- to copy lists from one dropdown to another
- to insert a formatted, excel list rather than write a long list and values
With DCs a very important ruby code step is redraw.
There are some situations when a redraw is not triggered, such as entering a DC and changing its raw geometry, consider the facearea() is not updated until a redraw (right click context menu) is made.
The area example, open option dialog, then the DC, move an edge or two, close, you will note the area calculation does not update. Unless you force a redraw via the context menu, DC,redraw or another method to update the option dialog.
area example.skpConsider the snippets kindly donated by Tig, Dan, Mitch and many others and attach the code to a button create in toolbar editor
https://sketchucation.com/forums/viewtopic.php?f=180&t=68489
or https://forums.sketchup.com/t/redraw-all-dynamic-components/77512Sketchup.active_model.selection.grep(Sketchup::ComponentInstance).each do |s| $dc_observers.get_latest_class.redraw_with_undo(s) end
This would be a good starting point, reading it, dot containers, we are looking at a selection, so a selection must be done for this to work, look up grep on internet, so filtered to specific elements of an array, with each do an action….redraw
Try this first on the example modelExpand this with
Sketchup.active_model.selection.grep(Sketchup::ComponentInstance).each do |s| puts s.name puts s.definition.name $dc_observers.get_latest_class.redraw_with_undo(s) end
puts writes the result to the ruby console, so open this and run the script to see both names
using puts to the ruby console is a method of checking the results you are seeking, as Dan wrote, messagebox can silently fail, so use the console to get some feedback as you experimentNow to this script we can add attributes “name_defn” and “name_inst” or of own choosing. Then assign the results
` Sketchup.active_model.selection.grep(Sketchup::ComponentInstance).each do |s|s.set_attribute 'dynamic_attributes','namedefn', s.definition.name.to_s s.set_attribute 'dynamic_attributes','nameatt', s.name.to_s
$dc_observers.get_latest_class.redraw_with_undo(s)
end`Try it on the example
It is best if the attribute in is already defined in the DC before altering its value, as there is a reference issue in the internal DC code if done on the fly. -
I thank you for your post, very complete, so I will study this with great attention.
Thank you so much,
Advertisement