How can we delete existing parts , and import a new geometry ?
Erik Kostson
Member, Moderator, Employee Posts: 276
✭✭✭✭
Say we have an existing geometry with parts, how can we first delete it and then finally import a new geometry into mechanical?
0
Best Answer
-
One way is as described below (works in 2023 R2 and 2024 R2):
import os work_dir = r'D:\myheatfiles\PyAnsys\PyMechanical\demo' ## geometry folder / change as needed ## Import geometry geometry_file = os.path.join(work_dir,'Valve.scdoc') geometry_import=ExtAPI.DataModel.Project.Model.GeometryImportGroup[0] # gets the Geometry Import geopartdel=[] ## parts to be deleted ##Delete existing parts for assembly in ExtAPI.DataModel.GeoData.Assemblies: for part in assembly.Parts: for body in part.Bodies: geopartdel.Add(body.Part) Model.DeleteParts(geopartdel) ##Imports new parts geometry_import.Import(geometry_file)
or without looping (parts):
import os work_dir = r'D:\demo' geometry_file = os.path.join(work_dir,'Valve.scdoc') geometry_import=ExtAPI.DataModel.Project.Model.GeometryImportGroup[0] geopartdel=ExtAPI.DataModel.GeoData.Assemblies[0].AllParts Model.DeleteParts(geopartdel) geometry_import.Import(geometry_file)
0
This discussion has been closed.