Loading other Plugin Files

I typically use this piece of code to load up other extension files:

    this_dir=File.dirname(__FILE__)
	# Fix for ruby 2.0
	if this_dir.respond_to?(:force_encoding)
		this_dir=this_dir.dup.force_encoding("UTF-8")
	end

	# Read Dictionary Attributes

	Sketchup.load(File.join(this_dir,"MEDEEK_RECT_WALL_DICTIONARY.rbs"))

I am wondering if I should be checking to see if the file is already loading prior to actually loading it?

If a file has been already loaded and you load it again what are the implications if any?

The global array $LOADED_FEATURES, aka $" (that’s dollar sign + double quote) references an array of the pathnames of files already loaded.

Sketchp.load mimics Kernel.require, not Kernel.load (which will reload the file and does not check the $LOADED_FEATURES array.)

If a file has already been loaded then the 2 former methods return false. If it’s the first request to load a file and the file loads successfully, then true is returned.

1 Like

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