Trouble with commit operation
-
I try to do a new plugin to save open and reload component inside a model and creat xref directory, it works well.
But i got trouble when I try to add "Model.start_operation" the plugin no longer works (refuse to load the new component). Any idea?
The attach file is functional for the trouble one you can erase the "#" on line 62 and line 83.
Thanks
-
Just put
model.commit_operation
beforemodel.save
.model.commit_operation is used to commit the geometry, and it must be done before you save the file, which is a separate operation.
-
Thanks for the answers, but still not working...
-
Then, it is something else, and you should track the progress of the
reload()
method with someputs
statement to see what is going wrong. -
when i use the "model start opération" the line -> new_definition = model.definitions.load(path) doesn't work at all and new_definition goes to the same definition of the old_definition.
but the reload() method works good if i don't use "model start opération" i got a new_definition and can remove the old one.
really strange.
On peut parler français remarque non?
-
@vico44 said:
when i use the "model start opération" the line -> new_definition = model.definitions.load(path) doesn't work at all and new_definition goes to the same definition of the old_definition.
but the reload() method works good if i don't use "model start opération" i got a new_definition and can remove the old one.
really strange.
On peut parler français remarque non?
Donc il faut peut-ĂȘtre mettre la ligne
new_definition = model.definitions.load(path)
en dehors du block [start_operation, commit_operation
] -
Au bah oui pourquoi j'n y es pas penser
-
Bon c'est pas le top, mais ça marche:
J'ai placer la ligne problématique (ligne 72) entre deux start_operation.
-
Tu pourrais faire une seule operation [start, commit] pour le guide point et le remplacement.
A few remarks:
- You need to be careful when you perform a loop on an object, and the process in the body can alter this object. In your case,
old_definition.instances
is altered when you change the definition of its instances.
old_definition.instances.each { |i| i.definition = new_definition }
so you may want to use instead a copy of the list of instances
old_definition.instances.to_a.each { |i| i.definition = new_definition }
- You can reorganize the code for more clarity (use also a consistent Tabbing)
def self.reload model = Sketchup.active_model select_composant = Sketchup.active_model.selection[0] old_definition = select_composant.definition good_name = old_definition.name filename = good_name + ".skp" path = old_definition.path #Path does not exist unless File.exist?(path) UI.messagebox("Error; Could not find file;\n\"#{path}\"" ) return end #Load new_definition new_definition = model.definitions.load(path) unless new_definition UI.messagebox("Error; Could not load component; \"#{File.basename(filename,".*")}\"") return end #Add guide point at origin model.start_operation("préparation", true) select_composant.locked = false entities = old_definition.entities entities.add_cpoint(ORIGIN) model.commit_operation #Replace definition model.start_operation("remplacer", true) new_definition.name = good_name old_definition.instances.to_a.each { |i| i.definition = new_definition } model.definitions.remove(old_definition.name) model.commit_operation end # reload
- You need to be careful when you perform a loop on an object, and the process in the body can alter this object. In your case,
-
En fait le guide point sert Ă modifier l'ancien composant a cause d'un bug sur model.definitions.load(path) qui refuse de lire un composant dans le mĂȘme rĂ©pertoire qu'un composant enregistrer si celui ci n'est pas modifier.
Je suis donc obliger de mettre la partie guide point avant model.définitions.load(path).
cf : https://sketchucation.com/forums/viewtopic.php?f=180&t=60568
Advertisement