[php] [chat]シンプルなIPアドレスファイル名ルームでのチャットを作った。

お客様のチャット

<!-- chat.php -->

<?php
function trace($txt){
    //print($txt);
    $a="a";
}
class RoomLog
{
    
    public $LOG_FILE_NAME;
    public $name;
    public $SPLIT_Str;
    public $message;
    public function get_ip_file_name(){
        global $_SERVER;
        $ip_Address=$_SERVER['REMOTE_ADDR'];
        print("ip_Address= " . $ip_Address . "<br>");
        if($ip_Address=="::1"){
            $ip_Address="192.168.1.29";
            print("テストのためip変数上書きしました。ip_Address= " . $ip_Address . "<br>");
        }
        $ip_Address_Arr = explode(".", $ip_Address);
        $ip_file_name = join('_', $ip_Address_Arr);
        $ip_file_name = "log/ip_" . $ip_file_name . "_chatlog.txt";
        print("ip_file_name= " . $ip_file_name . "<br>");
        return $ip_file_name;
    }
    public function initLog(){
        trace("■ initLog()<br>");
        global $LOG_FILE_NAME;
        global $name;
        global $SPLIT_Str;
        global $message;
        
        $ip_file_name=$this->get_ip_file_name();
        
        // データを書き込むファイルの名前
        //$LOG_FILE_NAME = "chat_class_txt_log.txt";
        $LOG_FILE_NAME = $ip_file_name;
     
        // 区切りのための文字列
        $SPLIT_Str = "|-|";
     
        // 名前を格納する変数
        $name = "お客様";
        // メッセージを格納する変数
        $message = "";
        
        $this->LOG_FILE_NAME=$LOG_FILE_NAME;
        $this->name=$name;
        $this->SPLIT_Str=$SPLIT_Str;
        $this->message=$message;
        /*
        trace("<br>");
        trace("this->LOG_FILE_NAME= " . $this->LOG_FILE_NAME . "<br>");
        trace("this->name= " . $this->name . "<br>");
        trace("this->SPLIT_Str= " . $this->SPLIT_Str . "<br>");
        trace("this->message= " . $this->message . "<br>");
        */
    }
    
    public function startMain(){
        trace("■ startMain()<br>");
        $this->initLog();
        $this->CheckFormPostData();
        $this->LogShow();
    }
    

    public function CheckFormPostData(){
        trace("■ CheckFormPostData()<br>");
        global $_POST;
        
        $name = $this->name;
        $SPLIT_Str = $this->SPLIT_Str;
        $message = $this->message;
        
        
        // 送信されたデータ
        $_POST_string = join(', ', $_POST);
        trace("_POST_string2= " . $_POST_string . "<br>");
        
        if (empty($_POST)) {
            trace("The form is empty.");
        } else {
            trace("Form data is present.");
        }
        
        // 送信された名前とメッセージを変数に代入
        if (isset($_POST['name'])) {
          $name = $_POST['name'];
     
          if (strpos($name, $SPLIT_Str) !== false) {
            // 名前に区切り文字が含まれている場合の処理
            echo "使用できない文字列「|-|」が含まれています。";
            return;
          }
     
          if ($name == "") {
            $name = "お客様";
          }
        }
        if (isset($_POST['message'])) {
          $message = $_POST['message'];
     
          if (strpos($message, $SPLIT_Str) !== false) {
            // メッセージに区切り文字が含まれている場合の処理
            echo "使用できない文字列「|-|」が含まれています。";
            return;
          }
     
          //$this->LOG_FILE_NAME=$LOG_FILE_NAME;
          $this->name=$name;
          //$this->SPLIT_Str=$SPLIT_Str;
          $this->message=$message;
          $this->LogWrite();
        }
    }
   
    
    public function LogWrite(){
      trace("■ LogWrite()<br>");
      $LOG_FILE_NAME = $this->LOG_FILE_NAME;
      $name = $this->name;
      $SPLIT_Str = $this->SPLIT_Str;
      $message = $this->message;
        
      //書き込みモードでファイルを開く
      $fp = fopen($LOG_FILE_NAME, "a") or exit($LOG_FILE_NAME . "が開けません");
 
      // | を区切り文字として2つのデータを繋げて書き込む
      fwrite($fp, $name . $SPLIT_Str . $message . "\n");
      
      
      // リダイレクトのためのHTTPヘッダーを送信
      //header("Location: " . $_SERVER['PHP_SELF'], true, 303);
      
      fclose($fp);
    }

    function LogShow(){
        trace("■ LogShow()<br>");
        //global $LOG_FILE_NAME;
        global $linesNum;
        global $lines;
        $LOG_FILE_NAME = $this->LOG_FILE_NAME;
        //$name = $this->name;
        //$SPLIT_Str = $this->SPLIT_Str;
        //$message = $this->message;
        
        if (!file_exists($LOG_FILE_NAME)) {
          // ファイルがない場合
          echo "書き込みはありません。";
     
          $linesNum = 0;
        } else {
     
          // ファイルの全行を読み取る
          $lines = file($LOG_FILE_NAME);
     
          // 読み込んだ行数
          $linesNum = count($lines);
        }
    }
    
}

$RoomLog_ins = new RoomLog();
$RoomLog_ins->startMain();

?>
 
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="utf-8">
  <title>1行メッセージ</title>
</head>
 
<body>
 
<h1>お問い合わせ内容</h1>
 
  <section>
    <?php
 
      // 一行ずつ表示する処理
      for ($i = 0; $i < $linesNum; $i++) {
 
         // 区切り文字でデータを区切って配列に格納
         $array = explode($SPLIT_Str, $lines[$i]);
 
         // 区切り文字の前の部分は名前
         $name = htmlspecialchars($array[0]);
         
         
         // 区切り文字の後の部分はメッセージ
         
         $array_length = count($array);
         if ($array_length == 2) {
           $message = htmlspecialchars($array[1]);
         }
         // 名前とメッセージを表示
         echo '<p>' . $name . "「" . str_replace(PHP_EOL, "", $message) . '」</p>';
      }
    ?>
  </section>


  
 
  <form method="post" action="chat_class_txt.php">
    <div>
      <!--<b>おなまえ</b>-->
      <!--<input name="name" type="text" size="20" maxlength="10">-->
      <input name="name" type="hidden" size="20" maxlength="10">
    </div>
    <div>
      <!--<b>ご入力</b>-->
      <input name="message" type="text" size="50" maxlength="50" required>
      <button name="submit" type="submit">送信</button>
    </div>
    
  </form>
  
</body>
</html>

担当者のチャット画面

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="utf-8">
  <title>1行メッセージ</title>
</head>
 
<body>
<!-- chat.php -->

<style>
.base {
  display: flex;
  flex-direction: row;
  width: 100vw;
  height: 90vh;
}
.class1 {
  width: 10%;
}
 
.class2 {
  display: flex;
  flex-direction: column;
  width: 90%;
}

</style>
<style>
  div {
    text-align: center;
    /* background-color: #aaaaaa; 16進数のカラーコードを使用する例 */
  }
  button{
      font-size: 200%;
      width:100px;
      height:100px;
  }
</style>
  <div class="base">
    <div class="class1">

<?php
//$dir = "log";
//$files = scandir($dir);
$files = glob("log/*");
$counter=0;
foreach ($files as $file) {
    //echo("<h2>" . $file . "</h2><br>");
    $url='log_frame.php';
    //echo('<a href="'.$url.'"><h1><div >' . $counter . '</div></h1></a><br>');
    
    $htmlStr='';
    $htmlStr=$htmlStr.'<form method="post" action="chat_class_txt_admin.php">';
    $htmlStr=$htmlStr.'<input type="hidden" name="LOG_FILE_NAME" value="' . $file . '">';
    $htmlStr=$htmlStr.'<button name="submit" type="submit">' . $counter . '</button>';
    $htmlStr=$htmlStr.'</form>';
    echo($htmlStr);

    $counter=$counter+1;
}

?>
      
</div>
<div class="class2">
<?php
function trace($txt){
    //print($txt);
    $a="a";
}
class RoomLog
{
    
    public $LOG_FILE_NAME;
    public $LOG_FILE_NAME_Opened;
    public $name;
    public $SPLIT_Str;
    public $message;
    public function get_ip_file_name(){
        global $_SERVER;
        $ip_Address=$_SERVER['REMOTE_ADDR'];
        trace("ip_Address= " . $ip_Address . "<br>");
        if($ip_Address=="::1"){
            $ip_Address="192.168.1.29";
            trace("テストのためip変数上書きしました。ip_Address= " . $ip_Address . "<br>");
        }
        $ip_Address_Arr = explode(".", $ip_Address);
        $ip_file_name = join('_', $ip_Address_Arr);
        $ip_file_name = "log/ip_" . $ip_file_name . "_chatlog.txt";
        trace("ip_file_name= " . $ip_file_name . "<br>");
        return $ip_file_name;
    }
    
    public function CheckFormPostData_Admin(){
        trace("■ CheckFormPostData_Admin()<br>");
        global $_POST;
        
        // 送信されたデータ
        $_POST_string = join(', ', $_POST);
        trace("_POST_string1= " . $_POST_string . "<br>");
        
        if (empty($_POST)) {
            trace("The form is empty.<br>");
        } else {
            trace("Form data is OK present.<br>");
        }
        if (isset($_POST['LOG_FILE_NAME'])) {
          $LOG_FILE_NAME = $_POST['LOG_FILE_NAME'];
          $this->LOG_FILE_NAME=$LOG_FILE_NAME;
          print("LOG_FILE_NAME= " . $LOG_FILE_NAME . "<br>");
        }
        /*
        // 送信された名前とメッセージを変数に代入
        if (isset($_POST['name'])) {
          $name = $_POST['name'];
     
          if (strpos($name, $SPLIT_Str) !== false) {
            // 名前に区切り文字が含まれている場合の処理
            echo "使用できない文字列「|-|」が含まれています。";
            return;
          }
     
          if ($name == "") {
            $name = "お客様";
          }
        }
        if (isset($_POST['message'])) {
          $message = $_POST['message'];
     
          if (strpos($message, $SPLIT_Str) !== false) {
            // メッセージに区切り文字が含まれている場合の処理
            echo "使用できない文字列「|-|」が含まれています。";
            return;
          }
     
          //$this->LOG_FILE_NAME=$LOG_FILE_NAME;
          $this->name=$name;
          //$this->SPLIT_Str=$SPLIT_Str;
          $this->message=$message;
          $this->LogWrite();
        }
        */
        return $LOG_FILE_NAME;
    }

