sketchucation logo sketchucation
    • Login
    1. Home
    2. scottlininger
    3. Posts
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 7
    • Posts 168
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: Setting dynamic attributes to expressions?

      Rich,

      You can set attributes and their formulas using the API, but it's not a documented process, unfortunately. Here's a kick start.

      All of the attributes are stored inside an AttributeDictionary called dynamic_attributes, as you discovered. In addition to the attribute's value, there are a series of "meta attributes" that describe properties of the DC attribute. These start with underscores, and they must be defined to work properly with the DC plugin. (They attribute keys are all lowercase.)

      Let's say you have an attribute called "FavoriteColor" that you manually create in the Component Attributes window. These are the attributes that the DC plugin would create if you made it end user editable (and therefore, these are the attributes your plugin would need to make to do it in Ruby code...)

      favoritecolor = "Red" # The raw value of the att.
      _favoritecolor_formula = "" # The formula, if set.
      _favoritecolor_label = "FavoriteColor" # The "cased" name of the att
      _favoritecolor_access = "TEXTBOX"

      access = "NONE" if consumers can't see or edit this attribute

      = "VIEW" if consumers can see this attribute

      = "TEXTBOX" if consumer can enter a value for this attribute

      = "LIST" if consumers can select a value from a list

      _favoritecolor_options = "Pink=pink&Red=255,0,0&Blue=blue" # url encoded list
      _favoritecolor_units = "STRING"
      _favoritecolor_formlabel = "Favorite Color"

      I wish I had complete documentation for all of this to share, but the best I can offer at the moment is a willingness to help. The best thing to do would be to use an attribute reading script to watch what attributes get set when you do things in the DC UI.

      Here's a code snippet that demonstrates creating some new attributes on the Sang component...

      UI.menu("Plugins").add_item('Make Sang Red') {
      
        # Assumes that sang is the 1st entity in model.
        sang = Sketchup.active_model.entities[0]
        sang_def = sang.definition
      
        # Override sang's shirt color to red. ("material"
        # is a special attribute that requires
        # you to set a formula to "take control" 
        # over the default material the user has painted.)
        sang_def.set_attribute 'dynamic_attributes',
          'material', 'red'
        sang_def.set_attribute 'dynamic_attributes',
          '_material_formula', '"red"'
      
        # Add a new configurable option to Sang.
        # (Any attribute that starts with an underscore
        # is a "meta attribute" that describes behavior.)
        sang_def.set_attribute 'dynamic_attributes',
          'weight', '145'
        sang_def.set_attribute 'dynamic_attributes',
          '_weight_label', 'weight'
        sang_def.set_attribute 'dynamic_attributes',
          '_weight_formlabel', 'My Weight'
        sang_def.set_attribute 'dynamic_attributes',
          '_weight_units', 'STRING'
        sang_def.set_attribute 'dynamic_attributes',
          '_weight_access', 'TEXTBOX'
      
        # Change the description that shows
        # up in the configure box with a custom
        # formula.
        sang_def.set_attribute 'dynamic_attributes',
          '_description_formula', 
          '"Sang is now red and weighs " & weight'
      
        # There is a global handle into the plugin that
        # allows you to make the same calls that the
        # plugin does, like so...
        dcs = $dc_observers.get_latest_class
        dcs.redraw_with_undo(sang)
      
      }
      
      posted in Developers' Forum
      scottliningerS
      scottlininger
    • RE: DC - 6Β² isn't written 6^2?

      Hey guys,

      We haven't forgotten about this. It's a surprisingly non trivial thing to fix. The actual coding is easy, but then we're introducing a new "version" of DCs that won't work on older Sketchup installs. Your DC that uses ^ would work great in SU 7.1, for example, but not work in 7.0.

      If your reply to that is "who cares! people can get a free upgrade!", then let me know and I'll add that to the feature request. In general, we lean toward backwards compatibility.

      Cheers,

      posted in Dynamic Components
      scottliningerS
      scottlininger
    • RE: SU 7,1 issue with Scale&Rotate Multiple ruby

      Hey everyone,

      If you see bugs with 7.1 and Ruby, please share a detailed post with the following information:

      1. Your OS (Mac, XP, Vista, etc.)
      2. Exact steps to reproduce
      3. A keyword or email that you typed into the bug splat screen
      4. Does it happen if you uninstall all other scripts?

      Thanks,

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • RE: Right click menu disabled???

      Is everyone else having this problem using Vista?

      posted in SketchUp Bug Reporting
      scottliningerS
      scottlininger
    • RE: Right click menu disabled???

      Hey guys,

      Some questions for the folks who are having this problem:

      1. What operating system are you using?

      2. What exact version of SU are you running?

      3. The problem is described as "right click" menus. Is it only Ruby items that are grayed out, or are all of them grayed out?

      Hopefully we can track it down...

      Cheers,

      posted in SketchUp Bug Reporting
      scottliningerS
      scottlininger
    • RE: New API doc - typos and questions

      @thomthom said:

      How much of this thread have you processed Scott?
      I think I'm loosing track of what I have reported.

      I have a lot of catch up to do. I have a paper copy here that I've marked as I update. I'll remerge that back into the forum soon.

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • RE: New API doc - typos and questions

      @thomthom said:

      @unknownuser said:

      It is like observers. It doesn't actually have to be a subclass to work. Any object that replies to the nextFrame callback can be used as an animation.

      Isn't observer like that as well? I realised once that I had used the wrong observer class as a base, but the observer still worked.

      Yes, that's how observers are as well.

      πŸ˜„

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • RE: New API doc - typos and questions

      It is like observers. It doesn't actually have to be a subclass to work. Any object that replies to the nextFrame callback can be used as an animation.

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • RE: New API doc - typos and questions

      I've got some catching up to do. Thanks for all of the details, guys! πŸ˜‰

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • RE: Where lies the bug?

      Thom,

      Can you filter the weirdness down to a few lines of Ruby and post? Sounds like SketchUp is using one unused cell of the transform matrix to store some scale information. I have no idea why, but there's probably a legacy reason for it.

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • RE: [prototype] Doublecut (0.1.0a) - Need help debugging

      Thom,

      Fantastic idea!

      One thing that might make your script simpler would be use a flattened copy of the window component to cut the 2nd hole instead of creating a new definition or group. (One less thing to keep track of and would keep the file size small.) However, I do like the idea of hiding all of the geometry inside the new hole to keep it out of the way... which wouldn't work with this approach.

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • RE: Can something cancel observer events?

      @thomthom said:

      Back to the drawing board. I think I need to make some sort of queuing system for actions to perform. Though, I'm not sure 'when' I can apply them safely.

      I haven't done too much experimentation with it, but I suspect that the timer approach would work safely.

      Another idea: have you played with onTransactionCommit? In theory, you could queue up your "stuff to do", and then do it all inside this handler. I haven't tried that ever, but in theory that event shouldn't be called until everything else is done.

      @thomthom said:

      And the thing about the Tools observer, that monitor user actions. But what if other plugins do modification to the geometry I'm watching?

      You might create an API that allows other developers to manually call your "handleChange" code. You wouldn't catch every plugin out there, but for the popular ones you might be able to coordinate with the authors to do that for you.

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • RE: Can something cancel observer events?

      The event system inside SketchUp is not designed to allow changes to geometry inside an event handler. You have to be very careful about any changes to the model that you make here. Bugsplats are common.

      In some cases, the problem is that changes that you make can fire another event, which can lead to infinite loops or cancelled event chains.

      When I was working on DCs, I quickly learned that the onToolStateChange event is the one spot that you can safely alter the model without crashes. For example, instead of watching the entities to see if they're moved, watch the move tool and the selection to figure out what the user is moving, and react accordingly.

      Of course, the tool state doesn't always change exactly where and how you might like it to, but by keeping track of states in some local variables, you can figure out what's going on.

      As you work through all of this, please keep in mind that the new API docs need help for not only what is wrong or missing, but for additional notes about how and now not to use the observers. Keep on adding to the documentation to-do thread and over time we'll at least make it easier on future developers.

      Cheers,

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • RE: New API Object Diagram

      @jim said:

      Something I'm curious about - why is a ComponentDefinition a DrawingElement? It's clear why an ComponentInstance is_a DrawingElement, but not sure about why the Definition needs to be.

      The only reason that I'm aware of is so it inherits .bounds from Drawingelement. That's really the only Drawingelement method that makes sense in a definition context.

      Other than that? "Historical reasons." πŸ˜‰

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • New API Object Diagram

      We're happy to announce a new feature on the Ruby Docs site, an object hierarchy diagram for the core parts of the API. Hopefully this will make it easier for SketchUp programmers to groc how things are related.

      Thanks to our QA master, Simone, for putting this together. You can read his blog post here.

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • RE: Sketchup registry key ?

      From Steve P., our installer expert:

      For SU6:

      HKEY_LOCAL_MACHINE\SOFTWARE \Microsoft\Windows
      CurrentVersion\Uninstall{98736A65-3C79-49EC-B7E9-A3C77774B0E6}\InstallLocation

      For SU7:
      HKEY_LOCAL_MACHINE\SOFTWARE\Google\Google SketchUp 7\InstallLocation

      Cheers,

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • RE: Set_attribute and undo operations

      Jim,

      Consider trying something like this, which will group them into a single undo event...

      Sketchup.active_model.start_operation "Modify Attributes"
      # make multiple attribute changes here.
      Sketchup.active_model.commit_operation
      

      ...and if you're responding to an observer event, you might consider something like this, which will "append" your attribute changes to the previous event. See start_operation for details on the 3rd param...

      Smodel.start_operation "Modify Attributes", true, false, true
      # make multiple attribute changes here.
      model.commit_operation
      

      Hope that helps!

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • RE: New API doc - typos and questions

      From Didier's post:

      301 Moved Permanently

      favicon

      (www.sketchucation.com)

      Need to add an FAQ for getting to installation directory of SU, for folks trying to build installers (and find out a mac equivalent.)

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • RE: Sketchup registry key ?

      Hey Didier,

      I don't know the answer to that off the top of my head. Let me know if you have any trouble with Thom's answer and I'll ask the experts (not me!) πŸ˜‰

      This would be a good addition to the FAQ section of the documentation site. I'll add a note to get this done...

      Cheers,

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • RE: New API doc - typos and questions

      Self note: need to add an explanation of how add_face works in relation to which "side" of the face is inside vs. outside, and document the exception where faces drawn at z=0 are always drawn with inside facing upward.

      πŸ˜„

      -Scott Lininger

      posted in Developers' Forum
      scottliningerS
      scottlininger
    • 1
    • 2
    • 3
    • 4
    • 5
    • 8
    • 9
    • 3 / 9