I use Ruby script to copy and move multiple dynamic components.
It works great but I noticed that the tag (layer) is changed to Untagged from the tag they were in.
Is this default behavior?
To fix this, in the loop of making copies, I can add to check the tag of original, save it, and assign it to the copy. But is there a better way?
Like what? Saying “Abracadabra” and waving a magic wand ? Nope, doesn’t work.
Come on, dude. It will not happen by itself. Coding is all about paying attention to the details and making it happen.
The originals were assigned to certain tags (layers) because someone set them to manually, or they were inserted into the model when the current tag (layer) was set to what was desired for the instance tag assignment.
(The latter is usually the only common reason to ever change the current tag to one other than “Untagged”. But when done inserting components, the current tag should be reset immediately. There are extensions that can remind you to do this.)
haha of course not. I was just reading the API documentation to write something to test my idea.
# Make copies of the selected components
copied_components = []
sel.each do |comp|
# Get the layer/tag of the component
comp_layer = comp.layer
# Make a copy of the component
copied_comp = comp.copy
# Assign the same layer/tag to the copied component
copied_comp.layer = comp_layer
# Add the copied component to the array
copied_components << copied_comp
end