Cleaning Dynamic Attributes

Hi API friends,

Today I bumped into an unexpected behavior and I’d like your advise regading what I’m doing (working on SU2019 Pro).

After cleaning a scene provided by users using Dynamic Components to generate their model, I added a quick “dynamic_attributes” attribute dictionary cleaning pass to avoid errors when subsequent manually trasnformations are performed by the users.

Files

Cleaning Code (only dynamic part)

#Remove the dynamic component data
Sketchup.active_model.entities.each do |current_entity|
  if current_entity.is_a? Sketchup::Entity
    current_attrdict = current_entity.attribute_dictionaries
    current_attrdict.delete("dynamic_attributes") unless current_attrdict.nil?
  end
end

The dynamic attributes seems totaly deleted but on some component instances, when transforming them , they are recreated and SU is trying to apply them again…

Did I missed something when cleaning the dynamics attributes ?

Thanks for any help on this :slight_smile:

you may need to reset behaviour as well…

john

@john_drivenupthewall Thanks for you answer but can you tell me why changing the behavior snaping method of the component definitions will prevent the dynamic component data to be reloaded by SU ?

looking at your video, it seemed to be a behaviour that is retained, not a dynamic attribute…

after cleaning there are 89 instances with behaviours, but none with dynamic_attributes…

john

YES. Dynamic Attributes are defined on the definitions. For attributes that do not change they stay on the definitions and are shared by all instances. Only those attributes that DIFFER per instance are created and attached to the instances. There is an exception, and that is nested dynamic groups. These groups always have all dynamic attributes.

Looking at your code, it will de-dynamicise only components that have instances in the model, leaving any still in the definition list without instances as DCs.

You are also only removing dynamic attributes from the top level and not nested child DCs and groups.

It would be more efficient to iterate the definition list, and “clean” each instance, then iterate each definition’s entities cleaning the nested entities.

There are several topic threads on this already and I believe @eneroth3 posted code to do this in one of them.

Flextools has a ‘Zapper’ function for this.

https://flextools.cc/

I made a de-DC-ifier, partly because I wanted to remove the dynamicness of dynamic components, partly because I was fond of the name I had come up with.

3 Likes

Thanks all for your replies :slight_smile: Even if I’ve been searching for answers on the community posts, it seems that I missed them… I’ll make a try will all the given infos.

Again @DanRathbun, thanks for the explanations and now that you’re writing it, it seems obvious to look into the definition !