    public function initLog(){
        trace("■ initLog()<br>");
        global $LOG_FILE_NAME;
        global $name;
        global $SPLIT_Str;
        global $message;
        
        $ip_file_name=$this->CheckFormPostData_Admin();
        
        // データを書き込むファイルの名前
        //$LOG_FILE_NAME = "chat_class_txt_log.txt";
        $LOG_FILE_NAME = $ip_file_name;
     
        // 区切りのための文字列
        $SPLIT_Str = "|-|";
     
        // 名前を格納する変数
        $name = "担当者";
        // メッセージを格納する変数
        $message = "";
        
        $this->LOG_FILE_NAME=$LOG_FILE_NAME;
        $this->name=$name;
        $this->SPLIT_Str=$SPLIT_Str;
        $this->message=$message;
        /*
        trace("<br>");
        trace("this->LOG_FILE_NAME= " . $this->LOG_FILE_NAME . "<br>");
        trace("this->name= " . $this->name . "<br>");
        trace("this->SPLIT_Str= " . $this->SPLIT_Str . "<br>");
        trace("this->message= " . $this->message . "<br>");
        */
    }
    
    public function startMain(){
        trace("■ startMain()<br>");
        $this->initLog();
        $this->CheckFormPostData();
        $this->LogShow();
    }
    

    public function CheckFormPostData(){
        trace("■ CheckFormPostData()<br>");
        global $_POST;
        
        $name = $this->name;
        $SPLIT_Str = $this->SPLIT_Str;
        $message = $this->message;
        
        
        // 送信されたデータ
        $_POST_string = join(', ', $_POST);
        //trace("_POST_string2= " . $_POST_string . "<br>");
        
        if (empty($_POST)) {
            trace("The form is empty.<br>");
        } else {
            trace("Form data is present.<br>");
        }
        
        // 送信された名前とメッセージを変数に代入
        if (isset($_POST['name'])) {
          $name = $_POST['name'];
     
          if (strpos($name, $SPLIT_Str) !== false) {
            // 名前に区切り文字が含まれている場合の処理
            echo "使用できない文字列「|-|」が含まれています。<br>";
            return;
          }
     
          if ($name == "") {
            $name = "担当者";
          }
        }
        if (isset($_POST['message'])) {
          $message = $_POST['message'];
     
          if (strpos($message, $SPLIT_Str) !== false) {
            // メッセージに区切り文字が含まれている場合の処理
            echo "使用できない文字列「|-|」が含まれています。<br>";
            return;
          }
     
          //$this->LOG_FILE_NAME=$LOG_FILE_NAME;
          $this->name=$name;
          //$this->SPLIT_Str=$SPLIT_Str;
          $this->message=$message;
          $this->LogWrite();
        }
    }
   
    
    public function LogWrite(){
      trace("■ LogWrite()<br>");
      $LOG_FILE_NAME = $this->LOG_FILE_NAME;
      $name = $this->name;
      $SPLIT_Str = $this->SPLIT_Str;
      $message = $this->message;
        
      //書き込みモードでファイルを開く
      $fp = fopen($LOG_FILE_NAME, "a") or exit($LOG_FILE_NAME . "が開けません<br>");
 
      // | を区切り文字として2つのデータを繋げて書き込む
      fwrite($fp, $name . $SPLIT_Str . $message . "\n");
      
      
      // リダイレクトのためのHTTPヘッダーを送信
      //header("Location: " . $_SERVER['PHP_SELF'], true, 303);
      
      fclose($fp);
    }

    function LogShow(){
        trace("■ LogShow()<br>");
        //global $LOG_FILE_NAME;
        global $linesNum;
        global $lines;
        $LOG_FILE_NAME = $this->LOG_FILE_NAME;
        //$name = $this->name;
        //$SPLIT_Str = $this->SPLIT_Str;
        //$message = $this->message;
        
        if (!file_exists($LOG_FILE_NAME)) {
          // ファイルがない場合
          echo "書き込みはありません。<br>";
     
          $linesNum = 0;
        } else {
     
          // ファイルの全行を読み取る
          $lines = file($LOG_FILE_NAME);
     
          // 読み込んだ行数
          $linesNum = count($lines);
        }
    }
    
}

$RoomLog_ins = new RoomLog();
$RoomLog_ins->startMain();

?>
 

 
<h1>お問い合わせ内容</h1>
 
  <section>
    <?php
 
      // 一行ずつ表示する処理
      for ($i = 0; $i < $linesNum; $i++) {
 
         // 区切り文字でデータを区切って配列に格納
         $array = explode($SPLIT_Str, $lines[$i]);
 
         // 区切り文字の前の部分は名前
         $name = htmlspecialchars($array[0]);
         
         
         // 区切り文字の後の部分はメッセージ
         
         $array_length = count($array);
         if ($array_length == 2) {
           $message = htmlspecialchars($array[1]);
         }
         // 名前とメッセージを表示
         echo '<p>' . $name . "「" . str_replace(PHP_EOL, "", $message) . '」</p>';
      }
    ?>
  </section>


  
 
  <form method="post" action="chat_class_txt_admin.php">
    <div>
      <!--<b>おなまえ</b>-->
      <!--<input name="name" type="text" size="20" maxlength="10">-->
      <input name="name" type="hidden" size="20" maxlength="10">
    </div>
    <div>
      <!--<b>ご入力</b>-->
      <?php
      echo('<input type="hidden" name="LOG_FILE_NAME" value="' . $LOG_FILE_NAME . '">');
      ?>
      <input name="message" type="text" size="50" maxlength="50" required>
      <button name="submit" type="submit">送信</button>
    </div>
    
  </form>
  
  
    </div><!--div class="class2"-->
  </div><!--div class="base"-->
</body>
</html>

こちらのサイトを参考にしました。
PHPで作るチャット(7) クロスサイトスクリプティング(XSS)の修正

このPHPをクラスベースで書き直しました。

[xampp] php Rechet chatを作る勉強。

参考サイト

[PHP]Ratchetの初期設定とテキストのリアルタイム通信テスト

Xamppをwindowsをインストール

https://sourceforge.net/projects/xampp/files/XAMPP%20Windows/7.4.33/

お名前.comのPHPが7.4なので

https://sourceforge.net/projects/xampp/files/XAMPP%20Windows/7.4.33/xampp-windows-x64-7.4.33-0-VC15-installer.exe/download

をダウンロードした。

システム環境変数にphpのパスを通す

C:\xampp\php

PHPのバージョン確認

PS C:\xampp\htdocs> php -v
PHP 7.4.33 (cli) (built: Nov  2 2022 16:00:55) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
PS C:\xampp\htdocs>

Composerをインストール

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e21205b207c3ff031906575712edab6f13eb0b361f2085f1f1237b7126d785e826a450292b6cfd1d64d92e6563bbde02') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

XAMPP の htdocs ディレクトリに任意の名前のフォルダを作成し、ターミナルでアクセスできる状態にします。この例では MyChat というフォルダ名にしています。

php ../composer.phar require cboden/ratchet

こんなファイルが出てきます。

composer.json を開き autoload の5行を追記します。

{
    "autoload": {
        "psr-4": {
            "MyApp\\": "src"
        }
    },
    "require": {
        "cboden/ratchet": "^0.4.3"
    }
}

ディレクトリ MyChat にフォルダ src/ を作成し、その中に(Chat.php)を作成します。

<?php
namespace MyApp;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
 
class Chat implements MessageComponentInterface {
    public function onOpen(ConnectionInterface $conn) {
    }
 
    public function onMessage(ConnectionInterface $from, $msg) {
    }
 
    public function onClose(ConnectionInterface $conn) {
    }
 
    public function onError(ConnectionInterface $conn, \Exception $e) {
    }
}

同様にフォルダ bin/ を作成し、その中にスクリプト(chat-server.php)を作成してください。

<?php
use Ratchet\Server\IoServer;
use MyApp\Chat;
 
    require dirname(__DIR__) . '/vendor/autoload.php';
 
    $server = IoServer::factory(
        new Chat(),
        8080
    );
 
    $server->run();

以上のスクリプトを作成後、ターミナルで以下のコマンドを入力してください。

php bin/chat-server.php

正常に動作するとターミナルには何も表示されないはずですが、以下のようなエラーが表示される場合があります。

PS C:\xampp\htdocs\MyChat> php bin/chat-server.php
PHP Fatal error:  Uncaught Error: Class 'MyApp\Chat' not found in C:\xampp\htdocs\MyChat\bin\chat-server.php:8
Stack trace:
#0 {main}
  thrown in C:\xampp\htdocs\MyChat\bin\chat-server.php on line 8

Fatal error: Uncaught Error: Class 'MyApp\Chat' not found in C:\xampp\htdocs\MyChat\bin\chat-server.php:8
Stack trace:
#0 {main}
  thrown in C:\xampp\htdocs\MyChat\bin\chat-server.php on line 8
PS C:\xampp\htdocs\MyChat>

もしこのエラーが表示されたなら composer.phar のアップデートを実行してみてください。アップデートのコマンドは以下のとおりです。

	php ../composer.phar update

再度やってみます。

php bin/chat-server.php

