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

    Erase_entitiies crashing SU 8

    Scheduled Pinned Locked Moved Newbie Forum
    sketchup
    6 Posts 3 Posters 133 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.
    • T Offline
      timwarner
      last edited by

      I have a piece of code that crashes SU 8 (on a Mac).

      Basically the idea is to create an instance of a component, find the positions of its vertices and then erase the instance. The instance is created correctly; the vertices are correctly printed, but then SU dies. Here's the code fragment, where ents is model entities.

      brace_template = ents.add_instance(brace.definition,brace_transformation)
      bte = brace_template.explode
      vertices = bte.select{|e| e.typename == "Vertex"}
      puts "Brace coordinates"
      vertices.each{|v| puts v.position}
      ents.erase_entities(bte)
      

      Any ideas why this is happening?

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        @timwarner said:

        I have a piece of code that crashes SU 8 (on a Mac).

        Basically the idea is to create an instance of a component, find the positions of its vertices and then erase the instance. The instance is created correctly; the vertices are correctly printed, but then SU dies. Here's the code fragment, where ents is model entities.

        brace_template = ents.add_instance(brace.definition,brace_transformation)
        bte = brace_template.explode
        vertices = bte.select{|e| e.typename == "Vertex"}
        puts "Brace coordinates"
        vertices.each{|v| puts v.position}
        ents.erase_entities(bte)
        

        Any ideas why this is happening?

        There are things in bte other than valid drawing elements. The same thing happens if you try to delete a curve rather than the edges that make up the curve.

        Replace ents.erase_entities(bte) with

        bte.each{|e| e.erase! if e.valid? && e.is_a?(Sketchup;;Drawingelement)}
        

        This worked for me in Windows and hopefully will work on a Mac also.

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

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

          The ...erase! if... method will work, but it can be slow if there are many entities after the explode - this might be quicker to have this at the end
          bte.each{|e|bte.delete(e) unless e.is_a?(Sketchup::Drawingelement)} ents.erase_entities(bte)

          TIG

          1 Reply Last reply Reply Quote 0
          • T Offline
            timwarner
            last edited by

            Thank you, people. This works. I'm still a bit confused about the issue of drawing elements, because when I tried deleting the vertices entity collection (which would have the effect of removing the whole component instance) SU still crashed. But the vertices object only contains vertices.

            Tim

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

              You can only erase a Drawingelement.
              Although a vertex is treated as an 'entity' for bulk changes with code like ents.transformation_entities(vertices) etc it cannot be erased in code.
              However you can do something like vertices.each{|v|ents.erase_entities(v.edges) if v.valid?} which has the same outcome, because if you could erase a vertex then its edges would vanish, as would those edges' faces etc...

              Presumably you understand that when you get an array returned with an explode, that array is not just Drawingelements, but includes vertices/loops/etc which cannot be 'erased', and thereby this caused you crash issues, so parsing that array to be just Drawingelements ensures such problems are avoided.

              TIG

              1 Reply Last reply Reply Quote 0
              • T Offline
                timwarner
                last edited by

                Thx ..my carelessness in thinking a vertex was a drawing element! .../T

                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