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

    Add DC-Attribut to group not show up

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 205 Views 2 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.
    • H Offline
      HPW
      last edited by

      I generate groups for my imported autocad-components to restore a hierachy.
      Now I would like to show some info in the 'Components Options' window when group is clicked.

      First I follow TIG's hint and add a definition to the group:

      class Sketchup;;Group
        def definition
          return self.entities[0].parent
        end
      end
      
      

      Then I do:

      ### Creating of the group from array
         group = entities.add_group(@group_list)
      
      ### Try to store attribut in group
      
         group_def = group.definition
         group_def.set_attribute 'dynamic_attributes', '_hasbehaviors', '1.0'
      
         group_def.set_attribute 'dynamic_attributes', '01_dummy', 'Dummy'
         group_def.set_attribute 'dynamic_attributes', '_01_dummy_label', '01_dummy'
         group_def.set_attribute 'dynamic_attributes', '_01_dummy_formlabel', 'This is a dummy attribute'
         group_def.set_attribute 'dynamic_attributes', '_01_dummy_units', 'STRING'
         group_def.set_attribute 'dynamic_attributes', '_01_dummy_access', 'VIEW'
      
         group_def.set_attribute 'dynamic_attributes', 'name', 'MyName'
         group_def.set_attribute 'dynamic_attributes', 'description', 'MyDescription'
         group_def.set_attribute 'dynamic_attributes', 'dialogwidth', '460'
         group_def.set_attribute 'dynamic_attributes', 'dialogheight', '550'
      
      

      The attribute gets stored in the dictionary, but opening the 'Components Options' window show only the default window with group.name and 'There are no options to choose on this component.'

      Maybe it is hardcoded that group can not have DC attributes?

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

        A Group can have attributes. A Component Definition OR Instance can too. However a Group is a special case. It has a definition BUT normally there should only ever be one instance of it - which is the group. A Group's definition is not normally used - however it is a way of moving a group into another group to avoid crashes. A Group is not acomponent so the Components Option window will not report its definition attributes.

        Solution: add the attributes to the Group itself and 'make_unique' to ensure that there are no duplicate instances of it. There shouldn't be... but a known bug means there can be... For example, using Ruby make a group of some geometry, copy the group, delete an edge in the copy and it'll sometimes also disappear in the original as if it were a component. Using make_unique on the copy returns a 'deprecated method' warning, BUT it works and groups are thereafter kept as individuals. If you copy a group within SUp then it is automatically made_unique. If you copy a group with Ruby and edit the contents of the copy manually the original is also made unique by that action... Just sometimes Ruby-copied groups are read as dupliactes of the same definition - which they should never be...

        Weird...

        TIG

        1 Reply Last reply Reply Quote 0
        • H Offline
          HPW
          last edited by

          TIG,

          Many thanks again for this tip.
          Since my groups are unique I tried to attach to the group itself.
          And it works!
          By the way: The make_unique throws a warning that it is depreciated.

          One problem pops up.
          The little image in the top left edge of the 'Components Options' window show normaly the component.
          Since the Group itself is no component it shows the last successfull loading image.
          I tried to set:

             group.set_attribute 'dynamic_attributes', 'imageurl', ''
          
          

          but this does not help.
          Not sure if I must point to a real image on the net or can I use a local file-url.

          Hans-Peter

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

            Unfortunately, as you say, a group is not a component !
            The group.make_unique is 'deprecated' BUT it works till it's fixed by Google...

            Why don't you make the group into a component, THEN you can probably use it as desired - inst=group.to_component - returns its instance OR defn=group.to_component.definition - returns its definition if you want to add to that... OR instn=defn.instances[0]to return what you just 'componentified' from the group...

            TIG

            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