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

Entity Attribute !?

Scheduled Pinned Locked Moved Developers' Forum
9 Posts 5 Posters 422 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.
  • M Offline
    mtriple
    last edited by 13 Aug 2014, 11:45

    im trying to modify a plugin to have more features. im noob so i might be wrong.
    i added an array that store "Entities Attributes".
    i need to deal with the Entities.
    when i use "Entities[0].erase!" it works.
    but when i retrieve the "Entities Attributes" and use it with ".erase!" does not work.
    i need way for retrieving the Entities it self from "Entities Attributes" or a way for dealing with Entities by "Entities Attributes".

    im using rubyeditior :
    E.g Entity: #Sketchup::Edge:0xaa527e0
    if u have a website that has all thees inf i will be glad.

    i searched google and dev website couldnt find what i want. thx for help anyway.

    compospray workin 2014

    1 Reply Last reply Reply Quote 0
    • T Offline
      tt_su
      last edited by 13 Aug 2014, 12:13

      I'm sorry, but what do you mean by "Entities Attributes"? I'm a bit confused if you are dealing with an Entities collection, a sub-class of an Entity or an attribute here.

      You mentioned: "Entities[0].erase!"
      What is "Entities" here? Capital letter indicate class/module or constant. But is that the name of your array?

      Do you have a code snippet showing what you are trying to do?

      1 Reply Last reply Reply Quote 0
      • M Offline
        mtriple
        last edited by 13 Aug 2014, 13:23

        sry for that. its "entities[0].erase!" no Capital letter
        thiss pic for what i mean by Entities Attributes.

        http://i375.photobucket.com/albums/oo199/mtriple1/Untitled_zps25bd5e21.jpg

        and this one is a box message for myarray.to_s contents.

        http://i375.photobucket.com/albums/oo199/mtriple1/111_zps0b8554b2.jpg

        and thiss the code i want to add : for deleting array content i might need use each i dont know but i tried use 1 content does not works.

        http://i375.photobucket.com/albums/oo199/mtriple1/1112_zps3b3acad7.jpg

        compospray workin 2014

        1 Reply Last reply Reply Quote 0
        • A Offline
          Aerilius
          last edited by 13 Aug 2014, 14:08

          What is the plugin that you want to modify, what does it do and what exactly do you want to achieve in your modification?

          This would be good to know so we can help because the example has several issues:

          • Whatever plugin it is, it uses global constants $MTtool_edg (which is so bad it's even banned from Extension Warehouse).
          • it uses convoluted half-abbreviations. In Ruby, human language and meaningful names are preferred, rather not abbreviations, and in no case anything in between. Consistency is all in programming. Bad naming leads to unmaintainable code and errors.
          • your added method accesses that global constant that has been set from outside. That is risky because you don't have control over what value it currently has. It is the best example of a side effect and side effects are better to avoid. There is certainly a better way how we can achieve what you want.

          Have you discovered the official API documentation , where you can browse hierarchically what you need? For example you have a Sketchup::Edge and you go to that class (and also "parent" on that page) and see everything you can do with an edge.

          1 Reply Last reply Reply Quote 0
          • D Offline
            Dan Rathbun
            last edited by 13 Aug 2014, 17:42

            Learn basic Ruby before using the SketchUp API.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • M Offline
              mtriple
              last edited by 13 Aug 2014, 19:15

              thx all. but that didnt help. i know about $ global var. but i need to use the var inside 2 classes. 1st class for store the entity, 2nd to modify it. thiss how the plugin work i dont want to modify whole plugin. im not interested in sharing on EXTENSION Warehouse. i only do that for my own use.
              i will try the Resources u provide. thx for ur time anyway.

              compospray workin 2014

              1 Reply Last reply Reply Quote 0
              • D Offline
                Dan Rathbun
                last edited by 13 Aug 2014, 19:35

                @mtriple said:

                i added an Array that store "Entities Attributes".

                ... but when i retrieve the "Entities Attributes" and use it with " .erase!" does not work.

                Because, erase!() is a Sketchup::Drawingelement instance method (inherited by subclasses.)

                The Ruby standard class Array, is NOT a subclass of Sketchup::Drawingelement, so it does not inherit an erase!() method.

                However, class Array has it's own delete_at() method.
                So you can use ents_array.delete_at(0) to erase the first array member.

                Or... you can use ents_array.shift, which erases the 1st member but returns it from the method call. This can be used to store the 1st member in another reference. Like:
                item1 = ents_array.shift

                🤓

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • T Offline
                  TIG Moderator
                  last edited by 13 Aug 2014, 21:12

                  model = Sketchup.active_model
                  Then
                  entities = model.entities
                  OR
                  entities = model.active_entities
                  Gives you a reference to a 'collection' of entities.
                  Do not iterate that collection in a way that removes items, because it dynamically changes the collection so you get unexpected results: instead you need to 'freeze' it as a snap-shot array first:
                  ents = entities.to_a
                  Then you can erase any element in the array by iteration - although I recommend you test for its validity beforehand - for example in your array you have some previously deleted entities, and erasing an edge deletes its face you might have not looked at yet:
                  entities.to_a.each{|e| e.erase! if e.valid? }
                  Which will avoid errors.
                  You can more efficiently delete a whole set of entities in one go, thus:
                  entities.erase_entities(entities_to_a)
                  or even the blunt:
                  entities.clear!
                  If you pre-process the array that is passed - so perhaps you only delete the faces - you limit the deletions, thus:
                  entities.erase_entities(entities.grep(Sketchup::Face))
                  ...
                  Please learn how to filter and process array lists...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • M Offline
                    mtriple
                    last edited by 13 Aug 2014, 23:25

                    thx u all. that was useful ill replay since i do some changes.

                    compospray workin 2014

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

                    Advertisement