Outputting blender to AI

This is a python script that I am using to get scene information from Blender in the Collada format and convert it to .csv so it can be used to train and interact with an AI client.

This Python script is NOT meant to run in Blenders local python environment.

It will check for dependencies, and Python version and convert the file of your choice to .csv .

Since I have to leave blender anyway unless I am working from an Anaconda generated enviornment I prefer to do these things in C#. I included a winForm version as well down below.

Summary

Collada Express

#C.Cowen Model Maker 67 , OpenCNC_AI

MIT licence,

import sys
import subprocess
import lxml.etree as ET
import pandas as pd

def check_python_version():
“”“Checks if the script is running on Python 3.10 or later. If not, raises an error.
“””
if sys.version_info < (3, 10):
raise Exception(“Python version 3.10 or later is required, dumbass”)

def check_dependencies():
“”“Checks if the lxml and pandas libraries are installed, and installs them if they are not.
“””
# Check if lxml is installed
try:
import lxml
except ImportError:
subprocess.run([“pip”, “install”, “lxml”])

# Check if pandas is installed
try:
    import pandas
except ImportError:
    subprocess.run(["pip", "install", "pandas"])

def convert(input_file: str, output_file: str) → None:
“”"Converts a COLLADA file to a CSV file containing the vertices of the model.

Args:
    input_file: The path to the COLLADA file to be converted.
    output_file: The path of the CSV file that will be created as a result of the conversion.
"""
# Parse the COLLADA file
tree = ET.parse(input_file)

# Extract the vertices from the file
vertices = tree.xpath("//mesh/vertices/input[@semantic='POSITION']/@source")

# Extract the coordinates from the file
coords = [float(x) for coord_str in tree.xpath(f"//source[@id='{vertex[1:]}']/float_array/text()") for vertex in vertices for x in coord_str.split()]

# Create a Pandas data frame from the list of coordinates
df = pd.DataFrame(coords, columns=["x", "y", "z"])

# Save the data frame to a CSV file
df.to_csv(output_file, index=False)

# The easiest time to add insult to injury is when you’re signing someone’s cast.

############ WinForm C# version ###########################

// C# Collberator
//Author C.Cowen Modelmaker 67 Dec.20_22
//Free public open source
// This takes a colladda file and makes it into an .csv
using System;
using System.IO;
using System.Windows.Forms;
using lxml.etree;
using pandas;

namespace COLLADA_Converter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void CheckDependencies()
    {
        // Check if lxml is installed
        try
        {
            var lxml = typeof(XElement);
        }
        catch (TypeLoadException)
        {
            // lxml is not installed, show an error message
            MessageBox.Show("lxml is not installed. Please install lxml and try again.");
        }

        // Check if pandas is installed
        try
        {
            var pandas = typeof(DataFrame);
        }
        catch (TypeLoadException)
        {
            // pandas is not installed, show an error message
            MessageBox.Show("pandas is not installed. Please install pandas and try again.");
        }
    }

    private void Convert(string inputFile, string outputFile)
    {
        // Parse the COLLADA file
        var tree = XElement.Load(inputFile);

        // Extract the vertices from the file
        var vertices = tree.XPathSelectElements("//mesh/vertices/input[@semantic='POSITION']/@source");

        // Extract the coordinates from the file
        var coords = new List<float>();
        foreach (var vertex in vertices)
        {
            var coordStr = tree.XPathSelectElement($"//source[@id='{vertex.Value[1:]}']/float_array/text()").Value;
            coords.AddRange(coordStr.Split().Select(float.Parse));
        }

        // Create a DataFrame from the list of coordinates
        var df = new DataFrame(coords, new[] { "x", "y", "z" });

        // Save the DataFrame to a CSV file
        df.ToC

//Light travels faster than sound, which is the reason that some people appear bright before you hear them speak.

This is not a good way to share lengthy code- please upload your code to GitHub or PasteBin or anything other than directly in your post