fix: search features + feature names for ISOGRID_SANDBOX attribute (Promote Body stores attrs on feature, not body)

This commit is contained in:
2026-02-16 17:26:20 +00:00
parent 6251787ca5
commit afaa925da8

View File

@@ -239,9 +239,18 @@ def find_sandbox_bodies(
) -> List[Tuple[str, Any, Any]]:
"""
Find bodies tagged with ISOGRID_SANDBOX attribute.
Search order:
1. Body-level attributes (part.Bodies)
2. Face-level attributes
3. Feature-level attributes (part history — Promote Body features)
4. Feature name matching (e.g. 'Sandbox_1' in feature name)
5. Body name matching
Returns list of (sandbox_id, body, face) tuples.
"""
tagged: List[Tuple[str, Any, Any]] = []
found_ids: set = set()
bodies = []
try:
@@ -251,6 +260,7 @@ def find_sandbox_bodies(
lister.WriteLine(f"[extract_sandbox] Scanning {len(bodies)} bodies...")
# --- Pass 1: body-level and face-level attributes ---
for body in bodies:
body_name = ""
try:
@@ -258,37 +268,106 @@ def find_sandbox_bodies(
except Exception:
pass
# Check body-level attribute
sandbox_id = _get_string_attribute(body, attr_name)
if sandbox_id:
if sandbox_id and sandbox_id not in found_ids:
faces = body.GetFaces()
if faces:
tagged.append((sandbox_id, body, faces[0]))
lister.WriteLine(f"[extract_sandbox] Found: {sandbox_id} (body attr on '{body_name}', {len(faces)} face(s))")
found_ids.add(sandbox_id)
lister.WriteLine(f"[extract_sandbox] Found: {sandbox_id} (body attr on '{body_name}')")
continue
# Check face-level attribute
for face in body.GetFaces():
sandbox_id = _get_string_attribute(face, attr_name)
if sandbox_id:
if sandbox_id and sandbox_id not in found_ids:
tagged.append((sandbox_id, body, face))
found_ids.add(sandbox_id)
lister.WriteLine(f"[extract_sandbox] Found: {sandbox_id} (face attr on '{body_name}')")
# Fallback: body name matching
if not tagged:
lister.WriteLine("[extract_sandbox] No attributes found, trying name matching...")
for body in bodies:
bname = ""
if tagged:
return tagged
# --- Pass 2: feature-level attributes (Promote Body features) ---
lister.WriteLine("[extract_sandbox] No body/face attrs found, scanning features...")
try:
features = part.Features.ToArray() if hasattr(part.Features, "ToArray") else list(part.Features)
lister.WriteLine(f"[extract_sandbox] Found {len(features)} features")
for feat in features:
feat_name = ""
try:
bname = body.Name if hasattr(body, "Name") else str(body)
feat_name = feat.Name if hasattr(feat, "Name") else str(feat)
except Exception:
pass
# Check feature attribute
sandbox_id = _get_string_attribute(feat, attr_name)
if sandbox_id and sandbox_id not in found_ids:
# Get the body produced by this feature
try:
feat_bodies = feat.GetBodies()
if feat_bodies:
body = feat_bodies[0]
faces = body.GetFaces()
if faces:
tagged.append((sandbox_id, body, faces[0]))
found_ids.add(sandbox_id)
lister.WriteLine(f"[extract_sandbox] Found: {sandbox_id} (feature attr on '{feat_name}')")
except Exception as exc:
lister.WriteLine(f"[extract_sandbox] Feature '{feat_name}' has attr but GetBodies failed: {exc}")
except Exception as exc:
lister.WriteLine(f"[extract_sandbox] Feature scan error: {exc}")
if tagged:
return tagged
# --- Pass 3: feature name matching (e.g. "Sandbox_1" in name) ---
lister.WriteLine("[extract_sandbox] No feature attrs found, trying feature name matching...")
try:
features = part.Features.ToArray() if hasattr(part.Features, "ToArray") else list(part.Features)
for feat in features:
feat_name = ""
try:
feat_name = feat.Name if hasattr(feat, "Name") else str(feat)
except Exception:
continue
if "sandbox" in bname.lower():
faces = body.GetFaces()
if faces:
sid = bname.lower().replace(" ", "_")
if "sandbox" in feat_name.lower():
try:
feat_bodies = feat.GetBodies()
if feat_bodies:
body = feat_bodies[0]
faces = body.GetFaces()
if faces:
sid = feat_name.lower().replace(" ", "_")
if sid not in found_ids:
tagged.append((sid, body, faces[0]))
found_ids.add(sid)
lister.WriteLine(f"[extract_sandbox] Found by feature name: {sid} ('{feat_name}')")
except Exception as exc:
lister.WriteLine(f"[extract_sandbox] Feature '{feat_name}' name match but GetBodies failed: {exc}")
except Exception:
pass
if tagged:
return tagged
# --- Pass 4: body name matching ---
lister.WriteLine("[extract_sandbox] No features matched, trying body name matching...")
for body in bodies:
bname = ""
try:
bname = body.Name if hasattr(body, "Name") else str(body)
except Exception:
continue
if "sandbox" in bname.lower():
faces = body.GetFaces()
if faces:
sid = bname.lower().replace(" ", "_")
if sid not in found_ids:
tagged.append((sid, body, faces[0]))
lister.WriteLine(f"[extract_sandbox] Found by name: {sid}")
found_ids.add(sid)
lister.WriteLine(f"[extract_sandbox] Found by body name: {sid}")
return tagged