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

    Save panel when new SU file

    Scheduled Pinned Locked Moved Plugins
    3 Posts 2 Posters 552 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.
    • K Offline
      kat
      last edited by

      Hey,
      In a script I try to make a new SU file to save in the components folder and draw a text object into. Therefore I first have to know the path of the old SU file in order to be able to open it again after opening, drawing in, saving and closing the new SU component file.
      I do this with an inputpanel so I can save the path the user has chosen, but when I then make a new SU file with

      Sketchup.file_new
      

      Sketchup automatically asks the user to save the current file and opens a second save panel again.

      def make_skp()
      ss = Sketchup.active_model.selection
      skp = Sketchup.active_model.name # Name of the current SU model
      path1 = Sketchup.active_model.path # Path of the current SU model
      
      # Settings of the selected text object
      tekstlabel = ss[0] 
      v = ss[0].vector
      name = ss[0].text
      l = ss[0].leader_type
      a = ss[0].arrow_type
      p = ss[0].point
      tekstlabel.erase! # Delete the text object
      
      UI.messagebox "Please save your SU file."
      path2 = UI.savepanel("Save as",path1,skp)
      # Check if path2 ends with skp
      	p = path2.split(".")
      	if p[1] != "skp"
      		path2=path2+".skp"
      	end
      Sketchup.active_model.close_active # Close the current SU model
      
      su = Sketchup.file_new # Make a new SU file for the text object
      path3= File.join($components, "Opbouw", name+".skp")
      su.active_model.save(path3)
      # Make a new text object with the same settings in the new file
      	t = su.active_model.entities.add_text(name,[0,0,0]) 
      	t.vector = v
      	t.leader_type = l
      	t.arrow_type = a
      	t.display_leader = true
      su.active_model.save(path3) # Save the new SU file
      su.active_model.close_active # Close the new SU file
      
      # Open the old SU file again
      Sketchup.open_file(path2)
      
      end
      

      The code I wrote works perfectly, but does anyone has an idea of how to avoid this second savepanel witch is a little bit annoying to fill in all over again?

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        Why not use the save_as method of the component definition?
        http://code.google.com/apis/sketchup/docs/ourdoc/componentdefinition.html#save_as

        Going about creating a new model for a component sounds cumbersome.

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • K Offline
          kat
          last edited by

          Thanks, can't see why i didn't think of that...

          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