正常に動作した場合は control+C で終了させてください。

以上で通信のための準備が整いました。

メッセージ送信の実行

実際に通信をテストするには、まず Chat.php を以下のように書き換えます。

<?php
namespace MyApp;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
 
class Chat implements MessageComponentInterface {
    protected $clients;
 
    public function __construct() {
        $this->clients = new \SplObjectStorage;
    }
 
    public function onOpen(ConnectionInterface $conn) {
        // Store the new connection to send messages to later
        $this->clients->attach($conn);
 
        echo "New connection! ({$conn->resourceId})\n";
    }
 
    public function onMessage(ConnectionInterface $from, $msg) {
        $numRecv = count($this->clients) - 1;
        echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n"
            , $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's');
 
        foreach ($this->clients as $client) {
            if ($from !== $client) {
                // The sender is not the receiver, send to each client connected
                $client->send($msg);
            }
        }
    }
 
    public function onClose(ConnectionInterface $conn) {
        // The connection is closed, remove it, as we can no longer send it messages
        $this->clients->detach($conn);
 
        echo "Connection {$conn->resourceId} has disconnected\n";
    }
 
    public function onError(ConnectionInterface $conn, \Exception $e) {
        echo "An error has occurred: {$e->getMessage()}\n";
 
        $conn->close();
    }
}

そして、ターミナルのウィンドウを3つ開き、それぞれ以下のコマンドを入力します。

php bin/chat-server.php
telnet localhost 8080
telnet localhost 8080

もし telnet がないと言われた場合は python を利用する以下のコマンドを試してみてください。

	python -m telnetlib localhost 8080

実行結果です。一方のtelnetにメッセージを入力すると、他方にメッセージが表示されます。接続状態などは bin/chat-server.php を実行したウィンドウに表示されます。

ブラウザを利用したメッセージの送信

chat-server.php を以下のように書き換えます。

<?php
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use MyApp\Chat;
 
    require dirname(__DIR__) . '/vendor/autoload.php';
 
    $server = IoServer::factory(
        new HttpServer(
            new WsServer(
                new Chat()
            )
        ),
        8080
    );
 
    $server->run();

ターミナルで再度 bin/chat-server.php を実行し、

MyChat/index.htmlに以下のHTMLフォームボタンで動くとjavascriptを入力します。

<br><br><br><br><br><br><br><br>
<a href="javascript:myFunction();">リンクでJSのmyFunction()実行</a>
<script>
function myFunction() {
// フォームボタンがクリックされたときの処理をここに記述

//------------------------------------------------------
var conn = new WebSocket('ws://localhost:8080');
conn.onopen = function(e) {
    console.log("Connection established!");
};
 
conn.onmessage = function(e) {
    console.log(e.data);
};
//------------------------------------------------------
alert('入室しました!');
}
</script>

実行結果は以下のとおりです。

ターミナルにブラウザから send によって送信したメッセージが表示されました。

以上、Ratchetの初期設定と、それを利用した通信の例でした。

[maya] maya_usd で get Selected Prim Path

maya_usd 選択したprimからprimのpathを得る方法
ls で取れた、

ufeObjects(ufe)

-sl/selectionフラグ と組み合わせて使用​​すると、ネイティブ Maya オブジェクトだけでなく、UFE インターフェイスを通じて定義されたオブジェクトも返されます。

import maya.cmds as cmds
 
proxy_prim_path = cmds.ls(sl=True, ufe = True)
#or
proxy_prim_path = cmds.ls(sl=True, ufeObjects = True)
print("proxy_prim_path= "+str(proxy_prim_path))

Output

proxy_prim_path= ['|stage1|stageShape1,/Ball1/Ball_Mesh']

参考URL

https://help.autodesk.com/cloudhelp/2022/ENU/Maya-Tech-Docs/CommandsPython/ls.html

https://stackoverflow.com/questions/76558940/select-and-hide-multiple-usd-prims-in-maya

[maya][python]scriptEditorInfoでスクリプトエディタの内容のログの最後の行を取る

Take the last line of the log in the contents of the script editor

#!/usr/bin/env python
# -*- coding: utf-8 -*-
workSpaceDir=cmds.workspace( q=True, rootDirectory=True )
print("workSpaceDir= "+workSpaceDir)
historyFilename=workSpaceDir+'scriptEditorInfo_tempHistoryLog7.txt'
print("historyFilename= "+historyFilename)
cmds.scriptEditorInfo(input="")
cmds.scriptEditorInfo( historyFilename=historyFilename, writeHistory=True )

print("----startLog00700---")
#-----この間にUSD prim を選択させてみたい。 ----------
#------難しいかな??
#-----この間にUSD prim を選択させてみたい。 ----------
import codecs
fin  = codecs.open(historyFilename, 'r', 'shift_jis')
lineCount=0
lineArr=[]
for line in fin:
    #print("lineNum:"+str(lineCount)+" lineStr:"+line)
    lineCount=lineCount+1
    lineArr.append(line)
#fout = codecs.open('sjis.txt', 'w', 'shift_jis')
#fin_str=str(fin)
lineArr_len=len(lineArr)
print("lineArr_len= "+str(lineArr_len))
LastLine_Str=lineArr[lineArr_len-1]
print("LastLine_Str= "+LastLine_Str)

cmds.scriptEditorInfo(input="")
cmds.scriptEditorInfo( historyFilename=historyFilename, writeHistory=False )

print("----NotLoged----")

[maya][mel] scriptedPanel のサンプルを動作させてみた。想像と違った。

I tried running the scriptedPanel sample.

// define callbacks for this type and make it a unique type
// as we don't want two panels sharing the same global data.

scriptedPanelType
    -ccb sampleCreateCallback
    -icb sampleInitCallback
    -acb sampleAddCallback
    -rcb sampleRemoveCallback
    -dcb sampleDeleteCallback
    -scb sampleSaveStateCallback
    -unique true
    "sampleScriptedPanelType6";


global proc sampleCreateCallback(string $panelName) {
//
//  Description:
//      Create any editors unparented here and do
//      any other initialization required.
//
//      In this example we will only declare a global array to
//        maintain some state information.
//
    global float $gSampleState[5];

}


global proc sampleInitCallback(string $panelName) {
//
//  Description:
//      Re-initialize the panel on file -new or file -open.
//
//      In this example we will only re-init the global array.
//
    global float $gSampleState[];

       $gSampleState[0] = 20.2;
       $gSampleState[1] = 50.5;
       $gSampleState[2] = 34.7;
       $gSampleState[3] = 2.0;
       $gSampleState[4] = 1.0;

}

global proc sampleAddCallback(string $panelName) {
//
//  Description:  Create UI and parent any editors.
//
    global float $gSampleState[];

    columnLayout -adj true topCol;
    separator -style "none" -h 10;
        frameLayout -l "Sliders" -mw 10;
            columnLayout -adj true sampleCol;
                separator -style "none" -h 10;

                floatSliderGrp -l "Property A" -f true
                    -v $gSampleState[0]
                    fsg1;
                floatSliderGrp -l "Property B" -f true
                    -v $gSampleState[1]
                    fsg2;
                floatSliderGrp -l "Property C" -f true
                    -v $gSampleState[2]
                    fsg3;
                separator -style "none" -h 10;
            setParent ..;
        setParent ..;

        separator -style "none" -h 10;
        frameLayout -l "Radio Buttons" -mw 10;
            columnLayout sampleCol2;
                separator -style "none" -h 10;
                radioButtonGrp -nrb 3
                    -l "Big Options"
                    -la3 "Option 1" "Option 2" "Option 3"
                    -select $gSampleState[3]
                    rbg;
                radioButtonGrp -nrb 3
                    -l "Little Options"
                    -la3 "Option 4" "Option 5" "Option 6"
                    -select $gSampleState[4]
                    rbg2;
                separator -style "none" -h 10;

}

global proc sampleRemoveCallback(string $panelName) {
//
//  Description:
//        Unparent any editors and save state if required.
//
        global float $gSampleState[];
       //  Scope the control names to this panel.
       //
       string $control = `scriptedPanel -q -control $panelName`;
       setParent $control;

       $gSampleState[0] = `floatSliderGrp -q -v fsg1`;
       $gSampleState[1] = `floatSliderGrp -q -v fsg2`;
       $gSampleState[2] = `floatSliderGrp -q -v fsg3`;
       $gSampleState[3] = `radioButtonGrp -q -sl rbg`;
       $gSampleState[4] = `radioButtonGrp -q -sl rbg2`;
}

global proc sampleDeleteCallback(string $panelName) {
//
//  Description:
//        Delete any editors and do any other cleanup required.

}

global proc string sampleSaveStateCallback(string $panelName) {
//
//  Description:
//        Return a string that will restore the current state
//        when it is executed.

        global float $gSampleState[];
       $indent = "\n\t\t\t";

       return ($indent+"$gSampleState[0]="+$gSampleState[0]+";" +
               $indent+"$gSampleState[1]="+$gSampleState[1]+";" +
               $indent+"$gSampleState[2]="+$gSampleState[2]+";" +
               $indent+"$gSampleState[3]="+$gSampleState[3]+";" +
               $indent+"$gSampleState[4]="+$gSampleState[4]+";" +
               $indent+"setSamplePanelState $panelName;\n" );
}

global proc setSamplePanelState( string $whichPanel ) {
//
//  Description:
//        This is a convenience proc to set the panel state from the
//        global array

        global float $gSampleState[];

       //  Scope the control names to this panel.
       //
       string $control = `scriptedPanel -q -control $whichPanel`;
       if ("" != $control) {
              setParent $control;

              floatSliderGrp -e -v $gSampleState[0] fsg1;
              floatSliderGrp -e -v $gSampleState[1] fsg2;
              floatSliderGrp -e -v $gSampleState[2] fsg3;
              if (0 != $gSampleState[3]) {
               radioButtonGrp -e -sl $gSampleState[3] rbg;
              };
           if (0 != $gSampleState[4]) {
               radioButtonGrp -e -sl $gSampleState[4] rbg2;
           }
       }
}


