例

以下に、アプリケーションでサポートされている両方のAPIでコマンドを実行する方法を示す2つの簡単な例を示します。

Javascriptコマンドの実行

APIのほとんどのJavascript関数は、Pythonスクリプト内での操作を容易にする文字列またはJsonデータを返します。 データの送受信に大きな問題はないはずです。

example_js.py​という名前のpythonスクリプトファイルを作成し、次のコードを追加します。

import lib_remote



Remote = lib_remote.RemotePainter()

Remote.checkConnection()



## Print the API version

Version = Remote.execScript( "alg.version.painter", "js" )

print( Version )



## Get a list of all the files in the default shelf/library:

Files = Remote.execScript( 'alg.resources.findResources("starter_assets", "*")', "js" )



for File in Files :

 print( File )

アプリケーションがコマンドラインで実行されている場合、このスクリプトを実行すると、コマンドが実行され、その結果が取得されます。

Pythonコマンドの実行

ほとんどのPython関数は、リモートスクリプトに渡すことのできないオブジェクトを返します。つまり、データを受け取るためには、文字列やJson辞書に明示的に変換する必要があります。

より簡単に行うには、アプリケーションの起動時にロードされるカスタムPythonスクリプトを作成し、インライン変換に依存しなくてもこのような変換を処理する関数を呼び出すことができます。

example_py.py​という名前のpythonスクリプトファイルを作成し、次のコードを追加します。

import lib_remote



Remote = lib_remote.RemotePainter()

Remote.checkConnection()



## import the substance_painter module to make

## its API available to us

Remote.execScript( "import substance_painter", "python" )



## Print the API version

Version = Remote.execScript( "substance_painter.__version__", "python" )

print( Version )



## Get a list of all the files in the default shelf/library

## Because the search function return objects, we have to convert

## the information into a string within the same command (inline)

Command = 'substance_painter.resource.search( "p:starter_assets/" )'

Command = '"|||".join( [ x.identifier().url() for x in {0}] )'.format( Command )



Files = Remote.execScript( Command, "python" )

Files = Files.split( "|||" )



for File in Files :

 print( File )

アプリケーションがコマンドラインで実行されている場合、このスクリプトを実行すると、コマンドが実行され、その結果が取得されます。

自動翻訳
言語セレクターを使用して、このページの英語版を表示します。
翻訳は役に立ちましたか?

Ask AI

Not sure where to start?
Ask me anything about Adobe products.

Type your question or pick a suggestion below.

Use of this AI chatbot is subject to Adobe's Privacy Policy. Don't share sensitive data. AI responses are not your Content, may be inaccurate, and any offers provided are non-binding. Generative AI Terms.