sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    How to delete a model imported from *.dae file by ruby.

    Scheduled Pinned Locked Moved SketchUp Discussions
    sketchup
    4 Posts 3 Posters 604 Views 3 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.
    • Y Offline
      yuyuwhy
      last edited by

      I have many *.dae files (about 10 thousand) that must be purged in SketchUp. So I write a plugin to deal with the *.dae files. How to delete a imported model in ruby?

      Here is my ruby scripts, but the code doesn't have any effects.

      model = Sketchup.active_model
      entities = model.active_entities
      entities.each { |singleEntity|
      entities.erase_entities singleEntity
      }

      1 Reply Last reply Reply Quote 0
      • D Offline
        driven
        last edited by

        what are you actually doing?

        open new drawing...
        import dae, purge, export purged dae...

        2.times{Sketchup.send_action('editUndo;')}
        

        start again...
        maybe you don't even need the 2.times....

        learn from the mistakes of others, you may not live long enough to make them all yourself...

        1 Reply Last reply Reply Quote 0
        • Y Offline
          yuyuwhy
          last edited by

          @driven said:

          what are you actually doing?

          open new drawing...
          import dae, purge, export purged dae...

          2.times{Sketchup.send_action('editUndo;')}
          

          start again...
          maybe you don't even need the 2.times....

          yes, I just need to keep repeating the process: import a dae , purge, export purged dae, and deal with the next dae.

          thank you very much...
          πŸ‘

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            Start off by clearing everything, by using:
            model = Sketchup.active_model model.entities.clear!
            then purge the model using:
            model.definitions.purge_unused model.active_layer=model.layers[0]; model.layers.purge_unused model.materials.current=nil; model.materials.purge_unused model.styles.purge_unused ds = model.attribute_dictionaries; ds.to_a.each{|d| ds.delete(d) } if ds
            Now you have an empty SKP.

            Try doing the import AND export within a model.start_operation(...) block, BUT do not ' commit' it, rather you need to ' abort' it after each one.
            That way the import happens, the export happens but the changes to the model are undone by each ' abort'. The exported file is NOT undone by the ' abort' !

            TIG

            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