Sign in to follow this  

Passing Lots of Data to a Python Script Using Python API

This topic is 2054 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, I'm basically writing a plugin system using Python and my Python is very rusty, I haven't used it for a very long time, but anyways I have Python API up and going and able to read python files and execute python functions. What I want to know today is how can I pass a "struct" or a class of variables from my C++ to say a function in Python? Here is kinda how I imagine it working:

bigClass.py

[background=rgb(245, 245, 255)][color=#000088]class[/color][color=#000000] [/color][color=#660066]BigClass[/color][color=#666600]([/color][color=#000088]object[/color][color=#666600]):[/color][/background]
[color=#434343][background=rgb(245, 245, 255)][color=#008800]"""__init__() functions as the class constructor"""[/color][/background][/color]
[color=#434343][background=rgb(245, 245, 255)][color=#000088]def[/color][color=#000000] __init__[/color][color=#666600]([/color][color=#000088]self[/color][color=#666600],[/color][color=#000000] name[/color][color=#666600]=[/color][color=#000088]None[/color][color=#666600],[/color][color=#000000] job[/color][color=#666600]=[/color][color=#000088]None[/color][color=#666600],[/color][color=#000000] quote[/color][color=#666600]=[/color][color=#000088]None, 25 variables more...[/color][color=#666600]):[/color][/background][/color]
[color=#434343][background=rgb(245, 245, 255)][color=#000088]self[/color][color=#666600].[/color][color=#000000]name [/color][color=#666600]=[/color][color=#000000] name[/color][/background][/color]
[color=#434343][background=rgb(245, 245, 255)][color=#000088]self[/color][color=#666600].[/color][color=#000000]job [/color][color=#666600]=[/color][color=#000000] job[/color][/background][/color]
[color=#434343][background=rgb(245, 245, 255)][color=#000088]self[/color][color=#666600].[/color][color=#000000]quote [/color][color=#666600]=[/color][color=#000000] quote[/color][/background][/color]
[background=rgb(245, 245, 255)][color=#000000]#25 variables more...[/color][/background]

UsersCode.py
[code]

PLUGIN_NAME = "Export Script"

def export(bigClass [], filePath):
for each bigClass
#write to file!
return true
[/code]

Then in my source code I could just do this:
[code]
Create class object using a lot of run simple command from Python API using the above.
Then create BigClass array and append all the data.
Then get the bigClass object we just made using C++ and pass it as a argument when we call the Python Function.
[/code]

As you can tell this is very tedious, a lot of code and a bit confusing. I was wondering how I could create a array object in Python's C++ API using my big class without making a page arguments in the initialization with Python just to be executed in a Python function someone made. Basicly I'm trying to accomplish what Blender 3D did when you write your export/import script.

Share this post


Link to post
Share on other sites
Never mind I found what I was looking for:

[code]


class BigClass:
def __init__(self, **kwds):
self.__init__(self, kwds)
self.__dict__.update(kwds)


#someScript.py

import BigClass
point = BigClass(Name='John', Age=101, size=200, etc...)
[/code]

This would work better since I don't have to recreate a giant class in Python and just use2-3 call simple commands in C++ to Python.

Share this post


Link to post
Share on other sites

This topic is 2054 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this