//  This script will create an unparented scripted panel, place it
//  in one window, remove it, and place it in another window then
//  return it to the first window.
//

//    Create unparented scripted panel
//
scriptedPanel -unParent -type "sampleScriptedPanelType6" -label "Sample" "sampleScriptedPanel6";

//    Create a couple of windows and parent the scripted panel to the first.
//
window "sampleWin6";
frameLayout -lv false -bv false frm;
scriptedPanel -e -parent "sampleWin6|frm" "sampleScriptedPanel6";
showWindow;
/*
window -w `window -q -w sampleWin` -h `window -q -h "sampleWin"` "sampleWin2";
frameLayout -lv false -bv false frm;
showWindow;
*/

[maya]maya_usdでstageのレイヤーにprimxformを作る、そのprimxformにAdd USD Referenceを追加する。

Create a primxform in the stage layer with maya_usd, and add Add USD Reference to that primxform.

print("add_primxform_for_stage_layer")

import maya.cmds as cmds
from maya import cmds
import mayaUsd.ufe
from pxr import Usd, UsdGeom
import re
import os
#cmds.workspace( directory=workspacepath)でいいかとおもっていたけどちがかった件。
def evalMelSetProject(FullDirPath):
	print("-----------------------------------maya.mel.eval evalMelSetProject(evalstr)----------------------------------------")# 20161121
	evalstr='setProject("'+FullDirPath+'");' #OK
	print("evalstr="+evalstr);
	maya.mel.eval(evalstr) #OK
	print("----------------------------------maya.mel.eval evalMelSetProject(evalstr) End----------------------------------")
	

def get_stage(stagePath):
    import mayaUsd.ufe
    #stagePath="|stage1|stageShape1"
    #stage = mayaUsd.ufe.getStage("|stage1|stageShape1")
    stage = mayaUsd.ufe.getStage(stagePath)
    print("stage= "+str(stage))
    # レイヤーを取得
    layer = stage.GetRootLayer()
    print("layer= "+str(layer))
    return stage


    
def get_selected_maya_usd_stage():
    selectedlist=cmds.ls(sl=True,long=1)
    print("selectedlist= "+str(selectedlist))
    selectedZero=selectedlist[0]
    print("selectedZero= "+selectedZero)
    selectedZeroType=cmds.objectType( selectedZero )
    print("selectedZeroType= "+str(selectedZeroType))
    usd_stage=""
    stagePath=""
    if(str(selectedZeroType)=="mayaUsdProxyShape"):
        layerPath=selectedZero
        usd_stage=get_stage(layerPath)
    elif(str(selectedZeroType)=="transform"):
        stageNumStr=selectedZero[6:]
        layerPath="|stage"+stageNumStr+"|stageShape"+stageNumStr
        print("layerPath= "+layerPath)
        cmds.select(layerPath)
        usd_stage=get_stage(layerPath)
    else:
        print("not stage!!!!")
    return usd_stage,layerPath


def usd_increment_name(name,existing_names):
    new_name = name
    i = 1
    # in演算子 new_name が existing_names に存在する場合はTrueを、そうでない場合はFalseを返します。
    while new_name in existing_names:
        new_name = name+str(i)
        print("存在します。"+str(new_name))
        i += 1
       
    else:
        print("while out  "+str(new_name))
    return new_name  

print("----start-----")
def add_prim_xform_for_stage_layer(add_ref_USD_file_path):
    #---------------------SetProject-------------------------
    filePath = cmds.file(q=1,sceneName=1)
    print("filePath= "+filePath)
    dirPath = os.path.dirname(filePath)
    dirPath=re.sub(r'\\', '/', dirPath)
    #dirPath=os.path.abspath(dirPath)
    print("dirPath= "+dirPath)
    FullDirPath=dirPath
    evalMelSetProject(FullDirPath)
    #-------------------------------------------------------
    
    stage,layerPath = get_selected_maya_usd_stage()
    print("stage= "+str(stage))
    print("layerPath= "+str(layerPath))
    # レイヤーを取得
    #layer = stage.GetEditTarget().GetLayer()
    layer = stage.GetRootLayer()
    print("layer= "+str(layer))
    
    # Primを作成
    prim_count=1
    prim_path = "/Xform"+str(prim_count)
    newPrimStagePath=layerPath+","+prim_path
    print("newPrimStagePath= "+newPrimStagePath)
    
    #layerPrimList = cmds.listRelatives(layerPath,children=1)
    #layerPrimList = cmds.listConnections(layerPath,destination=1)
    #print("layerPrimList= "+str(layerPrimList))

    # レイヤー内のすべてのPrimを取得
    all_prims = stage.Traverse()
    print("all_prims= "+str(all_prims))
    # Primのリストを出力
    
    all_primName_list=[]
    for prim in all_prims:
        print(prim.GetPath())
        all_primName_list.append(str(prim.GetPath()))
    print("all_primName_list= "+str(all_primName_list))
    
    
    newPrim_path=usd_increment_name("/Xform",all_primName_list)
    print("newPrim_path= "+newPrim_path)
    
    # Primを作成
    prim = UsdGeom.Xform.Define(stage, newPrim_path)
    
    # レイヤーにPrimを追加
    #layer.GetPrimAtPath(newPrim_path)
    
    print("Primが追加されました:", prim.GetPath())
   
    # 追加するUSDファイルのパス
    referencePath = dirPath+"/Usd/S_Stg_Cys_StartArea_Grd.usda"
    referencePath = add_ref_USD_file_path
    print("referencePath= "+referencePath)
    # USDリファレンスを追加
    prim.GetPrim().GetReferences().AddReference(referencePath)
    
    # ステージを保存
    #
    #setAttr -type "string" |stage6|stageShape6.filePath "D:/SandBox/USD_Maya2023/16_newyear/stageShape6-1GGoNk.usd";
    #cmds.setAttr -type "string" |stage6|stageShape6.filePath "D:/SandBox/USD_Maya2023/16_newyear/stageShape6-1GGoNk.usd";
    attName=layerPath+".filePath"
    layout_attpath=dirPath+"/Usd/Stg_Cys_003Floor01_example.usd"
    layout_attpath=dirPath+"/Layout_00100.usd"
    print("layout_attpath= "+layout_attpath)
    cmds.setAttr( attName, layout_attpath,type="string")
    #stage.GetRootLayer().subLayerPaths.append(dirPath+"Usd/Stg_Cys_003Floor01_example.usd")
    #stage.GetRootLayer().Save()
    """"""
    
#add_prim_xform_for_stage_layer()

g_lastSetPath=""

def select_exportDir(self):
    
    filePath = cmds.fileDialog2( cap = 'リファレンスするディレクトリの選択', okc = 'リファレンスするディレクトリを設定',dialogStyle = 2, fileMode = 3,startingDirectory=get_lastSetPath())
    if filePath == None:
        return False
    else:
        set_refDirPath(filePath[0]+"/")
        
def set_refDirPath(refDir):
    print("refDir= "+refDir)
    refDir_Arr=refDir.split("/")
    refDir_Arr_last=len(refDir_Arr)
    print("refDir_Arr_last= "+str(refDir_Arr_last))
    DirName=refDir_Arr[refDir_Arr_last-2]
    print("DirName= "+DirName)
    #D:/SandBox/USD_Maya2023/17_subfolder/Stick/Stick.mb
    ref_USD_filePath=refDir+DirName+".usda"
    add_prim_xform_for_stage_layer(ref_USD_filePath)
    
def exportFile():
    filePath = cmds.fileDialog2(fileFilter = '*.json', cap = '書き出し', okc = '書き出し',ds = 2, fm = 0)
    if filePath == None:
        return False
               
def importFile():
    filePath = cmds.fileDialog2(fileFilter = '*.json', cap = '読み込み', okc = '読み込み',ds = 2, fm = 1)
    if filePath == None:
        return False

def get_lastSetPath():
    global g_lastSetPath
    lastSetPath=""
    if(g_lastSetPath==""):
        print("g_lastSetPath=は値なし")
        scenePath=get_scenePath_ref()
        scenePath=os.path.abspath(scenePath)
        lastSetPath=scenePath
        g_lastSetPath=lastSetPath
    else:
        print("g_lastSetPath=は値 g_lastSetPath="+g_lastSetPath)
        lastSetPath=g_lastSetPath
    print("g_lastSetPath= "+g_lastSetPath)
    print("lastSetPath= "+lastSetPath)
    return lastSetPath

def get_scenePath_ref():
    scenefilePath = cmds.file(q=1, sceneName=1)
    mayaPath,mayaFile = os.path.split(scenefilePath)
    #mayaPath = mayaPath + "/Usd/"
    mayaPath=os.path.abspath(mayaPath)
    return mayaPath


text_Field_id=""       
def createWindow():
    scenefilePath = cmds.file(q=1, sceneName=1)

    USD_window = cmds.window("FURC_USD_Layout_Add_PrimXformReference_For_StageLayer_Window", widthHeight=(400, 200))
    USD_layout = cmds.columnLayout("USD_layout",adjustableColumn=True, parent=USD_window)

    cmds.text (label="primをぶら下げたいステージのレイヤーを選択して、", align='left', parent=USD_layout)
    cmds.text (label="[Add USD Referernce/Payload...]を押してください", align='left', parent=USD_layout)
    cmds.separator(parent=USD_layout)
    
    cmds.button(label="Add USD Referernce/Payload... ", command=select_exportDir, parent=USD_layout)
    
    #cmds.separator(parent=USD_layout)

    #cmds.button(label="Add USD Referernce/Payload... ", command=add_prim_xform_for_stage_layer, parent=USD_layout)

    cmds.showWindow(USD_window)
    return None


