SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
38 stars 10 forks source link

SketchUp distro'd style files have bracketed style names #714

Open DanRathbun opened 3 years ago

DanRathbun commented 3 years ago

SketchUp Ruby API Documentation Issue

Surprise! Native styles distributed with SketchUp have square brackets around their names and descriptions. When loading style files via Sketchup::Styles#add_style it comes as a surprise that strings properties are "bookended" with square brackets. Ie, the "Simple Style" actually has this name: "[Simple Style]".

If an existing style is loaded into the model again the differencing number is added to the end outside of the brackets. ie: "[Simple Style]1"

The documentation does not mention either the brackets nor the differencing.

So coders trying to get a reference via the Sketchup::Styles#[] method are clueless as to why the style is not found.


Would I be correct in assuming that the bracketing is used as marks for SketchUp to localize distributed style names and descriptions for the interface ?


In addition the result of the #add_style method is boolean when the average coder would expect a reference to the newly loaded style. Likely this cannot be changed at this late date.

So we are forced to do the snapshot and array subtract routine ...

  before = styles.to_a
  success = styles.add_style(path, false)
  if success
    style = (styles.to_a - before).first
    # ... etc ...

A pattern like the above would be a benefit to the code example in the docs. IE:

folder = Sketchup.find_support_file('Styles')
filename = 'MyStyle.style'
filepath = File.join(folder,filename)
styles = Sketchup.active_model.styles
before = styles.to_a # snapshot
status = styles.add_style(filepath, false)
if !status
  # ... bailout ...
else
  style = (styles.to_a - before).first
  # ... use style, etc ...
end
thomthom commented 3 years ago

Yea, I think this relates to localization.