Solved Clear LinkBox field

Hi everyone,

Very basic question here, but I'm trying to clear the a LinkBox field.
Would you use GeDialog.Command()? If so what BaseContainer to use?

def Command(self, id, bc):
   if id == TAKES_LINKBOX:
       if type(self.linkBox.GetLink(activeDocument)) != c4d.modules.takesystem.BaseTake:
           test = c4d.BaseContainer()
           self.Command(TAKES_LINKBOX, **???**)

Thank you all in advance! :grinning:


Hi Andre,

you can simply use SetLink(), the opposite of GetLink().

In order to clear a link box, you'd call: self.linkBox.SetLink(None)

The type you do in your code snippet is a bit unconventional in terms of Cinema 4D's API (not wrong though), but usually we recommend to stay in our API for example with CheckType() or IsInstanceOf(). But in the end, I think, you don't even need the type check, if you simply restrict the types accepted by the link box.
For example like so:

bcAcceptedObjects = c4d.BaseContainer()
bcAcceptedObjects.InsData(c4d.TakeBase, "") # only allow BaseTakes to be accepted
bcLinkBox = c4d.BaseContainer()
bcLinkBox.SetData(c4d.DESC_ACCEPT, bcAcceptedObjects)
self.linkBox = self.AddCustomGui(2001, c4d.CUSTOMGUI_LINKBOX, "My Link", c4d.BFH_SCALEFIT | c4d.BFV_CENTER, 0, 0, bcLinkBox)

I turned this thread into a question.


Hi Andreas,

Thank you very much! :relaxed:
It works like a treat and I appreciate your thorough explanation!

Happy Friday!