I have been having issues with DefinitionsList.load. I am trying to reload an external component that has been updated externally via Ruby.
I encounter the following behaviours:
model = Sketchup.active_model
# We have a single component in the model
old_definition = model.entities[0].definition
puts old_definition.path #=> '/HD/Users/User/cylinder.skp'
puts model.definitions.count #=> 1
# Note that the definition was saved to '/HD/Users/User/cylinder.skp', and
# the file was then edited independently
# Attempt to reload the component
new_definition = model.definitions.load '/HD/Users/User/cylinder.skp'
puts old_definition.guid #=> 1736b32a-8dd3-3040-bdfd-62a05e188985
puts new_definition.guid #=> 1736b32a-8dd3-3040-bdfd-62a05e188985
# The same GUID! The file was NOT loaded, as it has been edited since. It effectively loaded the internal component
# And a new (renamed) definition was not added to the definitions list:
puts model.definitions.count #=> 1
if new_definition == old_definition
puts "The definitions are the same! This shouldn't happen, no?"
end
# However, loading a new component that does not share a path with another component works:
second_new_definition = model.definitions.load '/HD/Users/User/cube.skp'
puts model.definitions.count #=>2
# Other things I have tried:
# - Renaming the old definition before load - same result:
old_definition.name= "new name"
new_definition = model.definitions.load '/HD/Users/User/cylinder.skp'
puts new_definition.name #=> "new_name"
It seems that Sketchup refuses to reload a component from a path if there is a component with that path in the model already. I canāt see this as intended behaviour, as it makes it difficult to update components that were edited elsewhere using Ruby.