Jump to content

I can not execute my code on xpresso script tag


Yerri

Recommended Posts

Hello to everyone, I have a little trouble with a code on xpresso, im newbie on this, but I made a funtional code and want to execute it but when I load it to the xpresso with script tag It just do nothing , I tried in the script tag and when I press play button, it just start to spam the message so If anyone can help me , I would be gratefull
Also I tried to get the "reset object selection" tag user data but I can´t too , I guess it is ID 33 and I only got it becuause I switched version And finally decide to use a boolean interface

Here is the code thanks!
def main(): gui.MessageDialog('Rig web') if __name__=='__main__': main() import webbrowser new=2; url="rigwebURL"; webbrowser.open(url,new=new);

Link to comment

Please format your code properly with the forum functionality.
(This may help me to understand why you choose such an unusual sequence of statements for your code.)

Anyway: Why do you want to open a website from an XPresso tag? XPresso is executed every time when the scene is evaluated. You'd get as many open websites as you get dialogs at the moment. This will kill your browser.

I do not understand the rest of your questions. User data should appear in the respective object's ports. The ID of user data depends on the object and is automatically assigned by C4D. What do you mean by boolean interface? For what? Where? In which context? Switched version what? Are you still talking about XPresso at all?

Link to comment
  • 2 months later...

Hi, Thanks for answering, I do not know how to do that, 

It is no properly an xpresso, is the pyhton tag, I just want to write a code that open a custom url web browser, with a normal user data button, when I talk about a boolen interface it is just the eye button, for example to execute my code

Link to comment
46 minutes ago, Yerri said:

Hi, Thanks for answering, I do not know how to do that, 

It is no properly an xpresso, is the pyhton tag, I just want to write a code that open a custom url web browser, with a normal user data button, when I talk about a boolen interface it is just the eye button, for example to execute my code

 

Okay, if what you have is actually a Python tag, then you need to evaluate the message from the button. That does not work in main() (which is the function that is executed when the object tree is evaluated). This would be a simple example for the tag content:

 

import c4d

def message(id, data) :
    if (id == c4d.MSG_DESCRIPTION_COMMAND) : 
        print (id, data)  
        ud = data['id'][0].id  
        if (ud == c4d.ID_USERDATA) :  
            bt = data['id'][1].id
            print (bt)  
            if (bt == 1):
                print ("some button pressed")
            elif (bt == 2):
                print ("other button pressed")

def main():
    pass

 

To make this work, your tag needs to have 2 buttons in the user data area, with the IDs 1 and 2. I called the 1 "Some Button" and the 2 "Other Button" so the console output makes sense 🦊

 

The function message receives an id parameter to tell you the type of message; you are interested only in COMMAND messages because that's what a button press gives you.

Also you get the data parameter, which is a Python dictionary. Only the entry "id" interests us, which is a DescID. To be exact, it is the DescID of your button. If you know DescIDs, this contains two hierarchic components which are DescLevels; the first describes the UserData area itself (ID_USERDATA), the second describes the button's ID that you find under "Manage User Data".

If you don't understand DescIDs and DescLevels, this is a bit difficult, but you can go with just the code I'm giving you: bt is the button's ID in the end, so the final conditional prints the proper text for your buttons.

 

(I still don't know why you write XPresso, and put it in the XPresso forum, when you actually mean Python and don't want any XPresso at all...)

Link to comment
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • LATEST ACTIVITIES

    1. 16

      3D world #310

    2. 53

      Looking forward to the next C4D release

    3. 8

      CORE 4D Youtube channel

    4. 1

      Nodes Modifier result isn't updated anymore

    5. 8

      CORE 4D Youtube channel

×
×
  • Create New...

Copyright Core 4D © 2023 Powered by Invision Community