Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > PYTHON Development
  New Posts New Posts
  FAQ FAQ  Forum Search

transfering py-Script to Plugin

Author
Message
  Topic Search Topic Search
Ronald Kissling View Drop Down
Member
Member


Joined: 2005 Dec 06
Location: Germany
Online Status: Offline
Posts: 27
Direct Link To This Post Topic: transfering py-Script to Plugin
    Posted: 2012 Oct 18 at 1:36pm
Hi all,

can anybody tell me how to transfer a script to a plugin?
The script works fine.
I have coppyed all the examples form the SDK to the pluginfolder

I've red in the sdk...
I've red in the forum...
It could not be so difficult...

I only need the first step till I can use callcommand

Thanks a lot
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1143
Direct Link To This Post Posted: 2012 Oct 19 at 2:34am
Hi,

What you need is to develop a CommandData plugin, the easiest plugin type.
Get a unique plugin ID (value for PLUGIN_ID) at this page: http://www.plugincafe.com/forum/developer.asp
Then in the Execute() function put your script's code.

MAXON
Developer Support
Back to Top
Ronald Kissling View Drop Down
Member
Member


Joined: 2005 Dec 06
Location: Germany
Online Status: Offline
Posts: 27
Direct Link To This Post Posted: 2012 Oct 19 at 1:22pm
You are my hero!!!
Realy.

Thanks a lot.

But one question:
Wy can't Maxon post such a little, easy thing in there SDK??
There is so much, but for a beginner nothing.

Thanks a lot again

Back to Top
Ronald Kissling View Drop Down
Member
Member


Joined: 2005 Dec 06
Location: Germany
Online Status: Offline
Posts: 27
Direct Link To This Post Posted: 2012 Oct 19 at 2:47pm
I'm struggeling again!

Why does this not work???
I only try to proceed several commands afer another?

Here is the code:
---------------------------
"""
Modified Date: 18/10/2012
"""

import c4d
import math
import os

from c4d import documents, plugins, bitmaps
#Welcome to the world of Python




PLUGIN_ID = 1234588880



class MYPLUGIN(plugins.CommandData):

     pass

      def Execute(self, doc):
           c4d.CallCommand(5159)                                # Würfel
        c4d.CallCommand(12305)                      # Konsole...    
           c4d.CallCommand(13957)                      # Konsole löschen

      
    
     

if __name__ == "__main__":
     # load icon.tif from res into bmp
     bmp = bitmaps.BaseBitmap()
     dir, file = os.path.split(__file__)
     fn = os.path.join(dir, "res", "icon.tif")
     bmp.InitWith(fn)
     # register the plugin
     okyn = plugins.RegisterCommandPlugin(id=PLUGIN_ID, str="V4D-Power-Reducer", info=c4d.PLUGINFLAG_COMMAND_HOTKEY, icon=bmp, help="", dat=MYPLUGIN())

     print "V4D-Power-Reducer ", okyn

--------------------

Is there any documentation "step by step" to learn how programming with phyton works??
Thanks a lot for every hint
Back to Top
tcastudios View Drop Down
Member
Member


Joined: 2005 Jan 21
Location: Sweden
Online Status: Offline
Posts: 559
Direct Link To This Post Posted: 2012 Oct 19 at 3:20pm
Step one, -always- use a unique plugin ID that you get from Plugin cafe (link in Yannicks' post)
Never, ever use a random or someone elses' ID or you are likely to cause corruption.
You need a separate Plugin ID for every and each plugin you make.

Python programming per se, is not Cinema specific and there are litterer tons of info
how to on the web.

Then I must agree, the first basic hurdles how to set up basic "default" plugin types
is sorely missing in the SDK. It -is- the biggest problem to get started not having any of that.
Sebastian, remember a couple of years ago the suggestion to set up this with the different
types of Faders, buttons, link fields in a default fashion? What happened ? :)


Cheers
Lennart
Back to Top
Ronald Kissling View Drop Down
Member
Member


