Thank you for sharing the error message, and I appreciate your patience! It appears there’s still a misunderstanding about how to fetch input and output data from Xpresso Python Nodes in Cinema 4D.
In Xpresso's Python Node API, you don’t need to call GetValue() explicitly on a port to read its value—ports are automatically translated into variables and made accessible to Python as part of your node's global namespace. Let's rewrite and simplify it using the correct workflow for Xpresso Python Nodes.
Correct Python Code for Xpresso Node
import c4d
def main():
# Get the global positions from the Xpresso inputs (these are automatic variables created by Xpresso)
global_position_a = Input1 # First object's global position (Vector)
global_position_b = Input2 # Second object's global position (Vector)
# Compute the distance between the two global positions
distance = (global_position_a - global_position_b).GetLength()
# Output the calculated distance
Output1 = distance # First output port
Explanation of Changes
-
Using Auto-Generated Variable Names in Xpresso:
- When you add input and output ports in the Xpresso Python Node, Cinema 4D automatically creates Python-side variables for those ports.
- These variables are named based on their user-defined names in Xpresso, such as
"Input1", "Input2", "Output1", etc.
- You don’t need to call
GetInPort, GetValue, or any similar function on the ports directly—just use the variable names.
In this case:
Input1: Automatically created for the first input port.
Input2: Automatically created for the second input port.
Output1: Automatically created for the first output port.
-
Removing Explicit API Calls like GetValue():
- Ports are already linked as variables in global scope. Trying to call
GetValue() is unnecessary (and incompatible) for Xpresso-specific data flows.
-
Output Variable Assignment:
- To output a value, such as the calculated distance, you simply assign it to the output port's variable name, e.g.,
Output1.
Connecting Xpresso Nodes
Now that the Python node script is correct, ensure that your setup in the Xpresso Editor is configured as follows:
-
Input Ports:
- Open the Python Node’s Attribute Manager and add two input ports.
- Rename the ports to something intuitive like
Input1 and Input2.
-
Connect the Objects:
- Drag your two objects (
Object A and Object B) into the Xpresso editor from the Object Manager.
- Use their Global Position outputs and connect them to
Input1 and Input2 on the Python Node.
-
Output Port:
- Add an output port to the Python Node (named
Output1).
- Connect this output to a Result Node to visualize the distance value in the viewport, or use a HUD display for testing.
Debugging
If you're still running into issues, you can debug the script in the Python Console (Shift+F10) by adding print statements like this:
print("Global Position A:", Input1)
print("Global Position B:", Input2)
print("Distance:", Output1)
Example Use Case
If both objects are at the following global coordinates:
- Object A:
(100, 0, 0)
- Object B:
(200, 0, 0)
The Python Node will calculate the result as:
distance = (Input1 - Input2).GetLength()
# (100, 0, 0) - (200, 0, 0) => (-100, 0, 0)
# Magnitude of (-100, 0, 0) = 100
The result 100 will be displayed in the output.
This should resolve the issue. Let me know if you need further assistance!