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

    Internal numbering of entities differs in iterations?

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 3 Posters 288 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.
    • artmusicstudioA Offline
      artmusicstudio
      last edited by

      hello,
      i face a seldom problem:

      i have always the same polyline created from ruby (say 10 edges, all connected) : curve

      then i generate a rectangle at the startin point : square

      then i use

      status1 = square.followme curve

      works perfect.

      BUT:

      while idenfifying the sidewalls of the result, i found out, that it's entity-number changes from iteration to iteration.
      i would not expect that.

      i checked it by letting the ruby ERASE the entity[16],

      which sometimes deleted a different face .

      can anybody confirm that?

      if so, how is it possible to allocate always the same face of an object generated in a routine?

      thanx stan

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        @artmusicstudio said:

        hello,
        if so, how is it possible to allocate always the same face of an object generated in a routine?

        Attach an attribute to the face to mark it.

        face.set_attribute("AMS_Fancy_Widget", "face number", i.to_s )

        You decide what the name of the attribute will be, and what value to store.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • artmusicstudioA Offline
          artmusicstudio
          last edited by

          hi dan,
          ok, so i can give an attribute to an entity.

          but what can i do , when the same face (let us say the front face of the cube , which is generated by the code again and again), sometimes has a different number in the array ? it is impossible then to know the number and so also not possible to assign attributes.

          what ever i do, in my case the number of the face changes (a 3d object crewted by follow me)

          hopefully infind the reason, since moving always the same face is an important feature for me.

          regards and thanx
          stan

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            I assumed you would attach an attribute before the operation.

            .. then search the array using one of the methods in Enumerable (which is mixed into Array.)

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              IF you know what direction the face's normal vector will be pointing.. then you could search the array for the face who's normal == vector.
              found = results.find {|f| f.normal == vector } face = found if found

              I'm not here much anymore.

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

                Currently at least, SketchUp does not give any entities an "enduring id" across sessions - it's unlikely that 'raw geometry' will ever get them. So you have give them an id attribute - as Dan has suggested.
                It can be an integer - this is best as searching strings is slower...
                i = 3 ### say... face.set_attribute("AMS_Fancy_Widget", "face_id", i )
                then later on

                num = 3 ### say...
                face = nil
                entities.grep(Sketchup;;Face).each{|e|
                  if face.get_attribute("AMS_Fancy_Widget", "face_id", -1) == num
                    face = e
                    break
                  end
                }
                if face ### do something ...
                

                Note how I used -1 as the default response rather than accepting 'nil' - you will NOT have used that as an id and now any faces without an id attribute will be skipped too, only the 'face' with the exact matching id number will be found... Because the 'face' with a particular id might no longer exist [it could have been deleted] you'll need to use a if face... test... in case there is no match.

                TIG

                1 Reply Last reply Reply Quote 0
                • artmusicstudioA Offline
                  artmusicstudio
                  last edited by

                  hi tig,
                  yes, i understand the principles of giving attributes to entities now and will try to experiment with this.
                  maybe i may go step back to my special situation (just for understanding):

                  i have an axis of different edges, giving a path for 'followme' ,

                  then i let create the ruby the same object again and again (imagine:

                  square, path, followme, delete
                  square, path, followme, delete
                  etc.)

                  the funny thing is, that the entities DO have a numbering , which is their position in the array, right?

                  and so a thought, while knowing , which entity has which number in the row, i could access them easily (again: always the same object with same amount of edges and faces from the same procedure)

                  but at this point the numbering of faces in the array changes, although generated thru same procedure.

                  and since the object is a follow-me- object, i cannot give any attributes to single faces, i guess.....

                  so that's the trouble.

                  but i can gerate these objects per hand too (face by face), so i will be able to use the 'attribute' option.

                  regards stan

                  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