def folderOpen(self):
    Exportpath = get_lastExportDirPath()
    Exportpath = Exportpath.replace('/', '\\')
    subprocess.Popen(["explorer", "/root,", Exportpath], shell=True)
    print(USD.mayaPath)

def get_scenePath():
    scenefilePath = cmds.file(q=1, sceneName=1)
    mayaPath,mayaFile = os.path.split(scenefilePath)
    mayaPath = mayaPath + "/Usd/"
    return mayaPath
    
def btn_scene(self):
    scenePath = get_scenePath()
    print("scenePath= "+scenePath)
    set_lastExportDirPath(scenePath)
    
def changeTextFld(*arg):
    #mayaPath = get_scenePath()
    #cmds.textField("pathTxtFld", edit=True, text=get_lastExportDirPath())
    #pathTxtFld_value=cmds.textField("pathTxtFld", r=True, v=True)
    #pathTxtFld_value = cmds.textField("pathTxtFld", q=True, text=True)
    text_Field_id="FURC_USD_Layout_Add_PrimXformReference_For_StageLayer_Window|USD_layout|pathTxtFld"
    print("text_Field_id= "+text_Field_id)
    pathTxtFld_value = cmds.textField(text_Field_id, q=True, text=True)
    #pathTxtFld_value = pathTxtFld
    print("pathTxtFld_value= "+pathTxtFld_value)
    set_lastExportDirPath(pathTxtFld_value)
    
def clearWindow():
    if cmds.window("FURC_USD_Layout_Add_PrimXformReference_For_StageLayer_Window",exists=True):
        cmds.deleteUI("FURC_USD_Layout_Add_PrimXformReference_For_StageLayer_Window")
    return None
    
def FURC_USD_Layout_Add_PrimXformReference_For_StageLayer_Window_Func():
    if cmds.window("FURC_USD_Layout_Add_PrimXformReference_For_StageLayer_Window",exists=True):
        cmds.deleteUI("FURC_USD_Layout_Add_PrimXformReference_For_StageLayer_Window")
    createWindow()



FURC_USD_Layout_Add_PrimXformReference_For_StageLayer_Window_Func()

[maya]maya_usd で選択したstageのLayerにPrimXformを追加する、同じ名前がある場合は別の名前で追加

Add a prim to the layer of the stage selected with maya_usd. It has the same name but is added with a different name.

print("add_primxform_for_stage_layer")

import maya.cmds as cmds
from maya import cmds
import mayaUsd.ufe
from pxr import Usd, UsdGeom

def get_stage(stagePath):
    import mayaUsd.ufe
    stage = mayaUsd.ufe.getStage(stagePath)
    print("stage= "+str(stage))
    # レイヤーを取得
    layer = stage.GetRootLayer()
    print("layer= "+str(layer))
    return stage


    
def get_selected_maya_usd_stage():
    selectedlist=cmds.ls(sl=True,long=1)
    print("selectedlist= "+str(selectedlist))
    selectedZero=selectedlist[0]
    selectedZeroType=cmds.objectType( selectedZero )
    print("selectedZeroType= "+str(selectedZeroType))
    usd_stage=""
    stagePath=""
    if(str(selectedZeroType)=="mayaUsdProxyShape"):
        layerPath=selectedZero
        usd_stage=get_stage(layerPath)
    elif(str(selectedZeroType)=="transform"):
        layerPath="|stage"+stageNumStr+"|stageShape"+stageNumStr
        cmds.select(layerPath)
        usd_stage=get_stage(layerPath)
    else:
        print("not stage!!!!")
    return usd_stage,layerPath

def Exist_Prim(prim_path):
    from maya import cmds
    from mayaUsd import ufe, lib
    from pxr import Sdf
    # Primが存在するかどうかを確認
    #primPath = Sdf.Path('/path/to/your/prim')
    primPath = Sdf.Path(prim_path)
    primExist = stage.GetPrimAtPath(primPath)
    if primExist:
        print('Primが存在します')
    else:
        print('Primが存在しません')
    return primExist

def usd_increment_name(name,existing_names):
    new_name = name
    i = 1
    # in演算子 new_name が existing_names に存在する場合はTrueを、そうでない場合はFalseを返します。
    while new_name in existing_names:
        new_name = name+str(i)
        print("存在します。"+str(new_name))
        i += 1
       
    else:
        print("while out")
    return new_name  

print("----start-----")
def add_prim_xform_for_stage_layer():

    stage,layerPath = get_selected_maya_usd_stage()
    
    # レイヤーを取得
    layer = stage.GetRootLayer()
    print("layer= "+str(layer))
    
    # Primを作成
    prim_count=1
    prim_path = "/Xform"+str(prim_count)
    newPrimStagePath=layerPath+","+prim_path
    print("newPrimStagePath= "+newPrimStagePath)

    Exist_Prim(newPrimStagePath)

    # レイヤー内のすべてのPrimを取得
    all_prims = stage.Traverse()
    print("all_prims= "+str(all_prims))
    # Primのリストを出力
    
    all_primName_list=[]
    for prim in all_prims:
        print(prim.GetPath())
        all_primName_list.append(str(prim.GetPath()))
    print("all_primName_list= "+str(all_primName_list))
    
    
    newPrim_path=usd_increment_name("/Xform",all_primName_list)
    print("newPrim_path= "+newPrim_path)
    
    # Primを作成
    prim = UsdGeom.Xform.Define(stage, newPrim_path)
    
    # レイヤーにPrimを追加
    #layer.GetPrimAtPath(newPrim_path)
    
    print("Primが追加されました:", prim.GetPath())


add_prim_xform_for_stage_layer()

[maya]maya_usdでシーンにある選択したステージをmaya_usd apiのstageとして取得するには?

How to get the selected stage in the scene in maya_usd as the stage in maya_usd api?

import maya.cmds as cmds

def get_stage(stagePath):
    import mayaUsd.ufe
    #stagePath="|stage1|stageShape1"
    #stage = mayaUsd.ufe.getStage("|stage1|stageShape1")
    stage = mayaUsd.ufe.getStage(stagePath)
    print("stage= "+str(stage))
    # レイヤーを取得
    layer = stage.GetRootLayer()
    print("layer= "+str(layer))

def get_selected_maya_usd_stage():
    selectedlist=cmds.ls(sl=True,long=1)
    print("selectedlist= "+str(selectedlist))
    selectedZero=selectedlist[0]
    selectedZeroType=cmds.objectType( selectedZero )
    print("selectedZeroType= "+str(selectedZeroType))
    
    stagePath=""
    if(str(selectedZeroType)=="mayaUsdProxyShape"):
        stagePath=selectedZero
        get_stage(stagePath)
    elif(str(selectedZeroType)=="transform"):
        stagePath="|stage"+stageNumStr+"|stageShape"+stageNumStr
        get_stage(stagePath)
    else:
        print("not stage!!!!")
        
get_selected_maya_usd_stage()

OUTPUT

selectedlist= ['|stage5']
selectedZeroType= transform
stage= Usd.Stage.Open(rootLayer=Sdf.Find('anon:000002B5C8EA5570:anonymousLayer1'), sessionLayer=Sdf.Find('anon:000002B5C8EA5870:anonymousLayer1-session.usda'), pathResolverContext=Ar.DefaultResolverContext())
layer= Sdf.Find('anon:000002B5C8EA5570:anonymousLayer1')

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

selectedlist= ['|stage5|stageShape5']
selectedZeroType= mayaUsdProxyShape
stage= Usd.Stage.Open(rootLayer=Sdf.Find('anon:000002B5C84B1070:anonymousLayer1'), sessionLayer=Sdf.Find('anon:000002B5C84B1670:anonymousLayer1-session.usda'), pathResolverContext=Ar.DefaultResolverContext())
layer= Sdf.Find('anon:000002B5C84B1070:anonymousLayer1')

参考URL
https://github.com/Autodesk/maya-usd/issues/1046

[maya] maya_usdのAPIで 「mel mayaUsdCreateStageWithNewLayer」で作ったsceneの中のレイヤーをpythonで取得するには?

How to get the layer in the scene created with “mel mayaUsdCreateStageWithNewLayer” using python with maya_usd API?



# maya_usdのAPIで 「mayaUsdCreateStageWithNewLayer」で作ったsceneの中のレイヤーを取得するには?
print("--------------------get_layers_in_scene -----------------------")

# トップノードだけを検索、意外と使う。
TopNode_01_list=cmds.ls(assemblies=1)
print("TopNode_01_list= "+str(TopNode_01_list))

# mewl で mayaUsdCreateStageWithNewLayer を呼ぶ。
import maya.mel as mel
mel.eval("$StageWithNewLayer=`mayaUsdCreateStageWithNewLayer`")


# トップノードだけを検索、意外と使う。
TopNode_02_list=cmds.ls(assemblies=1)
print("TopNode_02_list= "+str(TopNode_02_list))
# 差分を比較
TopNode_02_set = set(TopNode_02_list)
TopNode_01_set = set(TopNode_01_list)
print("TopNode_01_set= "+str(TopNode_01_set))
print("TopNode_02_set= "+str(TopNode_02_set))

TopNode_diff_set = TopNode_02_set - TopNode_01_set
print("TopNode_diff_set= "+str(TopNode_diff_set))
TopNode_diff_list = list(TopNode_diff_set)
print("TopNode_diff_list= "+str(TopNode_diff_list))
TopNode_new_diff_str=TopNode_diff_list[0]
print("TopNode_new_diff_str= "+str(TopNode_new_diff_str))
# stage1の番号抽出
stageNumStr=TopNode_new_diff_str[5:]
print("stageNumStr="+stageNumStr)
#-------------------------------------------------------

