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