Editor scripting access to custom inspectors to automate an asset

I’m trying to automate the setup of my 3d models using editor scripting as they require a bunch of things, and some of them can’t exactly be done in a prefab (e.g. manipulating meshes, etc.).

I’ve run into an issue where I need to automate something that uses a custom inspector for non-trivial setup. Specifically, it has a UI Toolkit based inspector that has some custom fields and logic that runs when a field is filled in, etc.

I’m looking for a way to automate this purely in code. Now of course I could just look at what code the UI runs and run that in my code, but there’s some non-trivial logic, and it would be much easier if I could just programmatically manipulate the inspector.

Is there a way to do this? Specifcally, say there’s a Foo component and associated FooInspector, and I’ve just added the component in code

Foo foo = target.AddComponent<Foo>();
// manipulate target/foo as if I was clicking in the GUI in the inspector here?
// ...

Is there any natural way to solve this?

You can just create the editor for it: Unity - Scripting API: Editor.CreateEditor