Navigation

    • Register
    • Login
    • Search
    1. Home
    2. beesperester
    3. Posts
    • Profile
    • More
      • Following
      • Followers
      • Topics
      • Posts
      • Best
      • Groups

    Posts made by beesperester

    RE: Python typing features

    @m_adam said in Python typing features:

    [...]
    @beesperester said in Python typing features:

    Would I be allowed to share my customized version of the dummy package?

    While we do not encourage this, the fact that we do not support typehint is limiting its usage, so you can release it but it will be on you to maintain it.

    Cheers,
    Maxime.

    Thanks. For everyone interested in the extended definitions you can find them in my github repository here: https://github.com/cgbits/c4dstubs

    Some of the definitions may not be 100% accurate because the docstrings have varying ways of defining the types / rtypes (list of float, tuple(int, float) etc.) and sometimes they omit the information if a parameter is optional. Over time I will improve the definitions while using them for my own plugin development purposes.

    Cheers

    posted in Cinema 4D SDK •
    RE: Python typing features

    Hi @m_adam, thanks for taking time to answer my question. I have been using the dummy package before, but there are some limitations / shortcomings compared to the type checking functionality of mypy or pylance.

    With the dummy package for example I am not getting the proper return type from BaseObject.GetName() which should be str but is None. Of course I can see that the return type is described as str in the docstring, but for the IDE it is still None and since it is a dummy package, the IDE can not infer the actual return type in python types or objects
    Screenshot 2021-05-13 at 15.35.03.png

    When using my customized version of the dummy package I can get the correct return type
    Screenshot 2021-05-16 at 18.43.37.png

    This is especially useful if I use something like GetChildren, because now pylance already knows about the type of objects in the returned list and I can easily browse the objects functions and can check in the IDE if my variables have the correct type
    Screenshot 2021-05-16 at 18.52.57.png

    Would I be allowed to share my customized version of the dummy package? It is based on the provided package but with added type hints and modified imports where possible and covers ca. 90% of the definitions.

    For example the definition for c4d.Vector would look like this:

    class Vector(object):
        x: float
        y: float
        z: float
    
        def __init__(self, x: Optional[Union[int, Vector, float]] = ..., y: Optional[Union[int, float]] = ..., z: Optional[Union[int, float]] = ...) -> None:
            """
            | Initializes a new :class:`Vector <c4d.Vector>`.
            | All arguments are optional so it is possible to create a new vector without any arguments. All components are simply `0`.
            | Otherwise *x* can be a :class:`Vector <c4d.Vector>` so all components of the passed vector will be copied to the new vector.
            | If only a number is passed, all components will be set to this.
            .. code-block:: python
            c4d.Vector()
            # => Vector(0,0,0)
            c4d.Vector(100)
            # => Vector(100,100,100)
            v = c4d.Vector(100,100,100)
            c4d.Vector(v)
            # => Vector(100,100,100)
            c4d.Vector(1,2,3)
            # => Vector(1,2,3)
            :type x: Union[int, float, c4d.Vector]
            :param x: If *x* is a number and is the only passed argument, set this to all components. If *x* is a vector, clone it. Otherwise set the X component.
            :type y: number
            :param y: Set the Y component.
            :type z: number
            :param z: Set the Z component.
            :rtype: c4d.Vector
            :return: A new vector.
            """
            ...
    

    Cheers

    posted in Cinema 4D SDK •
    RE: BaseContainer missing for GvNode created with c4dpy

    Hi, thanks for the information. I will try and utilise the x and y coordinates in GvNodeMaster.CreateNode() instead.

    Cheers

    posted in Cinema 4D SDK •
    BaseContainer missing for GvNode created with c4dpy

    I am creating a GvNode via GvNodeMaster.CreateNode() in a python script that opens an existing cinema 4d file and stores it after the modifications to a different cinema 4d file. When I open the newly created file in cinema 4d I can access and write to the the GvNode's x and y position perfectly fine like this in the python console:

    # x coordinate
    my_node.GetDataInstance().GetContainerInstance(1001).GetContainerInstance(1000)[100]  = x
    # y coordinate
    my_node.GetDataInstance().GetContainerInstance(1001).GetContainerInstance(1000)[101]  = y
    

    But when I try to access those coordinates from inside the python script via c4dpy I get an NoneType error because the last base container (1000) is missing in base container with id 1001. I tried manually creating a new BaseContainer instance and attaching it like this:

    my_node.GetDataInstance().GetContainerInstance(1001)[1000] = c4d.BaseContainer()
    

    But this totally messes up the graphview when I open it in cinema 4d. I guess because all the other attributes like width and hight are missing.

    Is this base container somehow created at a later stage where I don't have access yet? Is this intentional?

    posted in Cinema 4D SDK •
    Python typing features

    Are you planning to implement the new static typing features introduced in python 3.5 in future releases?
    In some parts of the python documentation I can already see type information for input arguments written like Union[int, float, c4d.Vector] etc...

    Right now I am creating my own stubs for pylance but it would be awesome, if you could add those 🙂

    posted in Cinema 4D SDK •