• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Check if group of entities exist, if true delete them

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 4 Posters 437 Views
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.
  • D Offline
    descoteaux
    last edited by 30 Jun 2013, 00:10

    I'm struggling a bit with this simple action. 😳

    I've got a tool that generates and places 3d text based on user input. However each time they use the tool I need to check if the 3d text already exists. If it does, it needs to be deleted and replaced.

    I've dug up Entities.erase_entities from the API, but I have not been able to implement it successfully where I avoid undefined local variable (trying to detect the 3d text on first run) and reference to deleted Group (attempting to delete the 3d text a second time) errors.

    Here is the relevant snippet:

    commentgroup = entities.add_group
    commentgroupents = commentgroup.entities
    addusercomment = commentgroupents.add_3d_text(usercomment, TextAlignLeft, "Arial",   true, false, fontheight, 0.0, 0.5, true, 5.0)
    

    Thank you.

    1 Reply Last reply Reply Quote 0
    • D Offline
      dukejazz
      last edited by 30 Jun 2013, 02:48

      Maybe this will help
      if you know the x1 y1 z1 of a group text

      Sketchup.active_model.active_entities.to_a.each{|e| e.erase! if e.is_a?(Sketchup::Text) and e.point==Geom::Point3d.new(x1,y1,z1) }

      Given a [x,y,z] delete a text note.
      http://sketchucation.com/forums/viewtopic.php?f=180&t=45726#p408528

      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 30 Jun 2013, 08:22

        @dukejazz said:

        Maybe this will help
        if you know the x1 y1 z1 of a group text

        Sketchup.active_model.active_entities.to_a.each{|e| e.erase! if e.is_a?(Sketchup::Text) and e.point==Geom::Point3d.new(x1,y1,z1) }

        Given a [x,y,z] delete a text note.
        http://sketchucation.com/forums/viewtopic.php?f=180&t=45726#p408528

        He talked about 3d text - not the Text labels -so that won't work.

        Problem is - once you use entities.add_3d_text it just generates a bunch of faces and edges. There is no way of knowing that it belong to something that came from .add_3d_text.

        @descoteaux: can you explain a bit more about what your plugin is doing?
        Is the 3d text the only thing in the group? Or is there more?

        If it's the only thing in the group then it's easy - you just need to check if there is any geometry in there.

        I made a plugin that let you edit 3d text (if it's made with the plugin): http://extensions.sketchup.com/en/content/3d-text-editor
        The text is contained within a group or component - and I add attributes with the settings I used to create the text so I can later detect that the group/component is 3d text and what the settings where to create it.

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

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 30 Jun 2013, 10:56

          Give your 3dText 'commentgroup' a unique 'attribute' to identify it.
          commentgroup.set_attribute('my_commentgroup', 'id', true)
          Then when you go to 'renew' it, delete it if it exists using

          entities.grep(Sketchup;;Group).each{|g|
           if g.get_attribute('my_commentgroup', 'id', nil)
            g.erase!
            break ### assuming there's only ever going to be one found ???
           end
          }
          

          TIG

          1 Reply Last reply Reply Quote 0
          • D Offline
            descoteaux
            last edited by 30 Jun 2013, 21:22

            Thanks for your help everyone! TIG's advice did the trick. 😄

            Also thomthom, thank you for pointing out your editable 3d text plugin. I've wished it existed for a long time. Awesome work!

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

            Advertisement