Ruby array variable

MMmm I think I will try writing infos directly in the file. 1, 2, 3, Go!

Write infos directly to file, give again only 1 result. :confused:
So it’s not the array the problem.
Well I think I have to check entity.definition.entities from Aerilius.

def attrib_piece(defs, f)
    iPiece = "" #Infos piece
    dicts = defs.attribute_dictionaries
    if dicts != nil
        dicts.each{ |dict|
            if dict.name == 'dynamic_attributes'
                dict.each{ |key, value|
                    iPiece = iPiece + "," + key.to_s + '=' + value.to_s
                }
                iPiece[0] = '' #Supprimer premier caractère (,)
            end
        }
    end
    f.puts(iPiece)
end

def lister_pieces(ents, f)
    ents.each{ |ent|    
        attrib_piece(ent,f)
        if ent.respond_to?(:each)
            ent.each{ |en|
                lister_pieces(en, f)
            }
        end
    }
end

#-----START-----
mod = Sketchup.active_model
ents = mod.entities
#ents = mod.selection

#Write file
modelPath = Sketchup.active_model.path
filename = File.basename(modelPath, '.csv')
if filename == ""
    filename = "Sans titre"
end
save_path = UI.savepanel "Enregistrer rapport CSV", modelPath, filename.chomp(".skp")+".csv"
if save_path != nil
    File.open(save_path, "w+") do |f|
        lister_pieces(ents, f)
    end
end

WORKING!!! with the help of Aerilius, by the ents = mod.definitions

Here is my final code for people who need it!

#DEFINITIONS
def attrib_piece(defs, f)
iPiece = “” #Infos piece
dicts = defs.attribute_dictionaries
if dicts != nil
dicts.each{ |dict|
if dict.name == ‘dynamic_attributes’
dict.each{ |key, value|
iPiece = iPiece + “,” + key.to_s + ‘=’ + value.to_s
}
iPiece[0] = ‘’ #Supprimer premier caractère (,)
end
}
end
f.puts(iPiece)
end

def lister_pieces(ents, f)
    ents.each{ |ent|    
        attrib_piece(ent,f)
        if ent.respond_to?(:each)
            ent.each{ |en|
                lister_pieces(en, f)
            }
        end
    }
end

#START
mod = Sketchup.active_model
ents = mod.definitions
modelPath = Sketchup.active_model.path
filename = File.basename(modelPath, ‘.csv’)
if filename == “”
filename = “Sans titre”
end
save_path = UI.savepanel “Enregistrer rapport CSV”, modelPath, filename.chomp(“.skp”)+“.csv”
if save_path != nil
File.open(save_path, “w+”) do |f|
lister_pieces(ents, f)
end
end

Of course thanks a lot for all people who help me! TY TY

I’m wondering if I need to purge the components before I run the script?

Purging removes component definitions that have 0 instances. If you just want to ignore them, you can also do:

ents = mod.definitions.select{ |definition| definition.count_instances > 0 }
1 Like

Scramble is the only way the encrypt script?

Yes, in the end SketchUp (the ruby interpreter) must still be able to unscramble and interprete it.
The alternative is to develop the essential parts in C/C++ as Ruby extension and compile it to binary code (for all supported platforms), which is a lot harder to disassemble.

1 Like

Where i can get the Scramble software?

you need to register as a developer and submit your extension which is returned scrambled…

there was to much hacking when it was publicly available…

john

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.