Hi,
I'm trying to automate the process of creating assembly with subassembly in C#. Is this possible? I was able to create the Assembly but not able to attached the subassembly.
Left SubAssembly Right SubAssembly
Footpath,Parking,Kerb,Carriageway | Carriageway,Kerb,Parking,Footpath
Below the sample code that I created.
void _CreateAssembly_1()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
CivilDocument civilDoc = CivilDocument.GetCivilDocument(doc.Database);
Point3d pntLoc = cSelection.Select_Point3d("Select Target Location");
if (pntLoc
== new Point3d
(0,
0,
0)) return; using (doc.LockDocument())
{
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
//acc3db.Assembly oAsm = new acc3db.Assembly();
ObjectId AssemblyId = civilDoc.AssemblyCollection.Add("test2", acc3db.AssemblyType.Other, pntLoc);
acc3db.Subassembly asm = AssemblyId.GetObject(OpenMode.ForWrite) as acc3db.Subassembly;
//civilDoc.SubassemblyCollection.Add("GEC_Carriageway_5layer",)
listBox1.Items.Clear();
// List Sub Assembly
foreach (var o in civilDoc.SubassemblyCollection)
{
acc3db.Subassembly subasm = o.GetObject(OpenMode.ForRead) as acc3db.Subassembly;
listBox1.Items.Add(" " + subasm.Name + " - " + subasm.Name);
}
// Create the CW subassembly
ObjectId subAsmId_R
= civilDoc
.SubassemblyCollection.ImportSubassembly("GEC_Carriageway_5layer_R_2",
@"C:\ProgramData\Autodesk\C3D 2023\enu\Imported Tools\GEC_Carriageway_5_layer\af8a6c22d9e746f895aad89dcfcc3f42.atc",
"43365f65-e04b-4df4-98ba-c308d3e806b4", pntLoc
.Add(new Vector3d
(0,
0,
0))); ObjectId subAsmId_L
= civilDoc
.SubassemblyCollection.ImportSubassembly("GEC_Carriageway_5layer_L_2",
@"C:\ProgramData\Autodesk\C3D 2023\enu\Imported Tools\GEC_Carriageway_5_layer\af8a6c22d9e746f895aad89dcfcc3f42.atc",
"43365f65-e04b-4df4-98ba-c308d3e806b4", pntLoc
.Add(new Vector3d
(0,
0,
0)));
acc3db.Subassembly sub = (acc3db.Subassembly)subAsmId_R.GetObject(OpenMode.ForWrite);
acc3db.Subassembly sub_L = (acc3db.Subassembly)subAsmId_L.GetObject(OpenMode.ForWrite);
foreach (var o in sub_L.ParamsLong)
{
if (o.DisplayName.ToUpper() == "SIDE") o.Value = 1;
}
tr.Commit();
}
}
}