How can I access the layer name in a DC via Ruby?
-
I want to access to the layer name of the DC as a part of the formula, the closest I can get is via the use of class DCFunctionsV1 mentioned in the post, which I couldn't repurpose for this case; http://sketchucation.com/forums/viewtopic.php?f=180&t=37083
I'm wondering if there's an easier way, many thanks in advance.
-
Hi erkan,
There isn't a built-in DC function to get the Layer. If you want to do it, you will need to write your own function for it. Follow the examples in the topic you linked to.
This can also be done with a stand-alone Ruby script in SketchUp, but outside the DC framework. It could go through the model, identify DC's, then assign the DC's Layer to an attribute.
-
thanks Jim, just as I thought
so here's how I try to tinker with that example, basically I've taken out the volume and tried to replace it with the Layer Name of the DC as per below;
if defined?($dc_observers) # Open SketchUp's Dynamic Component Functions (V1) class. # only if DC extension is active class DCFunctionsV1 protected # return layername # Usage; =layername() def layername(a) return @source_entity.layer.name end protected;layername end#class end#if
And I've found that @source_entity.layer.name is not correct, and couldn't make much of meaning from the existing resources unless I start understanding the Ruby. Can anybody show me how to access the Layer Name of the DC (@source_entity?)
many thanks
-
That line of code should return the selected component-instance's layer's name ?
However, once the DC code has assigned the name you might need to refresh [apply] the DC code again to show the correct layer-name if you have changed the instance's layer since it was last interrogated. -
In theory yes, it should return the Layer Name that the DC lies on, so that I can use it for conditional calculations. In the planned workflow there will be no Layer changes, so that should be fine.
-
I have used it on a DC and it worked for me ??
require('sketchup') require('dynamiccomponents.rb') if defined?($dc_observers) # Open SketchUp's Dynamic Component Functions (V1) class. # only if DC extension is active class DCFunctionsV1 protected # Usage; =layername() if not DCFunctionsV1.method_defined?(;layername) def layername(a) ###puts @source_entity.layer.name return @source_entity.layer.name end protected;layername end end#class end#if
-
ehem worked for me too , apparently I missed the first two lines.
thanks TIG!
Advertisement