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

    Issues with set_attributes Method and Components

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 6.0k 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.
    • medeekM Offline
      medeek
      last edited by

      For almost two years now I have been pulling out my hair trying to figure out why my start_operation and commit_operation in the truss module was throwing an error, see this thread:

      Link Preview Image
      Ruby operation left open

      I’ve had this bug in my plugin for a while. My code is: # Get handles to our model and the Entities collection it contains. @model1 = Sketchup.active_model entities = @model1.entities if @Trusstype == "King Post" @…

      favicon

      SketchUp Community (forums.sketchup.com)

      I finally had enough with this (minor) bug and pulled apart my code and systematically eliminated everything until I came to this single block of code (which is the cause of the error):

       da = 'dynamic_attributes'
          t_def.set_attribute da, 'trussfamily', @Trussfamily
          t_def.set_attribute da, '_trussfamily_label', 'TrussFamily'
          t_def.set_attribute da, '_trussfamily_formlabel', 'Truss Family'
          t_def.set_attribute da, '_trussfamily_units', 'STRING'
          t_def.set_attribute da, '_trussfamily_access', 'VIEW'
      

      With this block I am trying to set an attribute on the truss component using the dynamic attributes library. For some reason SketchUp does not like it and it makes the operation methods above blow up.

      Alternatively I thought why not forego the dynamic library stuff and just try this:

      lib = 'medeek_truss_eng'	
          t_def.set_attribute lib, 'trussfamily', @Trussfamily
      

      However, it does not seem that one can set attributes to a component definition, which is very frustrating.

      I'm now looking for a way to set attributes to a component definition (without side effects), if this possible, but I'm coming up empty.

      Nathaniel P. Wilkerson PE
      Medeek Engineering Inc
      design.medeek.com

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

        You should be able to set attributes for almost anything in SketchUp - including component-definitions...
        However, if these attributes are to be reused later, then you must do it by getting/setting the definition's attributes, NOT by getting/setting the attributes of an instance of the definition.

        Is that perhaps where you are tripping up ?

        Instances and definitions are quite separate things, so decide what you want to test/affect...

        PS: In your example '@Trusstype' must be a compatible 'type' of data - I assume it's a string ?
        Most 'types' are usable, but one of the few 'types' you need to tweak is a 'hash' - which can be converted to an 'array' for storage, and back again into a 'hash' when it's read back in...

        TIG

        1 Reply Last reply Reply Quote 0
        • medeekM Offline
          medeek
          last edited by

          The variable "t_def" is the component definition so I am feeding it the definition and not an instance. However in my second example it does not seem to work.

          Yes, @Trussfamily is a string.

          Nathaniel P. Wilkerson PE
          Medeek Engineering Inc
          design.medeek.com

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

            How do you 'know' for sure that setting the definition's attribute fails ?
            You give insufficient detail.
            If you use get_attribute() on the exact same definition [or instance.definition] you used set_attribute() on, then it should work.

            Make sure the attribute-dictionary-name and the key are exactly the same in both cases, and that you have a default value set up too - like result = t_def.get_attribute(lib, 'trussfamily', 'WTF!').
            If result == @Trussfamily it's working, but if result == 'WTF!' it's not !

            Make sure you have presets for the 'value' set/get @Trussfamily, and of course the ' lib' - which should be the string-name of the dictionary, e.g. lib = 'medeek_truss_eng'.

            It a dictionary of that exact name doesn't exist it's made, if it exists then it's reused...
            Personally I'd use dictionary name starting with an uppercase letter, and all keys in lowercase.
            There's less confusion that way...

            To check what's dictionaries and keys/values are attached to a definition use something like this.

            if t_def.attribute_dictionaries
              t_def.attribute_dictionaries.each{|d|
                puts "DICTIONARY == #{d.name}"
                d.each_pair{|k, v|
                  puts "#{k} = #{v}"
                }
              }
            else
              puts "NO DICTS !"
            end
            

            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