Author Topic: Create Assembly with SubAssembly in C#  (Read 2691 times)

0 Members and 1 Guest are viewing this topic.

alexisgacia

  • Mosquito
  • Posts: 3
Create Assembly with SubAssembly in C#
« on: October 24, 2023, 03:39:15 AM »
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.

Code - C#: [Select]
  1. void _CreateAssembly_1()
  2.         {
  3.             var doc = Application.DocumentManager.MdiActiveDocument;
  4.             var db = doc.Database;
  5.             var ed = doc.Editor;
  6.             CivilDocument civilDoc = CivilDocument.GetCivilDocument(doc.Database);
  7.             Point3d pntLoc = cSelection.Select_Point3d("Select Target Location");
  8.  
  9.             if (pntLoc == new Point3d(0, 0, 0)) return;
  10.             using (doc.LockDocument())
  11.             {
  12.                 using (Transaction tr = doc.TransactionManager.StartTransaction())
  13.                 {
  14.                     BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
  15.                     BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  16.                     //acc3db.Assembly oAsm = new acc3db.Assembly();
  17.  
  18.                     ObjectId AssemblyId = civilDoc.AssemblyCollection.Add("test2", acc3db.AssemblyType.Other, pntLoc);
  19.  
  20.                     acc3db.Subassembly asm = AssemblyId.GetObject(OpenMode.ForWrite) as acc3db.Subassembly;
  21.  
  22.                     //civilDoc.SubassemblyCollection.Add("GEC_Carriageway_5layer",)
  23.  
  24.                     listBox1.Items.Clear();
  25.                     // List Sub Assembly
  26.                     foreach (var o in civilDoc.SubassemblyCollection)
  27.                     {
  28.                         acc3db.Subassembly subasm = o.GetObject(OpenMode.ForRead) as acc3db.Subassembly;
  29.                         listBox1.Items.Add("  " + subasm.Name + " - " + subasm.Name);
  30.                     }
  31.                      
  32.                     // Create the CW subassembly                    
  33.                     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)));
  34.                     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)));
  35.  
  36.                     acc3db.Subassembly sub = (acc3db.Subassembly)subAsmId_R.GetObject(OpenMode.ForWrite);
  37.                     acc3db.Subassembly sub_L = (acc3db.Subassembly)subAsmId_L.GetObject(OpenMode.ForWrite);
  38.  
  39.                      foreach (var o in sub_L.ParamsLong)
  40.                     {
  41.                         if (o.DisplayName.ToUpper() == "SIDE") o.Value = 1;
  42.  
  43.                                              }
  44.  
  45.  
  46.                      
  47.  
  48.  
  49.  
  50.  
  51.                     tr.Commit();
  52.                 }
  53.             }
  54.         }
  55.