import mayaUsd.ufe
stagePath="|stage"+stageNumStr+"|stageShape"+stageNumStr
#stagePath="|stage1|stageShape1"
#stage = mayaUsd.ufe.getStage("|stage1|stageShape1")
stage = mayaUsd.ufe.getStage(stagePath)
print("stage= "+str(stage))
# レイヤーを取得
layer = stage.GetRootLayer()
print("layer= "+str(layer))

Output

--------------------get_layers_in_scene -----------------------
TopNode_01_list= ['persp', 'top', 'front', 'side']
TopNode_02_list= ['persp', 'top', 'front', 'side', 'stage1']
TopNode_01_set= {'front', 'side', 'persp', 'top'}
TopNode_02_set= {'persp', 'stage1', 'top', 'front', 'side'}
TopNode_diff_set= {'stage1'}
TopNode_diff_list= ['stage1']
TopNode_new_diff_str= stage1
stageNumStr=1
stage= Usd.Stage.Open(rootLayer=Sdf.Find('anon:000002B5C8D87560:anonymousLayer1'), sessionLayer=Sdf.Find('anon:000002B5C8D87160:anonymousLayer1-session.usda'), pathResolverContext=Ar.DefaultResolverContext())
layer= Sdf.Find('anon:000002B5C8D87560:anonymousLayer1')

maya-usd の github Version 0.25.0 をCMakeビルドしてみたい。という勉強。

まずビルドに必要なページはこれだ

https://github.com/Autodesk/maya-usd/blob/dev/doc/build.md

ビルド

コードの取得と構築

プロジェクトをビルドする最も簡単な方法は、提供されているbuild.pyスクリプトを実行することです。このスクリプトはプロジェクトをビルドし、必要なライブラリとプラグインをすべてインストールします。スクリプトの使用方法については、以下の手順に従ってください。

1. ツールとシステムの前提条件

プロジェクトをビルドする前に、次の表を参照して、コンパイラ、オペレーティング システム、cmake などの推奨バージョンを使用していることを確認してください。

必須WindowsMacLinax
オペレーティング·システムWindows 10/11ハイシエラ (10.13)
モハーベ (10.14)
カタリナ (10.15)
ビッグサー (11.2.x)
モントレー (12.6)
CentOS 7/8
RHEL 8.6
Rocky 8.6
コンパイラの要件Maya 2022 (VS 2017/2019)
Maya 2023 (VS 2019)
Maya 2024 (VS 2022)
Maya 2022 (Xcode 10.2.1)
Maya 2023 (Xcode 10.2.1)
Maya 2024 (Xcode 13.4)
Maya 2022 (gcc 6.3.1/9.3.1)
Maya 2023 (gcc 9.3.1)
Maya 2024 (gcc 11.2.1)
CMake バージョン (最小/最大)3.13 – 3.173.13 – 3.173.13 – 3.17
パイソン2.7.15 または 3.7.7 または 3.9.72.7.15 または 3.7.7 または 3.9.72.7.15 または 3.7.7 または 3.9.7
Python パッケージPyYAML、PySide、PyOpenGL、Jinja2PyYAML、PySide2、PyOpenGL、Jinja2PyYAML、PySide、PyOpenGL、Jinja2
ビルドジェネレーターVisual Studio、Ninja (推奨)XCode、Ninja (推奨)忍者(推奨)
コマンドプロセッサVisual Studio X64 {2017/2019/2022} コマンド プロンプトバッシュバッシュ
サポートされている Maya バージョン2022年、2023年、2024年2022年、2023年、2024年2022年、2023年、2024年

visual StudioのCMakeはインストールされているようだ。

https://learn.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=msvc-170

ところがNinjyaが推奨なので

CMake 3.17.0には、新しいNinjaスクリプトジェネレーター、拡張機能などが付属しています。

https://cmake.org/cmake/help/v3.17/generator/Ninja%20Multi-Config.html#generator:Ninja%20Multi-Config

https://github.com/Kitware/CMake/releases?page=14

https://github.com/Kitware/CMake/releases/download/v3.17.0/cmake-3.17.0-win64-x64.msi

C:\Program Files\CMake\

https://github.com/Kitware/CMake/releases/download/v3.17.0/cmake-3.17.0-win64-x64.zip

をダウンロードする。環境変数はこうだが

E:\ViewOf_maya_usd\cmake-3.17.0-win64-x64\cmake-3.17.0-win64-x64\bin

Python 2.7.15

https://www.python.org/ftp/python/2.7.15/python-2.7.15.amd64.msi

C:\Python27
でパスを通した。

Pythonは3.7.7

https://www.python.org/ftp/python/3.7.7/python-3.7.7-embed-amd64.zip

でパスを通した。

オプションWindowsMacLinax
QtMaya 2022 = 5.15.2
Maya 2023
= 5.15.2 Maya 2024 = 5.15.2
Maya 2022 = 5.15.2
Maya 2023
= 5.15.2 Maya 2024 = 5.15.2
Maya 2022 = 5.15.2
Maya 2023
= 5.15.2 Maya 2024 = 5.15.2

注:さまざまなプラットフォームでの追加のコンパイラ要件については、オンラインの Maya 開発者ヘルプ ドキュメントの「ビルド環境のセットアップ」にアクセスしてください。

2. Pixar USD をダウンロードして構築する

