Component loading issue

I am trying to load two components and merge these two component but i am not able to load the components…my code not throwing any error

def my_comp_creation
    carcass_code = "/Users/iclusters/Downloads/Comp_issues/mvp_version1/cache/KITCHEN_TOP_DISHDRAIN_SINGLEDOOR.skp"
    shutter_code ="/Users/iclusters/Downloads/Comp_issues/mvp_version1/cache/SINGLE_SHUTTER_GPROFILE_BOTTOM.skp"
    puts "Dynamic Carcass : #{carcass_code}" 
    puts "Dynamic Carcass : #{shutter_code}" 
    definitions = Sketchup.active_model.definitions
    model=Sketchup.active_model
    carcass_def = model.definitions.load(carcass_code)
    carcass_inst=model.entities.add_instance carcass_def, ORIGIN
    puts "carcass_def #{carcass_def}"
    puts "carcass_inst #{carcass_inst}"
    carcass_ents=carcass_inst.explode
    puts "carcass_ents #{carcass_ents}"
    carcass_inst = carcass_ents.grep(Sketchup::ComponentInstance)[0]
    puts "carcass_inst #{carcass_inst}"
    dict_name = "my_comp"
    curr_x_value = carcass_inst.get_attribute dict_name, 'lenx'
	curr_y_value = carcass_inst.get_attribute dict_name, 'leny'
	curr_z_value = carcass_inst.get_attribute dict_name, 'lenz'
		
	carcass_width = (carcass_inst.bounds.width.to_f*2.54)
	model.entities.erase_entities(carcass_inst)
				

	carcass_def.entities[0].set_attribute dict_name, '_lenx_formula', ('%s')%[10000]
	carcass_def.entities[0].set_attribute dict_name, '_leny_formula', ('%s')%[150]
	carcass_def.entities[0].set_attribute dict_name, '_lenz_formula', ('%s')%[20000]
	begin 
		dcs = $dc_observers.get_latest_class
        dcs.redraw_with_undo(carcass_def.entities[0])
        dcs.redraw_with_undo(carcass_def.entities[1]) if carcass_def.entities[1]
	rescue NoMethodError => e
		puts "No Method Error by sketchup : #{e}"
		UI.messagebox("Sketchup Error.Please Click Place component again.")
		return nil
	ensure
    end
    shutter_def=model.definitions.load(shutter_code)
    shutter_x_offset=1.mm
    shutter_z_offset=1.mm
    comp_width = 10000.mm - shutter_x_offset*5.08
    comp_width = 10000.mm - shutter_x_offset
    shutter_depth = 20000.mm - 96.mm
    comp_depth = 20000.mm - shutter_z_offset*2.54 - 1.mm*2.54
    shutter_def.entities[0].set_attribute dict_name, '_lenx_formula', ('%s')%[comp_width]

    shutter_def.entities[0].set_attribute dict_name, '_lenz_formula', ('%s')%[shutter_depth]
    begin 
        dcs = $dc_observers.get_latest_class
        dcs.redraw_with_undo(shutter_def.entities[0])
        dcs.redraw_with_undo(shutter_def.entities[1]) if shutter_def.entities[1]
    rescue NoMethodError => e
        puts "No Method Error by sketchup : #{e}"
        UI.messagebox("Sketchup Error.Please Click Place component again.")
        return nil
    ensure
       
    end
    defn_name = ('%s-%s-%s')%["KITCHEN_TOP_DISHDRAIN_SINGLEDOOR", "SINGLE_SHUTTER_GPROFILE_BOTTOM", Time.now.strftime('%H-%M-%S')]
    puts "#{defn_name}"
    defn        = definitions.add defn_name
    defn.set_attribute('rio_atts', 'shutter-code', "SINGLE_SHUTTER_GPROFILE_BOTTOM")
    trans       = Geom::Transformation.new([0.mm + shutter_x_offset, 0, 0.mm+shutter_z_offset])
	shut_inst   = defn.entities.add_instance(shutter_def, trans)
	shut_inst.set_attribute('rio_atts', 'block_type', 'shutter')
    puts "Shutter Added : #{shutter_def}"
    y_offset = 16.mm
    trans       = Geom::Transformation.new([0,100,0])
    ccass_inst  = defn.entities.add_instance(carcass_def, trans)
    ccass_inst.set_attribute('rio_atts', 'block_type', 'carcass')
    ref_point   = ccass_inst.bounds.corner(6)
    defn
end

my_comp_creation

Does your component contains exactly 1 other component? Upon loading you place an instance, which you then explode, which gives you a collection of entities, of which you then grep an instance and delete it. If your component contains 1 subcomponent, you are grepping that and deleting it.

also… what I did when starting to develop extensions some time ago, I placed UI.messagebox here and there, to see my code execute. You know, see the component being loaded, seeing it explode, seeing the deletions,…

yeah, i have seen component being loading ,exploding, deleting.

yeah my component contains exactly 1 other component

Then you know what is going wrong? You load it and immediately delete it… sort of.

but at the end of code i’m again adding instance then it should come again…

Hmm… no.
You add an instance to the entities collection of defn. But there is no instance of defn added to the model. Thus: place an instance of defn in the model

Re: The DC dictionary name (click to expand ...)

You are using dynamic component attribute names and the DC redraw method.

This will not work on a dictionary named "my_comp".
Use a local constant near the top of your extension submodule …

DCDICT ||= "dynamic_attributes"

… and then reuse that constant …

# Then later in the code ...
obj.set_attribute(DCDICT, "lenx", "50.0")

it’s s still not working

I did not say that was the only issue.
The DC extension is closed source and very complex.
You are not likely creating the DC correctly via code.

I’m already busy helping in another topic thread on initializing a new DC via code.

I would suggest in your first post (above) to edit it and pare down the snippet to only the component merging code, so this topic can concentrate on that coding problem.