Joined: 2005 Dec 06
Location: Germany
Online Status: Offline
Posts: 27
Direct Link To This Post Posted: 2012 Oct 20 at 4:46am
Hi Lenard,

my problem is not the solution of my problem in CINEMA.
The script recorder is a very easy tool tho find the commands.

My problems are like this:
Must commands stand every row exactly under the last row
Do i have to use 4 or 5 blanks in the struckture
Why do i always get

"    def Execute(self, doc):"
"IndentationError: unexpected indent"

My scritp works very well in Cimena als a py-Script.
What is to be done to change it to an Plugin?
I found a nice Video in Vimao about the struckture of a plugin.
But ther is nothing said about:
Where do i have place my def Funktion()...

Is there anybody out there who kmows a Book or totorial?
Is there anybody out there who could help me (I pay the translation)

Thanks to all

And: Sory for my horrible englisch
Back to Top
tcastudios View Drop Down
Member
Member


Joined: 2005 Jan 21
Location: Sweden
Online Status: Offline
Posts: 559
Direct Link To This Post Posted: 2012 Oct 20 at 10:08am
Yes, indents are paramount in py as they are used insted of brackets found in other coding types.
One usually use either a Tab step or four spaces. It is not recommended to mix what to use.
Either Tab or 4 spaces.
Check in your text application.

Any function of yours are normally placed before the Execute()

Cheers
Lennart

Edited by tcastudios - 2012 Oct 20 at 10:08am
Back to Top
Kissling1 View Drop Down
Member
Member


Joined: 2009 Apr 08
Location: Germany
Online Status: Offline
Posts: 28
Direct Link To This Post Posted: 2012 Oct 22 at 12:02am
Thanks to Lennard

I learn so much this weekend.
M fault was that I used spaces and tabs mixed

But now there is a new problem:
I tryed to define a funktion.
(Funtions have to be placed before the execute. wright?)

But nothing happens when the plugin is executet.
Can somebody give me a smal advice! Please
Here is my code
Thanks to all

"""
V4D-Power-Reducer
Copyright: VISION 4D
Written for CINEMA 4D R14

Modified Date: 18/10/2012
"""

import c4d
import math
import os

from c4d import documents, plugins, bitmaps
#Welcome to the world of Python


PLUGIN_ID = 1029229


class MYPLUGIN(plugins.CommandData):
    #pass

    def Execute(self, doc):
    
        def Test(self):
            print 'test'
            return True
    
    
        print 'Hello'
        print 'Hello again'
        Test
        #Check_serialinfo
        c4d.CallCommand(5159) # Würfel
        return True



if __name__ == "__main__":
    # load icon.tif from res into bmp
    bmp = bitmaps.BaseBitmap()
    dir, file = os.path.split(__file__)
    fn = os.path.join(dir, "res", "icon.tif")
    bmp.InitWith(fn)
    # register the plugin
    okyn = plugins.RegisterCommandPlugin(id=PLUGIN_ID, str="V4D-Power-Reducer", info=c4d.PLUGINFLAG_COMMAND_HOTKEY, icon=bmp, help="", dat=MYPLUGIN())
    c4d.CallCommand(13957)                                    # Konsole löschen
    print " "
    print "----------------------------------"
    print "V4D-Power-Reducer ", okyn
    print "----------------------------------"
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1143
Direct Link To This Post Posted: 2012 Oct 22 at 1:10am
Hi,

It's not good practice to declare a method inside another; you should declare Test() outside of Execute(). If you only write 'Test' it will not be called, Test is just the method variable. So to call it don't forget '()'. And as it's a class method (Test(self)) self has to be added before:
self.Test()

I think you should read one of the Python tutorials or books linked in the CINEMA Python SDK documentation (see Meta information: Internet Resources at the bottom of the Index page).



Edited by Yannick Puech - 2012 Oct 22 at 1:12am
MAXON
Developer Support
Back to Top

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.