USD の構築方法については、Pixar の公式 github ページ ( https://github.com/PixarAnimationStudios/USD ) を参照してください。Pixar は、Github リポジトリおよび で Maya USD ライブラリ/プラグインを構築するためのサポートを削除しましたbuild_usd.pyPixar USDMaya-usd プロジェクトをビルドするときは、以下の表の推奨コミット ID またはタグを使用することが重要です。

PIXERMaya で使用される USD バージョン
コミットID/タグリリース: v21.11またはv22.05bまたはv22.08またはv22.11
またはv23.02またはv23.08
開発: 10b6243 (タグ v23.08)
Maya 2022 = v21.11
Maya 2023 =v21.11
Maya 2024 = v22.11

Maya 2023 =v21.11 なので

https://github.com/PixarAnimationStudios/OpenUSD/archive/refs/tags/v21.11.zip

Pixar USD の構築に関する追加情報については、以下の「追加の構築手順」セクションを参照してください。

注:PATH環境に古い USD の場所がないことを確認してくださいPYTHONPATH。正しい USD の場所を指すようにプロジェクト内で自動的に調整されますPATHPYTHONPATH見るcmake/usd.cmake

3. ユニバーサルフロントエンド (UFE)

ユニバーサル フロント エンド (UFE) は、Maya が複数のデータ モデルのデータを参照および編集できるようにする DCC に依存しないコンポーネントです。これにより、Maya は USD などのパイプライン データを編集できるようになります。UFE は、Maya 2019 以降に組み込みコンポーネントとしてインストールされます。UFE は別個のバイナリ コンポーネントとして開発されるため、Maya とは別にバージョン管理されます。

ユーフェバージョンマヤバージョンUfe ドキュメント (社外)
v1.0.0マヤ 2019.x
v1.0.0マヤ 2020.x
v2.0.0
v2.0.3
v2.1.0
Maya 2022
Maya 2022.1/2022.2/2022.3
Maya 2022.4
https://help.autodesk.com/view/MAYAUL/2022/ENU/?guid=Maya_SDK_ufe_ref_index_html
v3.0.0
v3.2.0
v3.3.0
Maya 2023/2023.1
Maya 2023.2
Maya 2023.3
https://help.autodesk.com/view/MAYAUL/2023/ENU/?guid=MAYA_API_REF_ufe_ref_index_html
v4.0.0
v4.1.0
Maya 2024
Maya 2024.1
https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=MAYA_API_REF_ufe_ref_index_html
v0.5.xマヤ広報

UFE サポートを使用してプロジェクトをビルドするには、 Maya Devkitに含まれるヘッダーとライブラリを使用する必要があります。

https://www.autodesk.com/developer-network/platform-technologies/maya

注: UFE は Maya 2019 以降でのみサポートされています。

https://qiita.com/aizwellenstan/items/31a6e62aaad7fd234c34

によると こうだが

set PACKAGE_PATH=C:\Autodesk_Maya_2023_3_Update_DEVKIT_Windows\devkitBase

set VS_VERSION=2022
set CMAKE_PATH=C:\Program Files\Microsoft Visual Studio\%VS_VERSION%\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin

setx PATH "%PACKAGE_PATH%;%CMAKE_PATH%;%PATH%" /M

gitがないって言われたので64-bit Git for Windows Portable.

https://github.com/git-for-windows/git/releases/download/v2.43.0.windows.1/PortableGit-2.43.0-64-bit.7z.exe <<自動解凍式

set gitDir=E:\ViewOf_maya_usd\PortableGit\bin

にパスを通した。

今回はこうだった install_devkit_setenv.bat

set PACKAGE_PATH=E:\ViewOf_maya_usd\Autodesk_Maya_2023_3_Update_DEVKIT_Windows\devkitBase

set VS_VERSION=2022
::set CMAKE_PATH=C:\Program Files\Microsoft Visual Studio\%VS_VERSION%\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin
set CMAKE_PATH=C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin

::set MAYA_EXECUTABLE=C:\Program Files\Autodesk\Maya2023\bin\maya.exe
set MAYA_EXECUTABLE=C:\Program Files\Autodesk\Maya2023\bin\mayabatch.exe
set MAYA_PY_EXECUTABLE=C:\Program Files\Autodesk\Maya2023\bin\mayapy.exe
set MayaBinDir=C:\Program Files\Autodesk\Maya2023\bin
set pythonDir=E:\ViewOf_maya_usd\python-3.7.7-embed-amd64
set gitDir=E:\ViewOf_maya_usd\PortableGit\bin
set CMakeDir=E:\ViewOf_maya_usd\cmake-3.17.0-win64-x64\cmake-3.17.0-win64-x64\bin
set MAYA_DEVKIT_INC_DIR=E:\ViewOf_maya_usd\Autodesk_Maya_2023_3_Update_DEVKIT_Windows\devkitBase\devkit\Alembic\include
set MAYA_IMFbase_LIBRARY=E:\ViewOf_maya_usd\Autodesk_Maya_2023_3_Update_DEVKIT_Windows\devkitBase\lib\adskIMF.lib
set OpenUSD_Dir=E:\ViewOf_maya_usd\OpenUSD-21.11\OpenUSD-21.11
::setx PATH "%PACKAGE_PATH%;%CMAKE_PATH%;%PATH%" /M
setx PATH "%PACKAGE_PATH%;%CMAKE_PATH%;%MAYA_EXECUTABLE%;%MAYA_PY_EXECUTABLE%;%MayaBinDir%;%python27Dir%;%python37Dir%;%gitDir%;%CMakeDir%;%MAYA_DEVKIT_INC_DIR%;%MAYA_IMFbase_LIBRARY%;%OpenUSD_Dir%;%PATH%" /M



でこの install_devkit_setenv.bat を管理者として実行した。

現時点でのログはこうだ。

1> CMake generation started for default configuration: 'x64-Debug'.
1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "c:\program files\microsoft visual studio\2022\professional\common7\ide\commonextensions\microsoft\cmake\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="E:\ViewOf_maya_usd\VS2019_Rep\maya_usd\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe"   -DCMAKE_MAKE_PROGRAM="c:\program files\microsoft visual studio\2022\professional\common7\ide\commonextensions\microsoft\cmake\Ninja\ninja.exe" "E:\ViewOf_maya_usd\VS2019_Rep\maya_usd" 2>&1"
1> Working directory: E:\ViewOf_maya_usd\VS2019_Rep\maya_usd\out\build\x64-Debug
1> [CMake] -- Using Maya Light API Version 3
1> [CMake] -- Maya has setDefaultMaterialHandling API
1> [CMake] -- Maya has new point snapping API
1> [CMake] -- Maya has getCurrentUfeCameraPath
1> [CMake] -- Maya has isInCrashHandler API
1> [CMake] -- Maya has setUfeIdentifiers API
1> [CMake] -- Maya has updateUfeIdentifiers API
1> [CMake] -- Maya has getDisplayStyleOfAllViewports API
1> [CMake] -- Maya array iterator has difference_type trait
1> [CMake] -- MFnSet has getMemberPaths function
1> [CMake] -- MFnDisplayLayer exists
1> [CMake] -- MDisplayLayerMessage has MDisplayLayerMemberChangedFunction
1> [CMake] -- MRenderItem has HideOnPlayback API
1> [CMake] -- Maya has UFE gizmo drawing
1> [CMake] -- Found Python: C:/Python27/python.exe (found suitable exact version "2.7.15") found components: Interpreter 
1> [CMake] -- _PYTHON_VERSION_LIST: 2.7.15.final.0
1> [CMake] -- PYTHON_PREFIX: C:\Python27
1> [CMake] -- PYTHON_INCLUDE_DIR: C:\Python27\include
1> [CMake] -- PYTHON_SITE_PACKAGES: C:\Python27\Lib\site-packages
1> [CMake] -- PYTHON_MODULE_EXTENSION: .pyd
1> [CMake] -- PYTHON_IS_DEBUG: 0
1> [CMake] -- PYTHON_SIZEOF_VOID_P: 8
1> [CMake] -- PYTHON_LIBRARY_SUFFIX: 27
1> [CMake] -- PYTHON_MULTIARCH: 
1> [CMake] -- PYTHON_LIBDIR: C://lib
1> [CMake] -- Found PythonLibs: C:/Python27/libs/Python27.lib
1> [CMake] -- Build MayaUSD with Python3 = OFF
1> [CMake] --    PYTHON_INCLUDE_DIRS = C:/Python27/include
1> [CMake] --    PYTHON_LIBRARIES    = C:/Python27/libs/Python27.lib
1> [CMake] --    Python_EXECUTABLE   = C:/Python27/python.exe
1> [CMake] CMake Error at cmake/jinja.cmake:27 (message):
1> [CMake]   MARKUPSAFE_LOCATION not set
1> [CMake] Call Stack (most recent call first):
1> [CMake]   cmake/jinja.cmake:55 (init_markupsafe)
1> [CMake]   CMakeLists.txt:118 (include)
1> [CMake] -- Configuring incomplete, errors occurred!
1> 'C:\WINDOWS\system32\cmd.exe' 
'/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && 
"c:\program files\microsoft visual studio\2022\professional\common7\ide\commonextensions\microsoft\cmake\CMake\bin\cmake.exe"  
-G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" 
-DCMAKE_INSTALL_PREFIX:PATH="E:\ViewOf_maya_usd\VS2019_Rep\maya_usd\out\install\x64-Debug" 
-DCMAKE_C_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe" 
-DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe"   
-DCMAKE_MAKE_PROGRAM="c:\program files\microsoft visual studio\2022\professional\common7\ide\commonextensions\microsoft\cmake\Ninja\ninja.exe" 
"E:\ViewOf_maya_usd\VS2019_Rep\maya_usd" 2>&1"' execution failed with error: 
''C:\WINDOWS\system32\cmd.exe' 
'/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && 
"c:\program files\microsoft visual studio\2022\professional\common7\ide\commonextensions\microsoft\cmake\CMake\bin\cmake.exe"  
-G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="E:\ViewOf_maya_usd\VS2019_Rep\maya_usd\out\install\x64-Debug" 
-DCMAKE_C_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe" 
-DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe"   
-DCMAKE_MAKE_PROGRAM="c:\program files\microsoft visual studio\2022\professional\common7\ide\commonextensions\microsoft\cmake\Ninja\ninja.exe" 
"E:\ViewOf_maya_usd\VS2019_Rep\maya_usd" 2>&1"' returned with exit code: 1'.

でいいみたい

Mayaのパスは実行時に渡すみたい

E:\ViewOf_maya_usd\VS2019_Rep\maya_usd\build_mybat.bat で実行

python build.py --maya-location "C:\Program Files\Autodesk\Maya2023" --pxrusd-location E:\ViewOf_maya_usd\OpenUSD-23.08\OpenUSD-23.08 --devkit-location E:\ViewOf_maya_usd\Autodesk_Maya_2023_3_Update_DEVKIT_Windows\devkitBase E:\ViewOf_maya_usd\workspace

cmd /k
E:\ViewOf_maya_usd\VS2019_Rep\maya_usd> .\build_mybat.bat

こうでもなかった

Ninja推奨なので

cmake-gui.exeでやる。

でもこんなエラー MARKUPSAFE_LOCATION not set

Build MayaUSD with Python3 = OFF
   PYTHON_INCLUDE_DIRS = C:/Python27/include
   PYTHON_LIBRARIES    = C:/Python27/libs/Python27.lib
   Python_EXECUTABLE   = C:/Python27/python.exe
CMake Error at cmake/jinja.cmake:27 (message):
  MARKUPSAFE_LOCATION not set
Call Stack (most recent call first):
  cmake/jinja.cmake:55 (init_markupsafe)
  CMakeLists.txt:118 (include)

だからこう  参考>>https://github.com/Autodesk/maya-usd/issues/733

PS  C:\Python27> python -m pip install MarkupSafe
PS C:\Python27> python -m pip install jinja2 MarkupSafe
PS C:\Python27> python -m pip install jinja MarkupSafe

次のエラーは

USD_CONFIG_FILENOTFOUND

CMake Error at cmake/modules/FindUSD.cmake:49 (include):
  include could not find load file:

    USD_CONFIG_FILE-NOTFOUND
Call Stack (most recent call first):
  CMakeLists.txt:121 (find_package)


CMake Error at cmake/modules/FindUSD.cmake:52 (message):
  Expected PXR_VERSION defined in pxrConfig.cmake
Call Stack (most recent call first):
  CMakeLists.txt:121 (find_package)

E:\ViewOf_maya_usd\VS2019_Rep\maya_usd\plugin\pxr に

E:\ViewOf_maya_usd\OpenUSD-21.11\OpenUSD-21.11\pxr を 上書き

したらエラー変わった。

CMake Error at plugin/pxr/pxrConfig.cmake:19 (include):
  include could not find load file:

    E:/ViewOf_maya_usd/VS2019_Rep/maya_usd/plugin/pxr/cmake/pxrTargets.cmake
Call Stack (most recent call first):
  cmake/modules/FindUSD.cmake:49 (include)
  CMakeLists.txt:121 (find_package)


CMake Error at plugin/pxr/pxrConfig.cmake:25 (get_target_property):
  get_target_property() called with non-existent target "@PXR_ALL_LIBS@".
Call Stack (most recent call first):
  cmake/modules/FindUSD.cmake:49 (include)
  CMakeLists.txt:121 (find_package)


CMake Error at C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
  Could NOT find USD: Found unsuitable version
  "@PXR_MAJOR_VERSION@.@PXR_MINOR_VERSION@.@PXR_PATCH_VERSION@", but required
  is at least "0.21.11" (found
  E:/ViewOf_maya_usd/VS2019_Rep/maya_usd/plugin/pxr)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:443 (_FPHSA_FAILURE_MESSAGE)
  cmake/modules/FindUSD.cmake:148 (find_package_handle_standard_args)
  CMakeLists.txt:121 (find_package)

2023年から2024年になった。

依存関係が多すぎる事に足を突っ込んだ事に気が付いたので。止めようと思う。

https://github.com/PixarAnimationStudios/OpenUSD/issues/530

いや、そのコミットは実際にはビルドを完全に破壊します。偶然押し込まれたのです。
先ほども述べたように、pxr ビルド システムは非常に複雑であり、それを 1 つの小さな変更で修正する試みでした。うまくいきませんでした。

うまくいかないが、以下まんま本文続き

リポジトリのレイアウト
位置説明
ライブラリ他のすべてのプラグインが依存するライブラリ。一般的なユーティリティと機能が含まれます。
プラグイン/adskAutodesk Maya プラグイン
プラグイン/pxrPixar Maya プラグイン
プラグイン/アルAnimal Logic Maya プラグイン

5. build.py スクリプトの使用方法

引数

スクリプトに渡す必要がある引数は 4 つあります。

フラグ説明
–マヤの場所Maya がインストールされているディレクトリ。
–pxrusd-場所Pixar USD Core がインストールされているディレクトリ。
–devkit-場所Maya 開発キットがインストールされているディレクトリ。
ワークスペースの場所プロジェクトがプラグイン/ライブラリをビルドおよびインストールするためのワークスペースとして使用するディレクトリ
デフォルトのビルド引数
フラグ説明
–マテリアルxMaterialX 機能を有効にしてビルドする
オプションのビルド引数
フラグ説明
–build-argscmake 変数のカンマ区切りリストをビルド システムに渡すこともできます。
–no-materialxMayaUSD でマテリアル X サポートを構築しないでください。
--build-args="-DBUILD_ADSK_PLUGIN=ON,-DBUILD_PXR_PLUGIN=OFF,-DBUILD_TESTS=OFF"
CMake オプション
名前説明デフォルト
BUILD_MAYAUSD_LIBRARYコア USD ライブラリを構築します。の上
BUILD_ADSK_PLUGINAutodesk USD プラグインを構築します。の上
BUILD_PXR_PLUGINPixar USD プラグインとライブラリを構築します。の上
ビルド_AL_プラグインAnimal Logic USD プラグインとライブラリを構築します。の上
BUILD_HDMAYA従来の Maya-To-Hydra プラグインとシーン デリゲートを構築します。オフ
BUILD_RFM_TRANSLATORSRenderMan for Maya シェーダのトランスレータを構築します。の上
ビルド_テストすべての単体テストをビルドします。の上
ビルド_ストリクト_モードすべての警告をエラーとして強制します。の上
BUILD_WITH_PYTHON_3Python3でビルドします。オフ
BUILD_SHARED_LIBSライブラリを共有または静的としてビルドします。の上
ビルド_UB2ユニバーサル バイナリ 2 (UB2) Intel64+arm64 をビルド (Apple のみ)オフ
CMAKE_WANT_MATERIALX_BUILDMaterialX を使用した構築を有効にします (実験的)。オフ
ステージ
フラグ説明
–段階ステージのカンマ区切りリストをビルド システムに渡すこともできます。この引数が設定されていない場合、デフォルトでは「クリーン、構成、ビルド、インストール」ステージが実行されます。
オプション説明
クリーンクリーンビルド
構成、設定cmake ファイルが変更されるたびにこのステージを呼び出します
建てるプロジェクトをビルドします
インストール必要なプラグインとライブラリをすべてインストールします
テストすべての (PXR、AL、UFE) 単体テストを実行します
パッケージすべてのインストール ファイルをパッケージ ディレクトリ内の zip ファイルとしてバンドルします。
Examples:
--stages=configure,build,install
--stages=test

注:すべてのフラグの後に、spaceまたは=

CMakeジェネレーター

CMake Generator を選択するのはユーザー次第ですが、Ninja ジェネレーターの使用をお勧めします。Ninja Generator を使用するには、まずhttps://ninja-build.org/から Ninja バイナリをインストールする必要があります。

次に、ジェネレーターをダウンロードした Ninja バイナリに設定しNinjaCMAKE_MAKE_PROGRAM変数を Ninja バイナリに設定する必要があります。

python build.py --generator Ninja --build-args=-DCMAKE_MAKE_PROGRAM='path to ninja binary'
ビルドとインストールの場所

デフォルトでは、ビルド ディレクトリとインストール ディレクトリはワークスペースディレクトリ内に作成されます。--build-locationただし、およびフラグを設定することで、これらの場所を変更できます--install-location

ビルドログ

デフォルトでは、ビルド ログはbuild_log.txtビルド ディレクトリ内に書き込まれます。代わりに出力ストリームをコンソールにリダイレクトしたい場合は、--redirect-outstream-fileこれを渡して false に設定します。

追加のフラグとオプション

パラメーターを指定してスクリプトを実行すると、--help考えられるすべてのフラグと短い説明が表示されます。

6. 単体テストの実行方法

単体テストは、設定するか、ビルド ディレクトリから直接--stages=test呼び出すことで実行できます。ctest

たとえば、コマンドラインからすべての Animal Logic のテストを実行するには、 に移動してbuild/<variant>/plugin/alを呼び出しますctest

➜  ctest -j 8
Test project /Users/sabrih/Desktop/workspace/build/Debug/plugin/al
    Start 4: AL_USDMayaTestPlugin
    Start 5: TestUSDMayaPython
    Start 8: TestPxrUsdTranslators
    Start 7: TestAdditionalTranslators
    Start 1: AL_MayaUtilsTests
    Start 3: Python:AL_USDTransactionTests
    Start 2: GTest:AL_USDTransactionTests
    Start 6: testMayaSchemas
1/8 Test #2: GTest:AL_USDTransactionTests .....   Passed    0.06 sec
2/8 Test #6: testMayaSchemas ..................   Passed    0.10 sec
3/8 Test #3: Python:AL_USDTransactionTests ....   Passed    0.73 sec
4/8 Test #1: AL_MayaUtilsTests ................   Passed    6.01 sec
5/8 Test #8: TestPxrUsdTranslators ............   Passed    9.96 sec
6/8 Test #5: TestUSDMayaPython ................   Passed   10.28 sec
7/8 Test #7: TestAdditionalTranslators ........   Passed   12.06 sec
8/8 Test #4: AL_USDMayaTestPlugin .............   Passed   27.43 sec
100% tests passed, 0 tests failed out of 8

追加のビルド手順

パイソン:

MacOS で USD をビルドする場合は、システム バージョンではなく、Maya に付属の Python バージョンを使用することが重要です。これは主に MacOS での問題であり、Maya の Python バージョンがシステムによって提供されるバージョンと競合する可能性があることに注意してください。

MacOS 上で Maya (2022、2023、2024) 用の USD と Maya プラグインをビルドするには、次のコマンドを実行します。

/Applications/Autodesk/maya2024/Maya.app/Contents/bin/mayapy build_usd.py ~/Desktop/BUILD

デフォルトでは、usdviewPyOpenGL に依存するようにビルドされます。Maya の Python バージョンには PyOpenGL が同梱されていないため、次のエラー メッセージが表示されます。

PyOpenGL is not installed. If you have pip installed, run "pip install PyOpenGL" to install it, then re-run this script.
If PyOpenGL is already installed, you may need to update your ```PYTHONPATH``` to indicate where it is located.

このエラーを回避する最も簡単な方法は、PYTHONPATHシステムの Python または PyOpenGL が既にインストールされているサードパーティの Python パッケージ マネージャーを指すように設定することです。例えば

export PYTHONPATH=$PYTHONPATH:Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

pip listPython のパッケージ マネージャーでインストールされているパッケージのリストを確認するために使用します。

例えば

➜ pip list
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Package    Version
---------- -------
Jinja2     2.10   
MarkupSafe 1.1.0  
pip        19.1.1 
PyOpenGL   3.1.0  
PySide2    5.12.1 
PyYAML     3.13   
setuptools 39.0.1 
shiboken2  5.12.1 
テスト実行時の Linux DSO への依存関係

通常、このライブラリ内の一部の DSO では runpath または rpath のいずれかが使用され、他のライブラリ (USD 自体など) で明示的に指定されます。

何らかの理由でこれらのオプションのいずれも使用したくない場合は、次のようにしてオフに切り替えます。

CMAKE_SKIP_RPATH=TRUE

テストを実行できるようにするには、ADDITIONAL_LD_LIBRARY_PATH cmake 変数を $ENV{LD_LIBRARY_PATH} などに設定することで、MayaUSD_add_test 呼び出しのいずれかに LD_LIBRARY_PATH を挿入できます。

スキーマが標準以外の場所にインストールされている場合に使用できる、関連する ADDITIONAL_PXR_PLUGINPATH_NAME cmake var があります。

開発ツールセット-6:

CentOS 上の GCC 6 を含む Devtoolset-6 はメイン リポジトリから廃止され、ボールトに移動されました。CentOS に devtoolset-6 をインストールするには、以下の手順に従ってください。

# download the packages, install may fail with "no public key found"
sudo yum-config-manager --add-repo=http://vault.centos.org/7.6.1810/sclo/x86_64/rh/

# to fix "no public key found"
cd /etc/pki/rpm-gpg
ls # confirm RPM-GPG-KEY-CentOS-SIG-SCLo exists
sudo rpm --import RPM-GPG-KEY-CentOS-SIG-SCLo
rpm -qa gpg* # confirm key with substring f2ee9d55 exists

# to install devtoolset-6
sudo yum install devtoolset-6

# disable the vault after successful install
sudo yum-config-manager --disable vault.centos.org_7.6.1810_sclo_x86_64_rh_

Maya にプラグインをロードする方法

提供されているモジュール ファイル (*.mod) を使用すると、プラグインやライブラリのさまざまな環境変数を簡単に設定できます。プロジェクトが正常にビルドされたら、mayaUsd.mod/alUSD.mod/pxrUSD.modインストール ディレクトリ内にインストールされます。Maya がこれらの MOD ファイルを検出するには、MAYA_MODULE_PATHMOD ファイルがインストールされている場所を指すように環境変数を設定する必要があります。例:

set MAYA_MODULE_PATH=C:\workspace\install\RelWithDebInfo
export MAYA_MODULE_PATH=/usr/local/workspace/install/RelWithDebInfo

MAYA_MODULE_PATH が設定されたら、Maya を実行し、Windows -> Setting/Preferences -> Plug-in Managerプラグインをロードします。