plugin with link fields

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/03/2011 at 09:04, xxxxxxxx wrote:

Hey there,

I'm learning Python and the way I do this is by creating my first super-simple plugin.

Among other controls, this plugin should have link fields, but I don't understand how to set them up.
To be more precise, I want to create something like this:
http://www.thirdpartyplugins.com/python/modules/c4d.gui/BaseCustomGui/LinkBoxGui/index.html

Do I create them at the Init-function, where I set up my other controls?

# initualizing the controls
def Init(self, op) :
    self.InitAttr(op, float, [c4d.PY_VECTOR_1])
    op[c4d.PY_VECTOR_1] = 200.0
    ...
    #HERE?????
    return True

And what would be the best way to use i.e. the position of the object that has been dragged into this very link field in python?

Thank you very much for your help!
Robibert

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 02/03/2011 at 10:08, xxxxxxxx wrote:

Hi Robibert,

this depends on which plugin type you create. From your posted source it seems that you create a tag/object, ..correct?

The link field must be created in the description(.res) file of your plugin like this:

		LINK GV_COLLISION_SELECTION2 { ACCEPT { Tpolygonselection; } }

The C++ documentation contains more information about Descriptions , so you might use them as an addition to the Python documentation. I hope that helped.

Cheers, Sebastian

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 04/03/2011 at 01:38, xxxxxxxx wrote:

Hello Sebastian!

Yes, I'm trying to create an object plugin.

With your help I managed to set up the link-fields. Thanks!
Now I have another strange problem :/

I've got two of these link-fields, but somehow only the first one is being recognized in C4D, even though both are set up exactly the same way.

/res/description/*.res

LINK PY_LINK_1 { ACCEPT{ }; }
LINK PY_LINK_2 { ACCEPT{ }; }

Btw: Could you please provide a link to the C++ documentation where I can see how to set up these descriptions and their attibutes. I don't want to do a forum-post for every new data type (link, vector,...) I want to set up ;) Can't find it through Google. Maybe I use the wrong terms.

/res/description/*.h

PY_LINK_1 = 10001,
PY_LINK_2 = 10002

What are these numbers for, anyway? Kind of IDs?

/res/strings_us/description/*.str

PY_LINK_1 "Start";
PY_LINK_2 "End";

But when I try to read the main *.pyp file...

...
if not op[c4d.PY_LINK_1] and not op[c4d.PY_LINK_2]:
    print "Both empty"
...

...I get this error message:

AttibuteError: 'module' object has no attribute 'PY_LINK_2'

Strangly, when I do the if-condition only with 'PY_LINK_1' everything is fine.

Anyone got an idea?

Thanks again, Robibert

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 04/03/2011 at 05:21, xxxxxxxx wrote:

Hi Robibert,

you can download the C++ documentation from here:
http://www.maxon.net/index.php?id=157&L=0

C4D caches all symbols in header files for Python and Coffee. This cache is only updated if
a new description resource is added (for instance a new plugin is added).
You didn't add a new description resource, you updated it, so you need to clear the cache manually.

Go to the ($UserFolder)/prefs/ and delete the file coffeesymbolcache. On a next restart, C4D rebuilds the cache and PY_LINK_2 is added.

Cheers, Sebastian

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 04/03/2011 at 14:19, xxxxxxxx wrote:

Great! It works like a charm now :)

While I have you around, could you please also take a look at this code-snippet and tell me, where the mistake is? It's probably a newbie-mistake, so I don't want to make a new topic for it.

What I'm trying to do is: when a button is clicked, a cube is added.

...
def TestCube(name, pos) :
    testcube = c4d.BaseObject(c4d.Ocube)
    testcube.SetPos(pos)
    testcube.SetName(name)
    doc.InsertObject(testcube)
    c4d.EventAdd()
        
def Message(self, op, type, data) :
    if type==c4d.MSG_DESCRIPTION_COMMAND:
        if data["id"][0].id==10003:
            print "Create Nulls" ###### this works ######
            TestCube("TestCube", c4d.Vector(-200,0,0)) ###### this doesn't ######
    return True
...

The error I get is  NameError: global name 'TestCube' is not defined.

Maybe I mix up op  and  doc  here? The button is a description/attribute of the plugin object, that I create. So I believe I have to use  op in the Message() function. On the other hand, the testcube should not be added to the plugin object but to the scene/document. So should I use   doc in the Message()  function, instead?

Bye,
Robibert

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 09/03/2011 at 01:21, xxxxxxxx wrote:

Sorry, I don't have an answer for your question.
I've got a question. How did you Init the Linkfield ? I just can't figure it out.

self.InitAttr(op,link,[c4d.MYLINK])

does not work, because "link" is not defined.

Thanks, nux

//edit: I see, there's no need to Init it with InitAttr(), it just needs to be set in the Init() of the Plugin.

  
def Init(self,op) :  
  op[c4d.MYLINK] = None

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 14/03/2011 at 08:26, xxxxxxxx wrote:

Hi,

if this post still up to date, maybe the following information can help you ;)

testcube.SetPos(pos)

SetPos() is a function from the old python API (Py4D for 11.5),
use SetAbsPos( v ) or SetRelPos( v ) for C4D 12.

This works, for example.

  
...  
  def TestCube(self, name, pos) :  
      doc = c4d.documents.GetActiveDocument()  
      testcube = c4d.BaseObject(c4d.Ocube)  
      testcube.SetRelPos(pos)  
      testcube.SetName(name)  
      doc.InsertObject(testcube)  
      c4d.EventAdd()          
        
  def Message(self, op, type, data) :  
      if type==c4d.MSG_DESCRIPTION_COMMAND:  
          if data["id"][0].id==10003:  
              print "Create Nulls" ###### this works ######  
              self.TestCube("TestCube", c4d.Vector(-200,0,0))   
...  
  

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 14/03/2011 at 13:43, xxxxxxxx wrote:

thanks shirayuki, haven't tested it yet, but will soon. i'll let you know if it solved the problem.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 20/03/2011 at 10:39, xxxxxxxx wrote:

it works! thanks again, shirayuki