|
58 | 58 | # created for you. |
59 | 59 |
|
60 | 60 | import os |
| 61 | +from pathlib import Path |
61 | 62 |
|
62 | 63 | from ansys.dpf.core import examples |
63 | 64 |
|
64 | | -plugin_path = examples.download_gltf_plugin() |
65 | | -folder_root = os.path.join(os.getcwd().rsplit("pydpf-core", 1)[0], "pydpf-core") |
| 65 | +plugin_path = Path(examples.download_gltf_plugin()) |
| 66 | +folder_root = Path(__file__).parent.parent.parent |
66 | 67 |
|
67 | 68 | # %% |
68 | 69 | # To add third-party modules as dependencies to a plug-in package, you must |
|
83 | 84 | # To simplify this step, you can add a requirements file in the plug-in package: |
84 | 85 | # |
85 | 86 | print("\033[1m gltf_plugin/requirements.txt: \n \033[0m") |
86 | | -with open(os.path.join(plugin_path, "requirements.txt"), "r") as f: |
87 | | - for line in f.readlines(): |
| 87 | +requirements_path = plugin_path / "requirements.txt" |
| 88 | +with requirements_path.open("r") as file: |
| 89 | + for line in file.readlines(): |
88 | 90 | print("\t\t\t" + line) |
89 | 91 |
|
90 | 92 |
|
|
117 | 119 | # |
118 | 120 | # create_sites_for_python_operators.sh -pluginpath /path/to/plugin -zippath /path/to/plugin/assets/linx64.zip # noqa: E501 |
119 | 121 |
|
120 | | - |
121 | | -if os.name == "nt" and not os.path.exists( |
122 | | - os.path.join(plugin_path, "assets", "gltf_sites_winx64.zip") |
123 | | -): |
124 | | - cmd_file = os.path.join( |
125 | | - folder_root, |
126 | | - "doc", |
127 | | - "source", |
128 | | - "user_guide", |
129 | | - "create_sites_for_python_operators.ps1", |
| 122 | +site_path = plugin_path / "assets" / "gltf_sites_winx64.zip" |
| 123 | +if os.name == "nt" and not site_path.exists(): |
| 124 | + cmd_file = ( |
| 125 | + folder_root / "doc" / "source" / "user_guide" / "create_sites_for_python_operators.ps1" |
130 | 126 | ) |
131 | 127 | args = [ |
132 | 128 | "powershell", |
133 | | - cmd_file, |
| 129 | + str(cmd_file), |
134 | 130 | "-pluginpath", |
135 | | - plugin_path, |
| 131 | + str(plugin_path), |
136 | 132 | "-zippath", |
137 | | - os.path.join(plugin_path, "assets", "gltf_sites_winx64.zip"), |
| 133 | + str(plugin_path / "assets" / "gltf_sites_winx64.zip"), |
138 | 134 | ] |
139 | 135 | print(args) |
| 136 | + |
140 | 137 | import subprocess |
141 | 138 |
|
142 | 139 | process = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
150 | 147 | ) |
151 | 148 | else: |
152 | 149 | print("Installing pygltf in a virtual environment succeeded") |
153 | | -elif os.name == "posix" and not os.path.exists( |
154 | | - os.path.join(plugin_path, "assets", "gltf_sites_linx64.zip") |
155 | | -): |
156 | | - cmd_file = os.path.join( |
157 | | - folder_root, |
158 | | - "doc", |
159 | | - "source", |
160 | | - "user_guide", |
161 | | - "create_sites_for_python_operators.sh", |
| 150 | + |
| 151 | +elif os.name == "posix" and not site_path.exists(): |
| 152 | + cmd_file = ( |
| 153 | + folder_root / "doc" / "source" / "user_guide" / "create_sites_for_python_operators.sh" |
162 | 154 | ) |
163 | 155 | run_cmd = f"{cmd_file}" |
164 | 156 | args = ( |
165 | 157 | f' -pluginpath "{plugin_path}" ' |
166 | | - f"-zippath \"{os.path.join(plugin_path, 'assets', 'gltf_sites_linx64.zip')}\"" |
| 158 | + f'-zippath \"{plugin_path / "assets" / "gltf_sites_winx64.zip"}\"' |
167 | 159 | ) |
168 | 160 | print(run_cmd + args) |
169 | 161 | os.system(f"chmod u=rwx,o=x {cmd_file}") |
|
189 | 181 | # Python plugins are not supported in process. |
190 | 182 | dpf.start_local_server(config=dpf.AvailableServerConfigs.GrpcServer) |
191 | 183 |
|
192 | | -tmp = dpf.make_tmp_dir_server() |
193 | | -dpf.upload_files_in_folder(dpf.path_utilities.join(tmp, "plugins", "gltf_plugin"), plugin_path) |
194 | | -dpf.upload_file(plugin_path + ".xml", dpf.path_utilities.join(tmp, "plugins", "gltf_plugin.xml")) |
| 184 | +tmp = Path(dpf.make_tmp_dir_server()) |
| 185 | +dpf.upload_files_in_folder(dpf.path_utilities.join(str(tmp), "plugins", "gltf_plugin"), plugin_path) |
| 186 | +dpf.upload_file(str(plugin_path) + ".xml", dpf.path_utilities.join(str(tmp), "plugins", "gltf_plugin.xml")) |
195 | 187 |
|
196 | 188 | dpf.load_library( |
197 | 189 | dpf.path_utilities.join(tmp, "plugins", "gltf_plugin"), |
|
235 | 227 | # Use the custom operator |
236 | 228 | # ----------------------- |
237 | 229 |
|
238 | | -import os |
239 | | - |
240 | 230 | model = dpf.Model(dpf.upload_file_in_tmp_folder(examples.find_static_rst())) |
241 | 231 |
|
242 | 232 | mesh = model.metadata.meshed_region |
|
245 | 235 | displacement = model.results.displacement() |
246 | 236 | displacement.inputs.mesh_scoping(skin_mesh) |
247 | 237 | displacement.inputs.mesh(skin_mesh) |
248 | | -new_operator.inputs.path(os.path.join(tmp, "out")) |
| 238 | +new_operator.inputs.path(str(tmp / "out")) |
249 | 239 | new_operator.inputs.mesh(skin_mesh) |
250 | 240 | new_operator.inputs.field(displacement.outputs.fields_container()[0]) |
251 | 241 | new_operator.run() |
252 | 242 |
|
253 | 243 | print("operator ran successfully") |
254 | 244 |
|
255 | | -dpf.download_file(os.path.join(tmp, "out.glb"), os.path.join(os.getcwd(), "out.glb")) |
| 245 | +dpf.download_file(tmp / "out.glb", Path.cwd / "out.glb") |
256 | 246 |
|
257 | 247 | # %% |
258 | 248 | # You can download :download:`output <images/thumb/out.glb>` from the ``gltf`` operator. |
0 commit comments