Trouble with commit operation

Trouble with commit operation

Postby vico44 » Tue Jan 22, 2019 6:33 pm

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
0
Last edited by vico44 on Fri Jan 25, 2019 2:43 pm, edited 1 time in total.

vico44 
 

Re: Trouble with commit operation

Postby fredo6 » Tue Jan 22, 2019 9:57 pm

Just put model.commit_operation before model.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.
0
User avatar
fredo6 
PluginStore Author
PluginStore Author
 

Re: Trouble with commit operation

Postby vico44 » Wed Jan 23, 2019 10:07 am

Thanks for the answers, but still not working... :(
0

vico44 
 

Re: Trouble with commit operation

Postby fredo6 » Wed Jan 23, 2019 10:35 am

Then, it is something else, and you should track the progress of the reload() method with some putsstatement to see what is going wrong.
0
User avatar
fredo6 
PluginStore Author
PluginStore Author
 

Re: Trouble with commit operation

Postby vico44 » Wed Jan 23, 2019 12:57 pm

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?
0

vico44 
 

Re: Trouble with commit operation

Postby fredo6 » Thu Jan 24, 2019 11:01 am

vico44 wrote: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]
0
User avatar
fredo6 
PluginStore Author
PluginStore Author
 

Re: Trouble with commit operation

Postby vico44 » Fri Jan 25, 2019 10:16 am

Au bah oui pourquoi j'n y es pas penser ;)
0

vico44 
 

Re: Trouble with commit operation

Postby vico44 » Fri Jan 25, 2019 10:39 am

Bon c'est pas le top, mais ça marche:

J'ai placer la ligne problématique (ligne 72) entre deux start_operation.
0

vico44 
 

Re: Trouble with commit operation

Postby fredo6 » Fri Jan 25, 2019 11:06 am

Tu pourrais faire une seule operation [start, commit] pour le guide point et le remplacement.

A few remarks:

1) 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.
Code: Select all
old_definition.instances.each { |i| i.definition = new_definition }

so you may want to use instead a copy of the list of instances
Code: Select all
old_definition.instances.to_a.each { |i| i.definition = new_definition }


2) You can reorganize the code for more clarity (use also a consistent Tabbing)

Code: Select all
    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
0
User avatar
fredo6 
PluginStore Author
PluginStore Author
 

Re: Trouble with commit operation

Postby vico44 » Fri Jan 25, 2019 12:34 pm

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
0

vico44 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: jasro and 10 guests

Visit our sponsors: