Using Python batch 3 in the phantom engine_ Keywords: batch modify attributes

Unreal Python API documentation:- https://docs.unrealengine.com/4.26/en-US/PythonAPI/

In the last article Using Python batch 2 in the phantom engine_ Learning of unreal Library: batch renaming
), I learned how to use Python scripts through the tutorial. Next, I hope to implement some operations I want to do - batch modify object properties.

Although a potentially helpful guide was found in the treasure up owner's video Phantom engine automation - automated Python texture parameter setter , but I'm not going to look at it first. I hope I can try to master the learning method by consulting the official API documents and other information. And this video will be my way of asking for help after I hit a wall everywhere.

Here I quickly found the API document address (by randomly searching for the keyword unreal.SystemLibrary). After a brief browse, it's really long. There are 176 key functions in Library alone. It is estimated that it will be a bit hard to find the corresponding function through this document.

Next, analyze the specific requirements.
There are many components under my USD asset. I need to set the parameters in the components one by one to not render in the main channel (other parameters need not be considered first).
Then, I need to list the operation logic

  • Get selected object
  • View components within an object
  • Set parameter value

Here, because it is USD resource estimation, the lookup component is relatively complex. Try an ordinary object first.

1 get the selected object
First, try to retrieve the Select keyword in the document outline, and find up to 33. Filter out two close keywords through the function name

Click to see the details. It seems useless

Through the selection method in the previous article, you can guess that the commonly used commands are collected in various Library classes. Try to check the EditorUtilityLibrary class to see the built-in methods

Insert a message
When you start the USD plug-in, you find that it has loaded a py script. Follow the path to find the python folder of USD. If you need to operate USD, you can probably find the method from here!
D:\Program Files\Epic Games\UE_4.26\Engine\Plugins\Importers\USDImporter\Content\Python

This is a long dividing line

After I got the selected object, I got stuck in querying and setting the object properties. After some tossing, I had to turn to the above big guy video tutorial to set the sRGB and compression setting properties of the mapped object. See details- Using Python batch processing in the phantom engine 4#: Map parameter settings

You are enlightened, roll up your sleeves and prepare for a big fight. Some are stuck, and the setting operation almost reports an error. The parameter name does not exist on the XX object.
The case adjustment, underline and space adjustment are all reported as errors, and the visible parameters cannot be set. Gas!

After I failed, I pinned my hopes on a large number of scripts brought by the above-mentioned USD plug-in. Interestingly, I tested all kinds of error reports

Let's not talk about the sad things. Post some good resources I met on my way to study:

  • Start using Python in UE4 -This is an introductory article. Its greatest help to me is to obtain the importance of the class of the object and how to obtain the properties and functions of the class.
    Class is actually displayed when we get the object, but we don't pay much attention to it. In fact, the attribute parameters we want to set may not be on this class. To confirm this, you can use the help command in the article to directly help this object to get the help information of this class, including the properties that can be set and the methods that can be called.

  • After knowing that this class does not have this attribute, where to set it? I want to set Render in Main Pass on the object rendering attribute panel

    Through the official help document retrieval, we found unreal.PrimitiveComponent , I can feel that setting this parameter is inseparable from this, but I still don't know how to use it until I find this article There was a problem importing the fbx camera into the phantom engine , the source code attached to the boss provides new help

How to set camera parameters

import unreal

def set_attr():
    # Instantiate unreal class
    editor_util = unreal.EditorUtilityLibrary()

    # Get the camera (here I select it directly)
    selected_assets = editor_util.get_selection_set()
    cine_camera = selected_assets[0]
    unreal.log(cine_camera)

    # The sensor size I want to set is not in cine_camera, because CineCameraActor class does not have this property set
    unreal.log(help(cine_camera))
    
set_attr()

The camera is acquired here, but the sensor size parameter is not on the object
You can find this paragraph from help(cine_camera)

import unreal


def set_attr():
    # Instantiate unreal class
    editor_util = unreal.EditorUtilityLibrary()

    # Get the camera (here I select it directly)
    selected_assets = editor_util.get_selection_set()
    cine_camera = selected_assets[0]
    unreal.log(cine_camera)

    # Get camera components
    cam_component = cine_camera.get_cine_camera_component()
    unreal.log(help(cam_component))
    
set_attr()

The filmback setting can be found on the camera component

The dictionary can be obtained by taking values

unreal.log(cam_component.get_editor_property("filmback"))
LogPython: <Struct 'CameraFilmbackSettings' (0x00000297826CC954) {sensor_width: 22.459999, sensor_height: 18.670000, sensor_aspect_ratio: 1.202999}>

You can set it. After trying, there is no problem,

import unreal

def set_attr():
    # Instantiate unreal class
    editor_util = unreal.EditorUtilityLibrary()

    # Get the camera (here I select it directly)
    selected_assets = editor_util.get_selection_set()
    cine_camera = selected_assets[0]

    # Get camera components
    cam_component = cine_camera.get_cine_camera_component()

    # Set value
    cam_component.set_editor_property("filmback", {"sensor_width": 24})

set_attr()

Now the answer should be found. The reason why the parameter cannot be set is that the parameter is on the component of Actor

Set static mesh body: Render in Main Pass

import unreal

def set_attr():
    # Instantiate unreal class
    editor_util = unreal.EditorUtilityLibrary()

    # Get the object (here I select it directly)
    selected_assets = editor_util.get_selection_set()
    actor = selected_assets[0]

    # Get camera components
    componentList = actor.get_components_by_class(unreal.StaticMeshComponent)
    for component in componentList :
        component.set_render_in_main_pass(False)

set_attr()

The good news is that USD objects can also be generic, oH yHH

I hope this note helps you

Cheers [] ~ ( ̄▽  ̄)~*

Keywords: Python UE4

Added by Adeus on Wed, 19 Jan 2022 03:27:43 +0200