Call Command

On 10/10/2016 at 11:15, xxxxxxxx wrote:

Hello there,

The "CallCommand" work correctly in code 01 but in the code 02 doesn't work.
is it posssible to Call Command by clicking on the button Add Hair? (see screenshot below)

Code 01 :

  
import c4d  
  
def main() :      
  c4d.CallCommand(1018401)  
  

Code 02 :

  
import c4d  
  
def main() :  
    
  obj = op.GetObject()  
  AddHair = obj[c4d.ID_USERDATA,120]  
  
  if AddHair == 1 :  
      c4d.CallCommand(1018401)  
      c4d.EventAdd()      
      obj[c4d.ID_USERDATA,120] = 0 # AddHair = 0  
  

Download the .c4d file

Thanks

On 11/10/2016 at 00:06, xxxxxxxx wrote:

maybe

import c4d
  
def main() :
    
    obj = op.GetObject()
    AddHair = obj[c4d.ID_USERDATA,120]
  
    if AddHair == 1 :
        #c4d.CallCommand(1018401)
        Hair = c4d.BaseObject(c4d.Ohair)
        doc.InsertObject(Hair)
        c4d.EventAdd()
        obj[c4d.ID_USERDATA,120] = 0 # AddHair = 0

On 11/10/2016 at 01:48, xxxxxxxx wrote:

Hello,

could you explain what exactly you are trying to do? It seems that you want to press the user data button on the host object and catch that event in the Python tag. Is that correct?

The main() function in the Python tag corresponds to the Execute() function of a proper Tag plugin. This means that the code of the main() function is called within the execution of the scene. While the scene is executed you cannot edit   the scene or trigger events with EventAdd(). So main() is the wrong place to react to events or to edit the scene. Additionally, CallCommand() can only be called from the main thread (Threading Information).

When a button is pressed a message is sent. You can catch this message in a message() function in your Python tag. You have two options:

best wishes,
Sebastian

On 11/10/2016 at 07:53, xxxxxxxx wrote:

Hello,

Thank you for your detailed reply,

To be clear, the reason for my question is:
I have created a computer authorization system to protect my products.

actually with this system when a computer is not authorised to use my product, a message is
shown "Computer Not Authorized!" with "?" button at the right, when the button is pressed
popup windows opens with the instructions "How to authorize computer".
as the screenshot below:

Now i want to replace the button "?" by "Authorize" and open directly the Authorization Dialog.
as the screenshot below:

it is not important for me to add this option but I just want to know if is it possible or not?

I hope that my explanation is clear and sorry for my bad english :)

On 11/10/2016 at 09:14, xxxxxxxx wrote:

Originally posted by xxxxxxxx

maybe

import c4d
 
def main() :
    
    obj = op.GetObject()
    AddHair = obj[c4d.ID_USERDATA,120]
 
    if AddHair == 1 :
        #c4d.CallCommand(1018401)
        Hair = c4d.BaseObject(c4d.Ohair)
        doc.InsertObject(Hair)
        c4d.EventAdd()
        obj[c4d.ID_USERDATA,120] = 0 # AddHair = 0

Thank you, yes this work to add a hair object, in my case i would like call a command to execute my plugin from the User Data using this command:

c4d.CallCommand(myPluginID)

I am sorry if I was not clear enough. Check my previous replay ****for more details

On 12/10/2016 at 01:05, xxxxxxxx wrote:

Hello,

so you want to open a dialog window that is hosted by a CommandData plugin by calling CallCommand()? This is definitely possible but depending on how you want to implement this, this will be more or less complex.

As said before, when a button is pressed this triggers a message and you have to catch this message. You have to decide what button you want to trigger and where you want to catch this message. For example you could create your own TagData plugin that hosts a button. In that TagData plugin you could catch the message when this button is pressed to open your dialog. If you want to use a Python tag to catch the event when some user data button was pressed you can use the solutions I described above.

Best wishes,
Sebastian

On 12/10/2016 at 12:44, xxxxxxxx wrote:

Hello,

import c4d  
  
def message(id, data) :  
  if id == c4d.MSG_DESCRIPTION_COMMAND:  
      id2 = data['id'][0].id  
      if id2 == c4d.ID_USERDATA:  
          userDataId = data['id'][1].id  
          if userDataId == 120:  
              c4d.CallCommand(MyPluginID)  
def main() :  
  pass

I tried this code but it's working only in R17 et probably in R18. Can I do this in the older versions of Cinema 4D, in R14 for example? and is it possible to add the user data button out of the Python Tag, on a Null object for example?

Thanks.

On 13/10/2016 at 02:20, xxxxxxxx wrote:

Hello,

as described above the message() function was added to the Python tag in 17.053. AddEventNotification() was added in R16.021, so I'm afraid there is no solution for earlier versions.

best wishes,
Sebastian

On 13/10/2016 at 07:07, xxxxxxxx wrote:

Thank you very much for your reply.

So, I will probably use the following Condition to do that only in the versions that support the AddEventNotification().

  
  if c4d.GetC4DVersion() >= 16021 :  
      # _use_ _AddEventNotification()_   
  else :  
      # _do other things_  

Cordially,
Mustapha