diff --git a/src/Core/BatchQueueManager.cs b/src/Core/BatchQueueManager.cs index 91fedf7..3be3db9 100644 --- a/src/Core/BatchQueueManager.cs +++ b/src/Core/BatchQueueManager.cs @@ -527,6 +527,8 @@ namespace NavisworksTransport.Core // 真实物体名从 ModelItemReferences(Role=MovingObject)读取(BatchQueueItems 表无此列) string movingObjectName = item.MovingObjectName; string expectedAncestorChain = null; + int movingModelIndex = 0; + string movingObjectPathId = null; if (!item.IsVirtualObject) { var movingRefs = await _database.GetModelItemReferencesAsync( @@ -534,6 +536,8 @@ namespace NavisworksTransport.Core if (movingRefs.Count > 0) { movingObjectName = movingRefs[0].ObjectName ?? movingRefs[0].DisplayName; + movingModelIndex = movingRefs[0].ModelIndex; + movingObjectPathId = movingRefs[0].PathId; // 主 NW 按 PathId 解析移动物体 → 层级链(导出剖面盒保留树结构,副实例按链匹配) try @@ -570,6 +574,8 @@ namespace NavisworksTransport.Core item.IsVirtualObject, movingObjectName, expectedAncestorChain, + movingModelIndex, + movingObjectPathId, item.VirtualObjectLength, item.VirtualObjectWidth, item.VirtualObjectHeight, diff --git a/src/Core/Services/SectionBoxBatchDetector.cs b/src/Core/Services/SectionBoxBatchDetector.cs index 29ba78a..8289071 100644 --- a/src/Core/Services/SectionBoxBatchDetector.cs +++ b/src/Core/Services/SectionBoxBatchDetector.cs @@ -86,6 +86,8 @@ namespace NavisworksTransport.Core.Services bool isVirtualObject, string movingObjectName, string expectedAncestorChain, + int movingModelIndex, + string movingObjectPathId, double virtualObjectLengthModelUnits, double virtualObjectWidthModelUnits, double virtualObjectHeightModelUnits, @@ -135,6 +137,39 @@ namespace NavisworksTransport.Core.Services { exported = System.Windows.Application.Current.Dispatcher.Invoke(() => { + // 导出前:把移动物体恢复到路径起点(加入批处理时的位置),确保导出包含移动物体。 + // 真实物体可能已被后续操作移回 CAD 原位置(甚至不在路径剖面盒内)。 + if (!isVirtualObject && !string.IsNullOrWhiteSpace(movingObjectPathId)) + { + try + { + var pathAnim = Core.Animation.PathAnimationManager.GetInstance(); + if (pathAnim != null && route != null) + { + pathAnim.SetRoute(route); + var movingItem = document.Models.ResolvePathId(new Autodesk.Navisworks.Api.DocumentParts.ModelItemPathId + { + ModelIndex = movingModelIndex, + PathId = movingObjectPathId + }); + if (movingItem != null) + { + pathAnim.MoveObjectToPathStart( + movingItem, route.Points.Select(p => p.Position).ToList()); + LogManager.Info($"[剖面盒批检测] 移动物体已恢复到路径起点: {movingItem.DisplayName}"); + } + else + { + LogManager.Warning($"[剖面盒批检测] 无法解析移动物体 ModelItem({movingObjectPathId}),导出可能不包含该物体"); + } + } + } + catch (Exception moveEx) + { + LogManager.Warning($"[剖面盒批检测] 移动物体恢复到起点失败: {moveEx.Message}"); + } + } + var exporter = new SectionBoxExporter(); var traversal = exporter.GetObjectsAndHiddenItems(document, bounds); if (traversal.ObjectsInBox.Count == 0)