Browsing Plugin Paths



  • Hello, I'm looking for a way to get the filepaths from the Preferences -> Plugins -> Search Paths menu. I have a circumstance where one plugin needs to know where another plugin is installed so I want to be able to check those remote paths, but I can't figure out how to access the parameter.
    alt text

    GetWorldContainer() doesn't seem to contain this parameter but it does others, so I'm not sure where to go from here.

    Dan



  • hello,

    thanks @zipit for the answer.

    @d_schmidt, please, don't forget to mark your thread as a question and mark it as solved once it is. That help us :)

    Instead of getting the preferences, you can use GetModulePaths. It returns all module paths configured through g_modulePath, g_additionalModulePath and user preferences. Including Corelibs and Plugins default directories.

    You can have information on Application manual

            // Returns all module paths configured through g_modulePath, g_additionalModulePath and user preferences.
    	// include corelibs and plugins default directory.
    
    	const maxon::BaseArray<maxon::Url> myPluginPaths = maxon::Application::GetModulePaths() iferr_return;
    	
    	for (auto plugPath : myPluginPaths)
    		DiagnosticOutput("plugins path @", plugPath);
    
    

    If you do know the plugin ID, you can also use this kind of code.

            const maxon::Int32 plugin_ID = 1038235;
    
    	BasePlugin* myPlugin = FindPlugin(plugin_ID, PLUGINTYPE::ANY);
    
    	if (myPlugin == nullptr)
    		return maxon::NullptrError(MAXON_SOURCE_LOCATION);
    
    	const Filename myPluginPath = myPlugin->GetFilename();
    	const maxon::String directory = myPluginPath.GetDirectory().GetString();
    
    	DiagnosticOutput("directory of plugin @ is @", plugin_ID, directory);
    

    Cheers
    Manuel



  • Hi,

    preference data is often even for native c4d features implemented as a PreferenceData plugin. You have to access that plugin then. To get there you can drag and drop description elements into the python command line, delete the __getitem__() part (the stuff in brackets), and get the __repr__ of the object. With that you can figure out the plugin ID of the corresponding BasePlugin and then access your values.

    For your case as a script example:

    import c4d
    from c4d import plugins
    # Welcome to the world of Python
    
    def main():
        # Search for a plugin ID with a known str __repr__ of a BasePlugin. We got from the console:
        # Drag and drop: Plugins[c4d.PREF_PLUGINS_PATHS]
        # >>> Plugins
        #     <c4d.BaseList2D object called 'Plugins/Plugins' with ID 35 at 0x0000028FE8157A50>
        pid, op = None, plugins.GetFirstPlugin()
        while op:
            if 'Plugins/Plugins' in str(op):
                pid = op.GetID()
                break
            op = op.GetNext()
        print "pid:", pid
        
        # Use that ID
        op = plugins.FindPlugin(pid)
        if op:
            print op[c4d.PREF_PLUGINS_PATHS] # we know the enum from the console
    
    # Execute main()
    if __name__=='__main__':
        main()
    

    You can use then that Plugin ID in cpp to do the last part (Use that ID) there.

    Cheers,
    zipit



  • hello,

    thanks @zipit for the answer.

    @d_schmidt, please, don't forget to mark your thread as a question and mark it as solved once it is. That help us :)

    Instead of getting the preferences, you can use GetModulePaths. It returns all module paths configured through g_modulePath, g_additionalModulePath and user preferences. Including Corelibs and Plugins default directories.

    You can have information on Application manual

            // Returns all module paths configured through g_modulePath, g_additionalModulePath and user preferences.
    	// include corelibs and plugins default directory.
    
    	const maxon::BaseArray<maxon::Url> myPluginPaths = maxon::Application::GetModulePaths() iferr_return;
    	
    	for (auto plugPath : myPluginPaths)
    		DiagnosticOutput("plugins path @", plugPath);
    
    

    If you do know the plugin ID, you can also use this kind of code.

            const maxon::Int32 plugin_ID = 1038235;
    
    	BasePlugin* myPlugin = FindPlugin(plugin_ID, PLUGINTYPE::ANY);
    
    	if (myPlugin == nullptr)
    		return maxon::NullptrError(MAXON_SOURCE_LOCATION);
    
    	const Filename myPluginPath = myPlugin->GetFilename();
    	const maxon::String directory = myPluginPath.GetDirectory().GetString();
    
    	DiagnosticOutput("directory of plugin @ is @", plugin_ID, directory);
    

    Cheers
    Manuel



  • Thank you both for the replies! Between both of them I have exactly what I need, thanks.


Log in to reply