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

Naming components

Scheduled Pinned Locked Moved Developers' Forum
11 Posts 3 Posters 553 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.
  • F Offline
    Frankn
    last edited by 25 Feb 2012, 08:45

    I'm having a problem with a seemingly simple task. how can I add both a Name and Defintion Name to a component that contains subcomponents?

    I can add both to an instance of the subcomponents without a problem but I can only manage to add the Defintion Name to the parent component.

    I've read and searched but can't find a solution. 😳

    
    def=model.definitions.add @name + " (test def)" 
    entities=def.entities
    
    ins=entities.add_instance @def_test, [0, 0, 0]
    name=ins.name=@name + " (test ins)"
    
    

    Thanks,
    Frank

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 25 Feb 2012, 11:15

      @frankn said:

      I'm having a problem with a seemingly simple task. how can I add both a Name and Defintion Name to a component that contains subcomponents?

      I can add both to an instance of the subcomponents without a problem but I can only manage to add the Definition Name to the parent component.

      I've read and searched but can't find a solution. 😳

      
      > def=model.definitions.add @name + " (test def)" 
      > entities=def.entities
      > 
      > ins=entities.add_instance @def_test, [0, 0, 0]
      > name=ins.name=@name + " (test ins)"
      > 
      

      Thanks,
      Frank
      You can't use 'def' as a reference - it's reserved for 'methods', try 'defn' instead.

      defn=model.definitions.add(@name + " (test def)")
      tr=Geom;;Transformation.new()
      ins=defn.entities.add_instance(@def_test, tr)
      name=ins.name=@name + " (test ins)"
      

      Should work ??

      TIG

      1 Reply Last reply Reply Quote 0
      • D Offline
        Dan Rathbun
        last edited by 25 Feb 2012, 11:45

        You can assign a value to the name attribute to a particular Sketchup::ComponentDefinition as many times as you like, but after the first time, you will be re-assigning a new value.

        Keep in mind that, Rubywise, when you say definition, you really are talking about an instance of the Sketchup::ComponentDefinition class.

        And.. when you say, instance, we are talking about an instance of the Sketchup::ComponentInstance class.

        BOTH of these two class objects have an instance method, that allows assigning a (usually String) value, to an instance variable.
        The method identifiers, are the same (and likely the attributes, ie, instance variables,) " name".

        NOW... you may be a bit confused. Every Sketchup::ComponentInstance instance, has a Sketchup::ComponentDefinition instance, that describes it's properties, and if it is not unique, holds a list of all it's other siblings in the model.

        OK.. you do not attach OTHER Sketchup::ComponentDefinition instances to / beneath / inside of another Sketchup::ComponentDefinition. Instead, you attach Sketchup::ComponentInstance instances, (who are described by Sketchup::ComponentDefinition instances,) to ANOTHER Sketchup::ComponentDefinition instance, that has nested components.

        SO.. the actual nested objects... are Sketchup::ComponentInstance instances, never Sketchup::ComponentDefinition instances.

        Think of a Sketchup::ComponentDefinition instance as being a specification, and all the Sketchup::ComponentInstance instances OF IT, as being the articles built TO the specification.

        Lastly... all the Sketchup::ComponentDefinition instances, are kept at the model level, (all in one drawer of specifications, so to speak.) Accessed via the model.definitions() method.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 25 Feb 2012, 11:52

          And you should be using an editor like Notepad++ that has syntax highlighting, to avoid attempting to use keywords as variable names.

          301 Moved Permanently

          favicon

          (notepad-plus-plus.org)

          see: [url=http://forums.sketchucation.com/viewtopic.php?f=180&t=39783:2pgebma3][Info] Notepad++ : Tip, Tricks & Plugins[/url:2pgebma3]

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • F Offline
            Frankn
            last edited by 25 Feb 2012, 18:04

            Thanks for the replies.

            Sorry for using def as a reference, I'm not using that in my plugin code it was just as an example... though I didn't know not to use it... learn something new everyday. πŸ˜„ I got used to komodo edit for some reason even though seems like Notepad ++ is what most use.

            Now, that being said... Dan you're 100% correct I'm totally confused 😳 πŸ˜„ . And I'll have to reread your post a few times to get it straight, thanks for taking the time to explain the differences in detail.

            TIG, using your code I get the same result as I am now. Which is my parent component has a definition name but no name and the child component has both. I know I'm probably not explain what I'm trying to do properly since as already stated I'm confused. πŸ˜• πŸ˜†

            Here's something I found that resembles what I want to do other then I'm not working with groups...

            From a post by ThomThom, here...
            http://forums.sketchucation.com/viewtopic.php?f=180&t=23567

            group = model.active_entities.add_group(sel)
                  name = model.definitions.unique_name(input[0])
                  # We set the name we will see in the Entities window.
                  group.name = name
                  # We set the definition name as well. If you convert the group to a component, this is the
                  # name it will get.
                  group.entities.parent.name = name
            
            

            And also from TIG, here...
            http://forums.sketchucation.com/viewtopic.php?f=180&t=23311

            instance=group.to_component
            definition=instance.definition
            definition.name="My Definition's Name"
            instance.name="My Instance's Name"
            
            

            Hope that helps making what I'm trying to do clearer...
            Thanks,
            Frank

            1 Reply Last reply Reply Quote 0
            • T Offline
              TIG Moderator
              last edited by 25 Feb 2012, 19:12

              The code I offered you was simply a corrected version of yours.

              The code makes a new definition ['defn'] assigning it a new name [all definitions must have a unique name].
              The code then adds an instance of another preexisting component [again that definition must have a unique name of its own] into the entities of 'defn'.
              When that the instance is added it has no name [the default].
              The code then gives that instance a name.
              It also assigns a variable 'name', but does nothing with it.
              The code then stops.

              If you were then to add an instance of 'defn' it would obviously display that component's definitions name [all instances of that definition will!]... However, an instance will not have a name, because by default a new instance does not have a name.
              Of course you could give that instance any name you like... perhaps using 'name'...
              πŸ˜•

              TIG

              1 Reply Last reply Reply Quote 0
              • F Offline
                Frankn
                last edited by 25 Feb 2012, 19:24

                @tig said:

                The code I offered you was simply a corrected version of yours.
                If you were then to add an instance of 'defn' it would obviously display that component's definitions name [all instances of that definition will!]... However, an instance will not have a name, because by default a new instance does not have a name.
                Of course you could give that instance any name you like... perhaps using 'name'...
                πŸ˜•

                Ok so far I understand that logic and I'm aslo able to put it onto practice... except for the part I highligthed in bold... which correctly explains what I'm not able to do. I don't get where I should add the 'name' part. the only way I can think of is by

                defn_new=entities.add_instance defn, [0, 0, 0]
                

                but I get a double occurance error. And everything else I've tried will change the defintion name and not add an instance name.

                Perhaps it's in how I add the instance of defn to the model that is the problem(I hope I'm using the correct term, still a little confused)?...

                status=model.place_component(defn)
                
                1 Reply Last reply Reply Quote 0
                • T Offline
                  TIG Moderator
                  last edited by 25 Feb 2012, 20:48

                  dins=model.active_entities.add_instance(defn, tr) dins.name=name
                  The model.place_component(defn) is like picking ' defn' off the Component-Browser.
                  You'll get no 'reference' to it this way - so naming it is difficult - because it'd be the only instance defn.instances[0] would refer to it, BUT the ' place_component' will break your code when it's invoked - a convoluted observer set up might work BUT there are other easier ways...
                  Use add_instance and then if you want the instance [ dins] to be movable thereafter you can write your code as a 'Tool' class and then have the transformation of din reset dynamically to always be at the cursor's point, and when you left-click the mouse it'd set dins's transformation to be at the clicked point...
                  BUT perhaps that is too complex for now πŸ˜•

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • F Offline
                    Frankn
                    last edited by 25 Feb 2012, 21:19

                    I knew that model.place_component was too good to be true! πŸ˜„

                    @tig said:

                    Use add_instance and then if you want the instance [ dins] to be movable thereafter you can write your code as a 'Tool' class and then have the transformation of din reset dynamically to always be at the cursor's point, and when you left-click the mouse it'd set dins's transformation to be at the clicked point...
                    BUT perhaps that is too complex for now πŸ˜•

                    Ok, I have no idea what all that means but I'm game to learn it! Could you point me in the right direction? Maye a plugin that already does something similiar or a code snippet to get me started?

                    Thanks for the help TIG!

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      Dan Rathbun
                      last edited by 25 Feb 2012, 23:39

                      @frankn said:

                      Sorry for using def as a reference, I'm not using that in my plugin code it was just as an example... though I didn't know not to use it... learn something new everyday. πŸ˜„

                      They are called "reserved" keywords for good reason. Their misuse will confuse the poop out of the Ruby interpreter.

                      Here's a URL bookmark for ya':
                      Ruby Keywords

                      @frankn said:

                      I got used to komodo edit for some reason even though seems like Notepad ++ is what most use.

                      Well as long as it has syntax highlighting for Ruby, that shows keywords, and classes in a different color than user defined variables... it's OK. I also know some people are partial to NetBeans.

                      That's what syntax highlighting is all about. Helping you to not make those kind of mistakes.

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • F Offline
                        Frankn
                        last edited by 26 Feb 2012, 00:56

                        Thanks for the link Dan... that's the kind of info that seems trivial till you run into a problem. πŸ˜„

                        Yeah Komodo does all that good stuff plus the pro version does a bunch of other stuff and even debugging for ruby, I think. But I tried it and it had too many bells and whistles for a newbie like me and was confusing!

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

                        Advertisement