Possible to import DC attribute values?

Possible to import DC attribute values?

Postby marksolberg » Tue Nov 25, 2008 12:25 am

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 7

Perhaps with a custom Ruby script?

Thanks,
Mark
0

marksolberg 
 

Re: Possible to import DC attribute values?

Postby chrisglasier » Tue Nov 25, 2008 12:40 am

marksolberg wrote:... Basically I would like to use Sketchup to visualize performance data.


Anything useful here:

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
0
With JSON machines we can analyse what is to be achieved so that IT can help with automation to achieve it.
User avatar
chrisglasier 
PluginStore Author
PluginStore Author
 

Re: Possible to import DC attribute values?

Postby chrisglasier » Tue Nov 25, 2008 1:05 am

Correct link is this:
viewtopic.php?f=180&t=14299

Sorry

Chris
0
With JSON machines we can analyse what is to be achieved so that IT can help with automation to achieve it.
User avatar
chrisglasier 
PluginStore Author
PluginStore Author
 

Re: Possible to import DC attribute values?

Postby marksolberg » Tue Nov 25, 2008 3:31 am

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
0

marksolberg 
 

Re: Possible to import DC attribute values?

Postby Jim » Tue Nov 25, 2008 3:35 am

marksolberg wrote: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 7

Perhaps with a custom Ruby script?

Thanks,
Mark


Welcome 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:

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)
0
Hi

Jim 
Global Moderator
 

Re: Possible to import DC attribute values?

Postby marksolberg » Tue Nov 25, 2008 4:07 am

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
0

marksolberg 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Dynamic Components

Who is online

Users browsing this forum: No registered users and 1 guest

Visit our sponsors: