Possible to import DC attribute values?
-
If I have a DC with a custom identifier attribute like ProductNum is it possible to import and set a different attribute, say LenZ based upon an external file? Basically I would like to use Sketchup to visualize performance data. An example file might be something like:
A34 3.5
B22 9
B33 7Perhaps with a custom Ruby script?
Thanks,
Mark -
@marksolberg said:
... Basically I would like to use Sketchup to visualize performance data.
Anything useful here:
http://www.sketchucation.com/forums/scf/viewtopic.php?f=180&t=14299 ?
or on my web site (click button on left). I am interested in the versatility of import/export with webdialogs, so please let me know what you think.
Chris
edit: corrected link
-
Correct link is this:
http://www.sketchucation.com/forums/scf/viewtopic.php?f=180&t=14299Sorry
Chris
-
Chris,
I couldn't get the video to play in the linked topic. I don't know that it would matter though. I think this is beyond my knowledge. I didn't make it past the first paragraph before I got that look a dog gets when they hear an unfamiliar sound. Thanks just the same.Mark
-
@marksolberg said:
If I have a DC with a custom identifier attribute like ProductNum is it possible to import and set a different attribute, say LenZ based upon an external file? Basically I would like to use Sketchup to visualize performance data. An example file might be something like:
A34 3.5
B22 9
B33 7Perhaps with a custom Ruby script?
Thanks,
MarkWelcome Mark,
It is possible, and actually not terribly hard to write a Ruby script to set some attributes from a file. It's a little late for me, but perhaps someone will pick this up in the morning.
Also, Scott Lininger has posted some good information on the subject, which I will quote here:
@unknownuser said:
Hey folks,
My name is Scott, and I'm one of the developers for DCs. I'll be
floating around the groups from now on to help with all things Ruby or
DC related. Hiya! First, let me say that we intend to provide more
docs and examples of using your own Ruby scripts alongside DCs, but
they are still under development, so I'll attempt to address specific
questions as they come up.bveina has figured it out most of the way: DCs are implemented purely
in Ruby, and all of the attributes that you can apply via the
Component Attributes window can also be applied directly with script.
There is a dictionary called "dynamic_attributes" that gets attached
to both the Instance and the Definition, and this contains the
attributes that drive DC behaviors.There are two kinds of attributes in these dictionaries: those that
start with an underscore are "internal" attributes that do not show up
in the Component Attributes window. Those that begin with anything
else are the "visible" attributes. Here's an example of some
attributes one might find in our dictionary (http://code.google.com/p/
sketchupattributemanager/wiki/Welcome is a place where one can get a
tool to view these attributes, and inspecting existing DCs is the best
way to start to understand how everything is stored.)x=55
_x_formula="5*11"
_x_label="x"As bveina's script shows, there's nothing particularly secret or
magical about setting these attributes. But how does one fire a
redraw? First, there is an instance of the dc observers mechanism,
which lives in this global variable:$dc_observers
This object is, as its name suggests, essentially a collection of
observers that watches for DC interactions, such as the scale tool,
move tool, or component placement. Anyway, here's a code snippet that
applies a color to Sang then redraws him (this assumes it's running in
a template with Sang already in it):sang_instance = Sketchup.active_model.entities[0]
sang_definition = sang_instance.definition
ad = sang_definition.attribute_dictionary "dynamic_attributes"
ad["_material_formula"] = '"Red"'
$dc_observers.get_latest_class.redraw_with_undo(sang_instance)The only reason that we have to set the "_material_formula" instead of
just the "material" is because Sang happens to contain formula
already, so just replacing the material and then firing a redraw will
result in the old formula overwriting your new value. (Formulas always
get recalculated with a redraw, and their result is stored into the
attribute.)Whew! How's that for a 10-minute intro.
As I say, all of this will be better documented soon, but that's no
reason to keep you from diving in! DCs are "just another Ruby script,"
after all.Cheers,
Scott Lininger
Sketchup Software Engineer(source)
-
Thanks Chris,
The info in your last post seems to be the type of info I'm looking for. I'll post this in a separate forum also, but do you have any recommendations as to where to start learning Ruby programming for Sketchup? About a hundred years ago I went to college for programming (pre-WWW days) but somehow ended up in the casino industry in a non-programming capacity. Wish I would have stayed with programming, I've always enjoyed it.Mark
-
@marksolberg said:
Thanks Chris,
The info in your last post seems to be the type of info I'm looking for. I'll post this in a separate forum also, but do you have any recommendations as to where to start learning Ruby programming for Sketchup? About a hundred years ago I went to college for programming (pre-WWW days) but somehow ended up in the casino industry in a non-programming capacity. Wish I would have stayed with programming, I've always enjoyed it.Mark
Good day. I have always liked the field of programming, I reported a lot of efforts to become a programmer, now I am programming in C ++. As for the casino theme, I like this business, I like to hang out in my free time https://forestcasinos.co.nz/casino-zodiac/. It helps me recover and relax from a hard day's work.
Advertisement