sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Trouble with commit operation

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 2 Posters 6.7k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V Offline
      vico44
      last edited by vico44

      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


      Vico_newfile.rb

      1 Reply Last reply Reply Quote 0
      • fredo6F Offline
        fredo6
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • V Offline
          vico44
          last edited by

          Thanks for the answers, but still not working... 😞

          1 Reply Last reply Reply Quote 0
          • fredo6F Offline
            fredo6
            last edited by

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

            1 Reply Last reply Reply Quote 0
            • V Offline
              vico44
              last edited by

              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?

              1 Reply Last reply Reply Quote 0
              • fredo6F Offline
                fredo6
                last edited by

                @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]

                1 Reply Last reply Reply Quote 0
                • V Offline
                  vico44
                  last edited by

                  Au bah oui pourquoi j'n y es pas penser 😉

                  1 Reply Last reply Reply Quote 0
                  • V Offline
                    vico44
                    last edited by

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

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


                    Vico_newfile.rb

                    1 Reply Last reply Reply Quote 0
                    • fredo6F Offline
                      fredo6
                      last edited by

                      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.
                      
                      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 }
                      
                      
                      1. 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
                      
                      
                      1 Reply Last reply Reply Quote 0
                      • V Offline
                        vico44
                        last edited by

                        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

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement