NinthDesertDude Posted February 10, 2016 Share Posted February 10, 2016 Is it possible to get a list of all effects, including effects which are user-installed, and access or execute them in some way? I know that Pyrochild has a random effect plugin that presumably works this way. I want to make a plugin that saves the current image, executes a desired effect of the user's choice, then overwrites the result for the red/green/blue/hue/sat/val/alpha channels, in order to simulate channel locks. I think there's an Effect Lab that also accesses effects, but I don't know if it can access user-installed effects or not. Also, the list of effects should be obtained in a fair way like Rick wants. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Cc4FuzzyHuggles Posted February 10, 2016 Share Posted February 10, 2016 (edited) Is the plugin browser kind of what you are talking about? You said list effects and execute, so I thought maybe it would be a plugin that could be worth looking at. Edited February 10, 2016 by Cc4FuzzyHuggles 1 Quote *~ Cc4FuzzyHuggles Gallery ~* Link to comment Share on other sites More sharing options...
Rick Brewster Posted February 10, 2016 Share Posted February 10, 2016 There isn't a supported way to do this. Internally there's an EffectsCollection class but this functionality was never intentionally provided for plugins to use. pyrochild's effect might still be using it since it was compiled a long time ago (or it might just be broken now), or he may have replicated that functionality himself. Composability has not been a strong point of the effect system. 2 Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
NinthDesertDude Posted February 10, 2016 Author Share Posted February 10, 2016 Thanks Rick and Cc4FuzzyHuggles. I'll look at the plugin browser and see if it works in a fair way. Quote Link to comment Share on other sites More sharing options...
pyrochild Posted February 11, 2016 Share Posted February 11, 2016 ScriptLab gathers effect types this way: public static IEnumerable<Type> GatherEffects() { List<Assembly> assemblies = new List<Assembly>(); List<Type> ec = new List<Type>(); // PaintDotNet.Effects.dll assemblies.Add(Assembly.GetAssembly(typeof(Effect))); // TARGETDIR\Effects\*.dll string homeDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); string effectsDir = Path.Combine(homeDir, "Effects"); bool dirExists; try { dirExists = Directory.Exists(effectsDir); } catch { dirExists = false; } if (dirExists) { string fileSpec = "*.dll"; string[] filePaths = Directory.GetFiles(effectsDir, fileSpec); foreach (string filePath in filePaths) { Assembly pluginAssembly = null; try { pluginAssembly = Assembly.LoadFrom(filePath); assemblies.Add(pluginAssembly); } catch { } } } foreach (Assembly a in assemblies) { try { foreach (Type t in a.GetTypes()) { if (t.IsSubclassOf(typeof(Effect)) && !t.IsAbstract && !t.IsObsolete(false)) { ec.Add(t); } } } catch { } } return ec; } I think this code was copied from Paint.NET's source code back when the source was available (and modified since), so it's not accessing PdN's internal EffectsCollection code.After instantiating an Effect from the Type collection, you need to check for effect.Category == EffectCategory.DoNotDisplay. There's an effect with that category that you can display - the RotateZoomEffect. It's marked as DoNotDisplay so it can be manually placed in the Layers menu instead of Effects. If you want to render an effect multithreaded like Paint.NET does you'll need to check for effect.CheckForEffectFlags(EffectFlags.SingleRenderCall) and effect.CheckForEffectFlags(EffectFlags.SingleThreaded). Or just always render on 1 thread but performance will suffer compared to running an effect natively. 4 Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.