Message 1 of 5

Not applicable
03-09-2016
06:00 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to replace subassembly Left Side.
I'm doing this Right side successfully using below code.
but I can't do that right side.
This is main code.
[
Assembly.InsertSubassemblybefore(subReplace.Id, subTarget.Id);
subTarget.Erase();
]
Right Side is replaced well.
( the next subassembly (ex. basic side walk) is attached to subReplace.)
but Left side's Next (Or Previous) subassembly is not attached to subReplace.
I was using All function Assembly has.
InsertSubAssemblyAfter();
ReplaceSubassembly();
...
and I found the function in subassembly
SubassemblyHookTo();
but It is read only I can't to what I want.
Please Help.................. TTTTTTTTTTTT
using System; using System.Collections.Generic; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.EditorInput; using Autodesk.Civil.ApplicationServices; using Autodesk.Civil.DatabaseServices; using Autodesk.Civil.Runtime; using Autodesk.Civil.Settings; using Autodesk.Civil.DatabaseServices.Styles; using Section = Autodesk.Civil.DatabaseServices.Section; using DBObject = Autodesk.Civil.DatabaseServices.DBObject; namespace C3DTest2 { public class Class3 { public static CivilDocument cdoc = CivilApplication.ActiveDocument; public static Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; public static Database db = doc.Database; public static Editor ed = doc.Editor; public static Transaction tr; public DocumentLock docLock; [CommandMethod("REE")] public static void ReplaceSubAssem() { // PromptSelectionOptions pso = new PromptSelectionOptions(); pso.SingleOnly = true; PromptSelectionResult psr = ed.GetSelection(pso); if (psr.Status != PromptStatus.OK) return; using (tr = db.TransactionManager.StartTransaction()) { Subassembly subAssem = null; ObjectId subAssemId = ObjectId.Null; Assembly curAssem = null; foreach (SelectedObject sobj in psr.Value) { subAssem = tr.GetObject(sobj.ObjectId, OpenMode.ForWrite) as Subassembly; subAssemId = sobj.ObjectId; } AssemblyCollection AssemColl = cdoc.AssemblyCollection; bool bCheck = false; foreach (ObjectId AssemId in AssemColl) { Assembly Assem = tr.GetObject(AssemId, OpenMode.ForWrite) as Assembly; foreach (AssemblyGroup AssemGrp in Assem.Groups) { for (int i = 0; i < AssemGrp.GetSubassemblyIds().Count; i++) { ObjectId subId = AssemGrp.GetSubassemblyIds()[i]; if (subAssemId == subId) { curAssem = Assem; bCheck = true; break; } } if (bCheck == true) break; } if (bCheck == true) break; } ObjectId subReplaceId = cdoc.SubassemblyCollection.ImportStockSubassembly( "UrbanCurbGutterValley1", "Subassembly.UrbanCurbGutterValley1", new Point3d(6408, 4025, 0)); Subassembly subReplace = tr.GetObject(subReplaceId, OpenMode.ForWrite) as Subassembly; if (curAssem == null || subAssem == null) return; subReplace.Side = subAssem.Side; curAssem.InsertSubassemblyBefore(subReplace.Id, subAssem.Id); subAssem.Erase(); tr.Commit(); ed.Regen(); } } } }
Solved! Go to Solution.