Dynamic Components add sub DC

I have Dynamic Component which contains other DC. And I would like to add to main DC one more sub DC.

it is probably a very simple but in Warsaw is now 34 Celsius degrees and my mind…:wink:

model = Sketchup.active_model
cdef = model.definitions["Some DC Name"]
csub = model.definitions["Some DC SubName"]
t = Geom::Transformation::new([1,2,3])
ents = cdef.entities
ents.add_instance(csub,t)

Thanks, Dan.

When I insert new sub DC to the main DC is problem with the position of the sub DC. Main DC’s dimensions is 100,100,100 and the sub DC has dimensions 10,10,10. When I insert sub DC in position [50,50,50] everything is ok, but when I insert in positions [100,50,50] which is outside the main DC, sub DC is not inserted correctly. Sketchup puts him in position [110,50,50].
I suppose that there is a problem with BoundingBox of main DC, but I don’t have idea where should I look for solution.

The position (transformation) is not global, ie “not in model coordinates.”

It is relative to main component’s origin.

There is no such concept. A component’s bounding box will just expanded to encompass all it’s entities.

It is more likely the origin of the sub component is off by 10 in the x axis.

Dan,
I checked all of your suggestions.
Origin of sub DC is correct. But my script uses your method recalc_dc (inst.)

def recalc_dc(inst)
return nil unless defined?(DCObservers)
if inst.is_a?(Sketchup::ComponentInstance) &&
inst.attribute_dictionary(‘dynamic_attributes’)
if @dc_observers.nil?
ObjectSpace.each_object(DCObservers) {|o| break @dc_observers = o }
end
return nil unless @dc_observers.respond_to?(:get_latest_class)
latest_dc_class = @dc_observers.get_latest_class
return nil unless latest_dc_class.respond_to?(:redraw_with_undo)
latest_dc_class.redraw_with_undo(inst)
end
nil # (there is no particular return value)
end

And I noticed, it MOVES the inserted sub DC. When I turn off recalc_dc (inst) insert sub DC working properly. Dimensions and position are fine, but there are other features of my script which was based on your recalc_dc (inst.). And I can’t completly turn it off. Do you have any idea what needs to be changed?

NO, that method does not move anything. It is the DC code that may move your component based upon the values and/or formulas in the component’s “dynamic_attributes” dictionary.