Download

[Python] Error when running .py script from the command line

I’m trying to set up a script for automating Landscape Grass Type creation using Python.

Although I can run the script through the menu, it’ll need commandline arguments and when I try to run the same command as seen in the output log I get an error:


Cmd: py D:/Dropbox/Work/Games/assets/Python/CreateLandscapeGrass.py
LogPython: Landscape Grass Creator 0.1
LogPython: ===========================
LogPython: Usage:
LogPython: py <path to script>/CreateLandscapeGrass.py [path to source StaticMesh folder] [path to existing Landscape Grass Type]
LogPython: e.g. py C:\CreateLandscapeGrass.py /Game/MyFoliage/Meshes/ /Game/MyLandscapeStuff/MyFoliage
LogPython: Beginning test script

LogPython: py D:/Dropbox/Work/Games/assets/Python/CreateLandscapeGrass.py
LogPython: Error: Could not load Python file 'D:/Epic Games/UE_4.19/Engine/Binaries/Win64/py D:/Dropbox/Work/Games/assets/Python/CreateLandscapeGrass.py' (resolved from 'py D:/Dropbox/Work/Games/assets/Python/CreateLandscapeGrass.py')

Any idea what’s up? I tried ensuring the permissions of the script made it available to everyone (I’m running on windows), but it was still a no go.

Well, that was easy to solve once I thought about it.

You cannot run python scripts from the python commandline in UE. You must run them from the normal UE CMD commandline. Go figure.

On to a second question then: I’m not entirely sure if I can do this in the non-UE Studio build, but I want to find or create an asset in the content browser and then modify it.

There isn’t a lot to UE python yet, it seems very limited if you run help(unreal). As a test I’m trying to find an existing asset.


import unreal as ue
ue.find_object("Package", "/Game/Test/SM/Flowers/FlowerParams.FlowerParams", "ULandscapeGrassType")

Does this look right, or am I messing up the syntax or my understanding of what find_object(Outer, Name, Type) is meant to be?

You may want to have a look at this python plugin:

it’s better documented as for now, and have quite robust api to work with editor.

That looks great, cheers!