sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Naming an entity

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 943 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.
    • S Offline
      satay
      last edited by

      I've just started coding in ruby for sketchup and this forum really rock on helping me getting started.

      I wanted to created a line, name it, set attribute to it and be able to return to that particular line ( I mean selecting it) by stating its name in ruby script after sketchup is re-started. Do I need to make the line into group or component in order to do it ?

      Can I export the entity name ( in this case a line) and its attribute to a file (a csv or database file) ? If database can be used, what type of database ? Can I use MySQL and how do I read the database file into sketchup ?

      Thanks guys for all the help in this forum.

      1 Reply Last reply Reply Quote 0
      • gillesG Offline
        gilles
        last edited by

        Welcome here satay,
        I think you should post in the Developer's forum http://forums.sketchucation.com/viewforum.php?f=180.
        πŸ’­

        " c'est curieux chez les marins ce besoin de faire des phrases "

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

          I've moved this into its proper place in the Developers' Forum.
          You can only 'name' groups, component-definitions, component instances, materials, layers etc as this list shows.names.PNG https://developers.google.com/sketchup/docs/methods#index_n
          You can get the names of more things than you can assign names to in code...

          So you can't create a line [Edge] and 'name' it however you could assign an attribute to it and find it using that... However, be aware that over-drawing a line or perhaps an erase+undo might well loose the original edge and thereby its 'name' attribute...

          Assuming you have an edge using the reference 'edge'... then use...
          edge.set_attribute("Satay","edge_name","fred")
          or whatever name you want to assign...
          repeat for other edges with different names...
          then later on...
          edge_names = {} Sketchup.active_model.entities.each{|e| next unless e.is_a?(Sketchup::Edge) edge_names[e.get_attribute("Satay","edge_name","")] = e }
          Now you have a hash of all edges in the model by 'name'.
          So test_edge = edge_names["fred"] should return an edge that's assigned that name, or 'nil' if there's no match for the name. If there are edges with the same name then the last one found will be returned as 'test_edge'.

          Now do stuff with the matching edge, if found... πŸ€“

          TIG

          1 Reply Last reply Reply Quote 0
          • S Offline
            satay
            last edited by

            Thank you very much TIG for the prompt and in depth reply.

            There is a lot of info to digest and I will try it out.

            Thank you again.

            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