{"id":22484,"date":"2025-11-02T10:47:52","date_gmt":"2025-11-02T02:47:52","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=22484"},"modified":"2025-11-02T18:38:55","modified_gmt":"2025-11-02T10:38:55","slug":"siemens-nx%ef%bc%88ug%ef%bc%89-python-%e5%bc%80%e5%8f%91-%e8%8e%b7%e5%8f%96%e5%9f%ba%e6%9c%ac%e7%8e%af%e5%a2%83%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=22484","title":{"rendered":"Siemens NX\uff08UG\uff09 Python \u5f00\u53d1 &#8211; \u83b7\u53d6\u57fa\u672c\u73af\u5883\u4fe1\u606f"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title ez-toc-toggle\" style=\"cursor:pointer\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.iyatt.com\/?p=22484\/#%E7%8E%AF%E5%A2%83\" >\u73af\u5883<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.iyatt.com\/?p=22484\/#NX%E7%89%88%E6%9C%AC%E3%80%81Python%E7%89%88%E6%9C%AC%E3%80%81Python%E8%A7%A3%E9%87%8A%E5%99%A8%E8%B7%AF%E5%BE%84%E3%80%81Python%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%B7%AF%E5%BE%84\" >NX\u7248\u672c\u3001Python\u7248\u672c\u3001Python\u89e3\u91ca\u5668\u8def\u5f84\u3001Python\u73af\u5883\u53d8\u91cf\u8def\u5f84<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.iyatt.com\/?p=22484\/#%E5%B7%B2%E5%AE%89%E8%A3%85%E5%8C%85%E5%90%8D\" >\u5df2\u5b89\u88c5\u5305\u540d<\/a><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E7%8E%AF%E5%A2%83\"><\/span>\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<ul>\n<li>Windows 11 25H2<\/li>\n<li>NX 2506<\/li>\n<li>\u5185\u7f6e Python 3.12.8<\/li>\n<\/ul>\n<h1><span class=\"ez-toc-section\" id=\"NX%E7%89%88%E6%9C%AC%E3%80%81Python%E7%89%88%E6%9C%AC%E3%80%81Python%E8%A7%A3%E9%87%8A%E5%99%A8%E8%B7%AF%E5%BE%84%E3%80%81Python%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%B7%AF%E5%BE%84\"><\/span>NX\u7248\u672c\u3001Python\u7248\u672c\u3001Python\u89e3\u91ca\u5668\u8def\u5f84\u3001Python\u73af\u5883\u53d8\u91cf\u8def\u5f84<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<pre><code class=\"language-python\">import NXOpen\n\nimport sys\n\ndef main():\n    session = NXOpen.Session.GetSession()\n    lw = session.ListingWindow # \u83b7\u53d6 NX \u7684\u63a7\u5236\u53f0\u8f93\u51fa\u7a97\u53e3\n    lw.Open()\n\n    nxVersion = session.GetEnvironmentVariableValue(&#039;UGII_VERSION&#039;)\n    lw.WriteLine(f&#039;NX \u7248\u672c\uff1a{nxVersion}&#039;)\n\n    lw.WriteLine(f&#039;\\nPython \u7248\u672c\uff1a{sys.version}&#039;)\n    lw.WriteLine(f&#039;Python \u89e3\u91ca\u5668\u8def\u5f84\uff1a{sys.executable}&#039;)\n\n    lw.WriteLine(&#039;\\nPython \u73af\u5883\u53d8\u91cf\u5217\u8868\uff1a&#039;)\n    for p in sys.path:\n        lw.WriteLine(p)\n\nif __name__ == &#039;__main__&#039;:\n    main()<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/11\/image-1762050721290.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 594px; --smush-placeholder-aspect-ratio: 594\/278;\" \/><\/p>\n<h1><span class=\"ez-toc-section\" id=\"%E5%B7%B2%E5%AE%89%E8%A3%85%E5%8C%85%E5%90%8D\"><\/span>\u5df2\u5b89\u88c5\u5305\u540d<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<pre><code class=\"language-python\">import NXOpen\n\nimport pkgutil\n\ndef main():\n    lw = NXOpen.Session.GetSession().ListingWindow\n    lw.Open()\n\n    modules = sorted([mod.name for mod in pkgutil.iter_modules()]) # \u679a\u4e3e\u5df2\u5b89\u88c5\u5305\n\n    lw.WriteLine(f&#039;\u5df2\u5b89\u88c5\u6a21\u5757\u6570\u91cf\uff1a{len(modules)}&#039;)\n    for module in modules:\n        lw.WriteLine(module)\n\nif __name__ == &#039;__main__&#039;:\n    main()<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/11\/image-1762051656611.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 378px; --smush-placeholder-aspect-ratio: 378\/724;\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73af\u5883 Windows 11 25H2 NX 2506 \u5185\u7f6e Python 3.12.8 NX\u7248\u672c\u3001Python [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"_lmt_disableupdate":"no","_lmt_disable":"no","footnotes":""},"categories":[1,618,592,617],"tags":[1829,1824,909,1297,1826,1825],"class_list":["post-22484","post","type-post","status-publish","format-standard","hentry","category-all","category-cad-cam","category-python","category-siemens-nx","tag-journal","tag-nxopen","tag-python","tag-siemens-nx","tag-1826","tag-1825"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/22484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=22484"}],"version-history":[{"count":3,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/22484\/revisions"}],"predecessor-version":[{"id":22511,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/22484\/revisions\/22511"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=22484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=22484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=22484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}