Replace Left Side Subassembly

Replace Left Side Subassembly

Anonymous
Not applicable
1,108 Views
4 Replies
Message 1 of 5

Replace Left Side Subassembly

Anonymous
Not applicable

 

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();

 

]

 

test1.png

 

 

 

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();
            }
        }
    }
}
0 Likes
Accepted solutions (1)
1,109 Views
4 Replies
Replies (4)
Message 2 of 5

joantopo
Mentor
Mentor

Hi.

 

I have done some things with C3D API but in general with other objects.

About subassemblies, I did it just to get/set the input parameters.

 

In Civil 3D, when you drag a subassembly from the tool palette (before dropping in the assembly), you already have that comands (Insert previous,next, Replace..) in the command line or ToolTip.

 

I supose that you want to do this directly from selecting the subassembly in the assembly, in fact I told this idea:

https://forums.autodesk.com/t5/autocad-civil-3d-ideastation/replace-subassembly-selecting-assembly/i...

 

But I didn´t know in that moment that we could do this with C3D API.

It sounds good.

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
Message 3 of 5

Anonymous
Not applicable
Hello joantopo
Thank you so much reply my msg.

I saw that link already before send the msg and got some ideas.

But the main problem is "left side".
I can do that(replace/insert subassembly) in civil3d but I have to do that
programming code............ I think I will have to search this more harder.

Really Really really appreciate 🙂
0 Likes
Message 4 of 5

Jeff_M
Consultant
Consultant
Accepted solution

@Anonymous, welcome to the Civil3D forums! It looks like you've found a bug in the API. I'm getting the same results as you are, and it's definitely not the expected result. 

 

Hopefully @augusto.goncalves will chime in on this.

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 5

joantopo
Mentor
Mentor

Sorry, I referred to this:

https://forums.autodesk.com/t5/autocad-civil-3d-ideastation/replace-subassembly-picking-another-suba...

 

But about the idea of listing all the subassemblies which are contained in the selected assembly to replace one of them (because it is invisible to select it graphically), I think would be great.

You don´t have to change the point style or link style to do it visible previously.  🙂

 

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
0 Likes