Dynamic Component Length Parameters ???
-
Greetings,
I'm experimenting with reading, and eventually setting, attributes within dynamic components. I feel I'm making good progress, but I've come upon an issue that puzzles me. Attached to this message is a dynamic component I've created, and also a snippet that I'm running via the web console. The snippet burrows down into the component and provides the keys and their values. However, although it lists the formulas for the component coordinates (e.g. the formulas for x,y, and z), it does not provide the formulas for the lenx, leny or lenz parameters - it only gives their resultant values.
Specifically, the "Pier Footing" component's lenx, leny, and lenz parameters are all specified via formulas. Yet the listing only gives their resultant values. However, the snippet does list the formula for the z-coordinate for this component.
If you wanted to read/set the length formulas, how would you do so?
Thanks!
-
There is an AttributeDictionary (also named "dynamic_attributes") attached to the Definition, which is the one of more interest. I think the AttributeDictionary which is attached to an instance is more of a temporary store, and used for attribute values which differ from the Definition's.
-
THANK YOU Jim! Indeed, when I loop through the attributes of the component definition I seem to be getting both the formulas and the resultant formula values for the len attributes.
You're the best! Now I can experiment with setting attribute values. Here's my snippet to read the attributes for both the definitions and the instances...
model=Sketchup.active_model defs = model.definitions puts "" puts "----------------------------------" puts "Script starting..." puts "----------------------------------" puts "" puts " Starting the Component Definition Phase..." puts "" defs.each do |x| puts " Definition name; " + x.name x.attribute_dictionaries.each do |y| puts " Dictionary name; " + y.name if y.name == "dynamic_attributes" y.each_pair {|k,v| puts " Key; " + k + ", Value; " + v.to_s} end end puts "" end puts "" puts "----------------------------------" puts "" puts " Starting the Instance Definition Phase..." puts "" entities=model.entities entities.each do |e| if e.class==Sketchup;;ComponentInstance puts " We've got an INSTANCE named ... " + e.name e.attribute_dictionaries.each do |g| puts " Dict name; " + g.name g.each_pair {|k,v| puts " Key; " + k + ", Value; " + v.to_s} end puts "" subEntities=e.definition.entities puts " Number of subentities; " + subEntities.count.to_s subEntities.each do |f| if f.class==Sketchup;;ComponentInstance puts " We've got a NESTED component" puts " Name of component instance; " + f.name f.attribute_dictionaries.each do |e| puts " Dict name; " + e.name e.each_pair {|k,v| puts " Key; " + k + ", Value; " + v.to_s} end end end end end
-
You're welcome, I'm glad it helped.
In anticipation of your next question, this is how I have seen recommended as the way to redraw an DC Instance.
Assume a single instance has been selected:
ins = Sketchup.active_model.selection[0] $dc_observers.get_latest_class.redraw_with_undo(ins)
-
Jim (and all),
In anticipation of your next question,... <<
Yes! That works for me. I just set an attribute of a selected DC and it did indeed respond on-screen.
Let me ask you one more question please - and anyone else who's programmed DCs please feel free to give your advice as well.
I'm a bit surprised that there's not more traffic here in the forum concerning this topic of reading and setting DC attributes. I would have thought that this would be the next step from using lots of groups within a model. Maybe I'm missing something?
Maybe I should give an example of what I'm hoping to do. I developing my own version of a housebuilder program by using Steve Hurlbut's program as a guide (thanks Steve, wherever you are). He's using groups (I'm guessing components were not around in '05), so I thought I would try using DCs. In the most simple case, lets say you define a wall stud as a DC, with parameters that define the nominal size (2x4, 2x6,...) and the length. Then, as you bring new studs into the model, you set their size and length appropriately. My assumption here is that this would be superior to using groups. Am I wrong about this? Or are there issues with DCs that make this impractical?
Again, thanks for your help!
-
My guess would be that DC's are just not entirely well explored by most users. I think lots of people have never taken the time to learn how to really make them very well, if at all.
I started learning hot to make DC's before I knew any ruby. They pushed me in to ruby, once I realized I had lots bigger ideas than a DC accomodate. So now I wonder what advantage does using the DC framework give you in your script making? They just seem like a headache to interface with through ruby. I hope you prove me wrong.
Chris
-
Chris,
Thanks for your reply.
So now I wonder what advantage does using the DC framework give you in your script making? <<
I was buying into the belief that components consume less resources - but even if they generally are more efficient, I'm not sure that applies when you use dynamic components. If you have 10 instances of a dynamic component within a drawing, each with different parameter settings, then are you still saving resources or has it just copied that component 10 times? I don't know how they've been constructed.
They just seem like a headache to interface with through ruby. <<
I'm getting that feeling.
Thanks again
-
I also started to play with dynamic components as a way to put some info. But extracting all this information is a big pain - SketchUp's Generate report is a big mess - only inches and a lot of useless data!
Advertisement