Additional files for plug-in dev
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/12/2011 at 15:26, xxxxxxxx wrote:
The external libs I use (not written by me) I've placed in the Maxon/user area:
/user/library/python/packages/osx folder (or win I suppose for win system) -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/12/2011 at 15:38, xxxxxxxx wrote:
Thanks, Lennart. I suppose my question should be qualified by saying I want it to be portable with the plug folder to other systems. I was hoping to have everything contained.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/12/2011 at 15:52, xxxxxxxx wrote:
I see. Maybe it's worth trying have your file in your plugin folder and upon start
of Cinema have it check if that file is present in the lib folder and if not have it
copied. I'm not sure of the loading order and a worst case would need a restart
of Cinema (with a Info popup).
I use this way for browser lib files copied by some of my plugins and it works fine. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/12/2011 at 15:56, xxxxxxxx wrote:
Very interesting. It's worth a try for sure. Thanks, Lennart.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/12/2011 at 19:01, xxxxxxxx wrote:
Yes. It is possible to import multiple .py files (your classes) from within your plugins folder.
Here's the jist of it:
-Create a .py file with your class in it.
For this simple example. The external class will be called "MyClass"-Make your class code look like this:
class MyClass() : def __init__(self, name = 'Scott') : #The constructor with a required name parameter self.name = name #Sets up the name parameter to work
-Name the .py file "MyClass.py"
-Put the file in your plugins folder
-At the top of your plugin code. Add these three lines of code:
import.os sys.path.append("C:/Program Files/MAXON/your CINEMA 4D version/plugins/MyPlugin") from MyClass import MyClass
*Note: Make sure you edit that code to your specific path names!!!!
-Next. In your plugin code. You'll need to instantiate your external class like this:
class Sub(MyClass) : #The parent class this class is connected to is listed in the parentheses def __init__(self) : #The sub class's constructor MyClass.__init__(self) #Call to the super class called "MyClass" in the external file
-Now you can call to that external class from withing any of your plugin's methods.
Example:def Execute(self, tag, doc, op, bt, priority, flags) : s = Sub() #Create an instance of the sub class..Which is also inheriting things from the external MyClass.py file print s.name #Prints the default name parameter value that exists inside of the MyClass.py file return c4d.EXECUTIONRESULT_OK
FYI:
Be aware that you'll sometimes have to shut down C4D and restart it when adding your external stuff.
Using: print sys.path will let you know whether or not the folder you're targeting is actually set up as a valid path.I've only done this a couple of times. And I haven't really tested it that much yet. So no guarantees that it's bug free.
But so far it seems to work fine for me.-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/12/2011 at 19:08, xxxxxxxx wrote:
Wow! Thanks a ton for that , Scott. I will try it thusly!
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/12/2011 at 01:30, xxxxxxxx wrote:
Originally posted by xxxxxxxx
sys.path.append("C:/Program Files/MAXON/ your CINEMA 4D version /plugins/ MyPlugin")
Please use this instead, as it is more safe when the user moves you plugin to another folder or he is on another platform, etc.
import os import sys __currdir__ = os.path.dirname(__file__) if __currdir__ not in sys.path: sys.path.insert(0, __currdir__)
Cheers, Niklas
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/01/2012 at 14:21, xxxxxxxx wrote:
@ScottA:
Originally posted by xxxxxxxx
-Next. In your plugin code. You'll need to instantiate your external class like this:
class Sub(MyClass) : #The parent class this class is connected to is listed in the parentheses def __init__(self) : #The sub class's constructor MyClass.__init__(self) #Call to the super class called "MyClass" in the external file
-Now you can call to that external class from withing any of your plugin's methods.
Example:def Execute(self, tag, doc, op, bt, priority, flags) : s = Sub() #Create an instance of the sub class..Which is also inheriting things from the external MyClass.py file print s.name #Prints the default name parameter value that exists inside of the MyClass.py file return c4d.EXECUTIONRESULT_OK
Why are you creating a subclass for MyClass? This is neither called "creating an instance" nor it is necessary. Just instantiate MyClass like this:
def Execute(self, tag, doc, op, bt, priority, flags) : s = MyClass() print s.name
Note: Overriding __init__ for calling the super-classes constructor isn't necessary, too.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/01/2012 at 15:47, xxxxxxxx wrote:
When you see me do something strange. There is usually no good reason for it other than I don't know a better way to do it.
Do German's know what the term "sky hook" means?
I make lots of them.I'm self taught. And I tend to make up my own rules sometimes.
Like Charles Barkley says: "I am not a role model"-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/01/2012 at 21:39, xxxxxxxx wrote:
Hm, actually never heard of it..
So I am. I often learn something from your posts, but this time I taught you.
Cheers,