I've been taking a deep dive into this via the the scripting language and the Fabrication API. Also been working on a modified version of the FabricationSample Add-In using AI (Claude CLI). It's done a pretty good job of adding features but, the Swap In is still a hangup. Essentially it will swap the item successfully but, can't place it back on the design line. Here's what it returned.
Key Findings
COD Script Approach (SwapCID.cod)
- Uses item.Load(itmName) which replaces the item IN PLACE - this preserves position
- Stores connector EndLocation using item.EndLocation(1, "X"), item.EndLocation(1, "Y"), etc.
- Critical limitation: Even COD scripting notes on line 109: "Manual redraw/redevelop required in CADmep to restore 3D position"
Fabrication API Limitations
- Service.LoadServiceItem() creates a NEW item rather than replacing in-place
- There is no direct API method to set connector endpoint positions
- There is no programmatic access to the Redevelop command
Changes Made
Updated MoveItemWithOffset() (ItemSwapService.cs:478-550) to:
1. Primary method: Use SendStringToExecute with AutoCAD's MOVE command
- Format: _.MOVE (handent "handle") 0,0,0 @offsetX,offsetY,offsetZ
- This uses native CAD move functionality which may work better for Fabrication items
2. Fallback: Direct entity transformation if SendStringToExecute fails
Remaining Limitation
Items on designlines (nodes/fittings) are constrained by their connections to adjacent items. Even with the MOVE command, they may resist repositioning because:
- They're part of a connected run/route
- Their position is determined by adjacent item connections
- Manual redevelop or reconnection may be required
Recommendation
For items on designlines, after swapping you may need to:
1. Select the swapped item in AutoCAD
2. Use the MAPREDEVELOP command to regenerate geometry
3. Or manually grip-edit the item to reconnect it to the run
Will be curious if anyone is able to crack it because I've blown all my tokens for the day
