<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: want to rotate structures with pipe network in Civil 3D Customization Forum</title>
    <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12497192#M2575</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/13116392"&gt;@goswami12897&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you attached example drawing&lt;/P&gt;</description>
    <pubDate>Mon, 15 Jan 2024 11:40:53 GMT</pubDate>
    <dc:creator>hosneyalaa</dc:creator>
    <dc:date>2024-01-15T11:40:53Z</dc:date>
    <item>
      <title>want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12492711#M2571</link>
      <description>&lt;P&gt;Hello I am developing small tool so I can swap multiple structural members at once but I want to align the replacing parts along with the direction of pipe too please can anyone help me how can I do that the code is below&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;
using Autodesk.Civil.DatabaseServices.Styles;
using System;

[assembly: CommandClass(typeof(SwapParts.Swap))]
namespace SwapParts
{
    public class Swap
    {
        [CommandMethod("SwapAllParts")]
        public void SwapParts()
        {
            Document document = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            Database database = document.Database;
            Editor editor = document.Editor;

            editor.WriteMessage("\n Select the structures to replace");

            PromptSelectionResult solidSelected = editor.GetSelection();
            if (solidSelected.Status != PromptStatus.OK)
            {
                editor.WriteMessage("\n Selected wrong Objects. Please restart the command to try again");
                return;
            }
            SelectionSet set = solidSelected.Value;
            using (Transaction transaction = database.TransactionManager.StartTransaction())
            {

                CivilDocument cDoc = CivilApplication.ActiveDocument;
                PartsListCollection partsListCollection = cDoc.Styles.PartsListSet;
                foreach (ObjectId part in partsListCollection)
                {
                    PartsList partsList = transaction.GetObject(part, OpenMode.ForRead) as PartsList;
                    {
                        editor.WriteMessage($"\nPARTS LISTS: {partsList.Name}");
                    }
                }
                    PromptStringOptions partsListName = new PromptStringOptions("\nSelect the Parts List from which you want to insert the new part")
                    {
                        AllowSpaces = true,
                    };
                    PromptResult partlistName1 = editor.GetString(partsListName);
                    string partsListName2 = partlistName1.StringResult;
                    ObjectId PartsList1 = cDoc.Styles.PartsListSet[partsListName2];
                    PartsList partsList2 = transaction.GetObject(PartsList1, OpenMode.ForWrite) as PartsList;
                    ObjectIdCollection partFamilyCollection = partsList2.GetPartFamilyIdsByDomain(DomainType.Structure);
                    foreach (ObjectId partStr in partFamilyCollection)
                    {
                        PartFamily partFamily1 = transaction.GetObject(partStr, OpenMode.ForWrite) as PartFamily;
                        if (partFamily1.Domain == DomainType.Structure)
                        {
                         editor.WriteMessage($"\nStructures: {partFamily1.Name}");
                        }
                    } 
                PromptStringOptions partFamilyName = new PromptStringOptions("\nSelect the structure you want to swap these structures with")
                {
                    AllowSpaces = true,
                };
                PromptResult partFamilySwapping = editor.GetString(partFamilyName);
                string swapper = partFamilySwapping.StringResult;
                ObjectId structureId = partsList2[swapper];
                Structure structure = transaction.GetObject(structureId, OpenMode.ForWrite) as Structure;
                PartFamily str1 = transaction.GetObject(structureId, OpenMode.ForWrite) as PartFamily;
                ObjectId psizestr = str1[0];
                

                foreach (SelectedObject obj in set)
                {
                    if (obj.ObjectId.ObjectClass.DxfName.Contains("STRUCTURE"))
                    {
                        Structure str = transaction.GetObject(obj.ObjectId, OpenMode.ForRead) as Structure;
                        str.SwapPartFamilyAndSize(structureId, psizestr);
                        string[] pipeNames = str.GetConnectedPipeNames();
                        if (pipeNames.Length &amp;gt; 1)
                        {
                            ObjectId pipedId = str.get_ConnectedPipe(1);
                            Pipe pipe = transaction.GetObject(pipedId, OpenMode.ForRead) as Pipe;
                            
                        }
                        else
                        {
                            ObjectId pipedId = str.get_ConnectedPipe(0);
                            Pipe pipe = transaction.GetObject(pipedId, OpenMode.ForRead) as Pipe;
                            
                        }


                    }
                }
                transaction.Commit();
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;the part where the if else statement begins I tried to get angle the replacement tool works fine but unable to understand how to rotate the structures to align with pipe please help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 08:55:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12492711#M2571</guid>
      <dc:creator>goswami12897</dc:creator>
      <dc:date>2024-01-12T08:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12493297#M2572</link>
      <description>&lt;P&gt;Structure.Rotation property (read/write)? You just need to determine the rotation angle based on the connected pipe(s)&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 14:15:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12493297#M2572</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2024-01-12T14:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12493337#M2573</link>
      <description>&lt;P&gt;exactly to what should I equate it to that's my doubt that it automatically takes direction of pipe&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 14:31:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12493337#M2573</guid>
      <dc:creator>goswami12897</dc:creator>
      <dc:date>2024-01-12T14:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12497098#M2574</link>
      <description>&lt;P&gt;I tried this but it is throwing the violation error and civil3d closes down please help me to rectify errors&lt;/P&gt;&lt;LI-CODE lang="general"&gt; if (obj.ObjectId.ObjectClass.DxfName.Contains("STRUCTURE"))
                    {
                        Structure str = transaction.GetObject(obj.ObjectId, OpenMode.ForRead) as Structure;
                        str.SwapPartFamilyAndSize(structureId, psizestr);
                        string[] pipeNames = str.GetConnectedPipeNames();
                        if (pipeNames.Length &amp;gt; 1)
                        {
                            ObjectId pipedId = str.get_ConnectedPipe(1);
                            Pipe pipe = transaction.GetObject(pipedId, OpenMode.ForRead) as Pipe;
                            Point3d pt1 = pipe.StartPoint;
                            Point3d pt2 = pipe.EndPoint;
                            double angle = Vector3d.XAxis.GetAngleTo(pt2 - pt1);
                            structure.Rotation = angle;
                        }
                        else
                        { 
                            ObjectId pipedId = str.get_ConnectedPipe(0);
                            Pipe pipe = transaction.GetObject(pipedId, OpenMode.ForRead) as Pipe;
                            Point3d pt1 = pipe.StartPoint;
                            Point3d pt2 = pipe.EndPoint;
                            double angle = Vector3d.XAxis.GetAngleTo(pt2 - pt1);
                            structure.Rotation = angle;
                        }
                       
                    }&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 15 Jan 2024 10:36:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12497098#M2574</guid>
      <dc:creator>goswami12897</dc:creator>
      <dc:date>2024-01-15T10:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12497192#M2575</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/13116392"&gt;@goswami12897&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you attached example drawing&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 11:40:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12497192#M2575</guid>
      <dc:creator>hosneyalaa</dc:creator>
      <dc:date>2024-01-15T11:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12497242#M2576</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-01-15 173336.png" style="width: 925px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1314186i9C33098EF6EFBB9F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-01-15 173336.png" alt="Screenshot 2024-01-15 173336.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-01-15 173233.png" style="width: 429px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1314187i2A8E0888179E1ADE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-01-15 173233.png" alt="Screenshot 2024-01-15 173233.png" /&gt;&lt;/span&gt;Like here when I swapped null structure with the rectangular slab I want that slab to be aligned with the pipe following it basically in it's direction, I commented out the part that was causing violation and this much happened now I want to rotate the part too to align it with pipe following it and if it's the last pipe I want it to be aligned with the pipe preceding it&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 12:08:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12497242#M2576</guid>
      <dc:creator>goswami12897</dc:creator>
      <dc:date>2024-01-15T12:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12497251#M2577</link>
      <description>&lt;P&gt;basically all parts are coming in horizontal rotation ie 0 degees but I want them to be following the pipe rotation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 12:11:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12497251#M2577</guid>
      <dc:creator>goswami12897</dc:creator>
      <dc:date>2024-01-15T12:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12497680#M2578</link>
      <description>&lt;P&gt;Your code is a bit of confusing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the "if..." condition, you test "obj" is a Structure or not. If yes, you open it for READ, and assign it as variable "str" for calculating rotation. Then you set the rotation angle to another structure pointer "structure", which is declare outside the code scope you showed: it is the same Structure as the variable "str" points to? was it opened for write?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 15:57:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12497680#M2578</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2024-01-15T15:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12497704#M2579</link>
      <description>&lt;P&gt;one str is the structure that usee selected on screen, structure is fhe structure that is made on screen that swaps str&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 16:05:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12497704#M2579</guid>
      <dc:creator>goswami12897</dc:creator>
      <dc:date>2024-01-15T16:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12498485#M2580</link>
      <description>&lt;P&gt;I do not understand your answer: shouldn't 2 structure variables point to the same structure (you only want to parsize to a different partsize (e.g the structure position is unchanged).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also&lt;/P&gt;
&lt;PRE class="lia-code-sample line-numbers language-general" tabindex="0"&gt;&lt;CODE&gt;str.SwapPartFamilyAndSize(structureId, psizestr);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the "structureId" in the SwapPartFamilyAndSize() call? Is it a partFamily's ObjectId? If yes, you have bad variable naming habit; if not (e.g., if it is a structure's ObjectId, as the variable name implies), that is one possible reason you get crash.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should post more code to make sure how all variables are declared and objects are instantiated. Otherwise, I can only guess based on "common-sense" of variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 00:38:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12498485#M2580</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2024-01-16T00:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12498842#M2581</link>
      <description>&lt;P&gt;so copy that code and comment out the line where Structure class variable was introduced, run it in civil3d it will throw an error that the objectid should be from structure class based on the commonsense I see. As I have already stated parts are getting swapped successfully I need help regarding rotation of the members, thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 06:07:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12498842#M2581</guid>
      <dc:creator>goswami12897</dc:creator>
      <dc:date>2024-01-16T06:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12498843#M2582</link>
      <description>&lt;P&gt;Whenever you put an objectid, you need to allocate the class as well right otherwise which objectid it is?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 06:09:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12498843#M2582</guid>
      <dc:creator>goswami12897</dc:creator>
      <dc:date>2024-01-16T06:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12499392#M2583</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/13116392"&gt;@goswami12897&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You do not need to the rotate , He takes it from the manhole before&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="7.gif" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1314607i6A9EB841996746F1/image-size/large?v=v2&amp;amp;px=999" role="button" title="7.gif" alt="7.gif" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 12:18:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12499392#M2583</guid>
      <dc:creator>hosneyalaa</dc:creator>
      <dc:date>2024-01-16T12:18:37Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12499401#M2584</link>
      <description>&lt;P&gt;Yes that's true but some parts in the network are at&amp;nbsp; 0 degree rotation from horizontal so have to get the rotation according to the pipe inlet&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 12:22:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12499401#M2584</guid>
      <dc:creator>goswami12897</dc:creator>
      <dc:date>2024-01-16T12:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12517037#M2585</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6591997"&gt;@hosneyalaa&lt;/a&gt;&amp;nbsp;is there any way we can get objectid's of the pipes connected to a structure or vice versa?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2024 05:01:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12517037#M2585</guid>
      <dc:creator>goswami12897</dc:creator>
      <dc:date>2024-01-24T05:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12517120#M2586</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="00.JPG" style="width: 782px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1317693iFE11FC918ADCA0FD/image-size/large?v=v2&amp;amp;px=999" role="button" title="00.JPG" alt="00.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2024 06:34:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12517120#M2586</guid>
      <dc:creator>hosneyalaa</dc:creator>
      <dc:date>2024-01-24T06:34:19Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12517333#M2587</link>
      <description>&lt;P&gt;Hey the parts are successfully rotating now but when our angle of pipe in downwards in civil3D the rotation is not matching the pipe, can you tell me what could be done other then that it is spot on.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Internal;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;
using Autodesk.Civil.DatabaseServices.Styles;
using System;
using System.Linq;

[assembly: CommandClass(typeof(SwapParts.Swap))]
namespace SwapParts
{
    public class Swap
    {
        [CommandMethod("SwapAllParts")]
        public void SwapParts()
        {
            Document document = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            Database database = document.Database;
            Editor editor = document.Editor;

            editor.WriteMessage("\n Select the structures to replace");

            PromptSelectionResult solidSelected = editor.GetSelection();
            if (solidSelected.Status != PromptStatus.OK)
            {
                editor.WriteMessage("\n Selected wrong Objects. Please restart the command to try again");
                return;
            }
            SelectionSet set = solidSelected.Value;
            using (Transaction transaction = database.TransactionManager.StartTransaction())
            {

                CivilDocument cDoc = CivilApplication.ActiveDocument;
                PartsListCollection partsListCollection = cDoc.Styles.PartsListSet;
                foreach (ObjectId part in partsListCollection)
                {
                    PartsList partsList = transaction.GetObject(part, OpenMode.ForRead) as PartsList;
                    {
                        editor.WriteMessage($"\nPARTS LISTS: {partsList.Name}");
                    }
                }
                    PromptStringOptions partsListName = new PromptStringOptions("\nSelect the Parts List from which you want to insert the new part")
                    {
                        AllowSpaces = true,
                    };
                    PromptResult partlistName1 = editor.GetString(partsListName);
                    string partsListName2 = partlistName1.StringResult;
                    ObjectId PartsList1 = cDoc.Styles.PartsListSet[partsListName2];
                    PartsList partsList2 = transaction.GetObject(PartsList1, OpenMode.ForWrite) as PartsList;
                    ObjectIdCollection partFamilyCollection = partsList2.GetPartFamilyIdsByDomain(DomainType.Structure);
                    foreach (ObjectId partStr in partFamilyCollection)
                    {
                        PartFamily partFamily1 = transaction.GetObject(partStr, OpenMode.ForWrite) as PartFamily;
                        if (partFamily1.Domain == DomainType.Structure)
                        {
                         editor.WriteMessage($"\nStructures: {partFamily1.Name}");
                        }
                    } 
                PromptStringOptions partFamilyName = new PromptStringOptions("\nSelect the structure you want to swap these structures with")
                {
                    AllowSpaces = true,
                };
                PromptResult partFamilySwapping = editor.GetString(partFamilyName);
                string swapper = partFamilySwapping.StringResult;
                ObjectId structureId = partsList2[swapper];
                Structure structure = transaction.GetObject(structureId, OpenMode.ForWrite) as Structure;
                PartFamily str1 = transaction.GetObject(structureId, OpenMode.ForWrite) as PartFamily;
                ObjectId psizestr = str1[0];
                

                foreach (SelectedObject obj in set)
                {
                    if (obj.ObjectId.ObjectClass.DxfName.Contains("STRUCTURE"))
                    {
                        Structure str = transaction.GetObject(obj.ObjectId, OpenMode.ForWrite) as Structure;
                        
                            string[] pipeNames = str.GetConnectedPipeNames();
                            foreach (string count in pipeNames)
                            {
                                editor.WriteMessage($"\n{count} ");
                            }




                        if (pipeNames.Length &amp;gt; 1)
                        {
                            try
                            {
                                ObjectId pipeId = str.get_ConnectedPipe(1);
                                Pipe pipe = transaction.GetObject(pipeId, OpenMode.ForRead) as Pipe;
                                Point3d pt1 = pipe.StartPoint;
                                Point3d pt2 = pipe.EndPoint;
                                double angle = Vector3d.XAxis.GetAngleTo(pt2-pt1);
                                str.Rotation = angle;
                                editor.WriteMessage($"\n 2 pipes connected angle of Rotation : {angle:N3}");
                            }
                            catch (System.Exception exx)
                            {
                                editor.WriteMessage($"\n {exx}");
                            }

                        }
                        else
                        {
                            try
                            {
                                ObjectId pipedId = str.get_ConnectedPipe(0);
                                Pipe pipe = transaction.GetObject(pipedId, OpenMode.ForRead) as Pipe;
                                Point3d pt1 = pipe.StartPoint;
                                Point3d pt2 = pipe.EndPoint;
                                double angle = Vector3d.XAxis.GetAngleTo(pt2 - pt1);
                                str.Rotation = angle;
                                editor.WriteMessage($"\n 1 pipe connected angle of Rotation : {angle:N3}");
                            }
                            catch (System.Exception ex)
                            {
                                editor.WriteMessage($"{ex}");
                            }
                        }
                        
                        str.SwapPartFamilyAndSize(structureId, psizestr);

                    }
                }
                transaction.Commit();
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;like in these attached Screenshots if the pipes are coming in V shape it is fine but when opposite it is having error please check just some geometric correction required.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-01-24 145152.png" style="width: 990px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1317731iF0AEE6CC6EA6DEBC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-01-24 145152.png" alt="Screenshot 2024-01-24 145152.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2024 09:24:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12517333#M2587</guid>
      <dc:creator>goswami12897</dc:creator>
      <dc:date>2024-01-24T09:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12517341#M2588</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-01-24 145208.png" style="width: 903px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1317733iF17A27901C6F88FB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-01-24 145208.png" alt="Screenshot 2024-01-24 145208.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-01-24 145152.png" style="width: 990px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1317734i81D4F303F555D019/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-01-24 145152.png" alt="Screenshot 2024-01-24 145152.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2024 09:26:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12517341#M2588</guid>
      <dc:creator>goswami12897</dc:creator>
      <dc:date>2024-01-24T09:26:21Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12517614#M2589</link>
      <description>&lt;P&gt;TRY&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;foreach (SelectedObject obj in set)
                {
                    if (obj.ObjectId.ObjectClass.DxfName.Contains("STRUCTURE"))
                    {
                        Structure str = transaction.GetObject(obj.ObjectId, OpenMode.ForRead) as Structure;
                        str.SwapPartFamilyAndSize(structureId, psizestr);

                        string[] pipeNames = str.GetConnectedPipeNames();
                        if (pipeNames.Length &amp;gt; 1)
                        {
                            ObjectId pipedId = str.get_ConnectedPipe(1);
                            Pipe pipe = transaction.GetObject(pipedId, OpenMode.ForRead) as Pipe;
                            Point3d pt1 = pipe.StartPoint;
                            Point3d pt2 = pipe.EndPoint;
                            //double angle = Vector3d.XAxis.GetAngleTo(pt2 - pt1);
                            double angle = Vector3d.XAxis.GetAngleTo(pt1.GetVectorTo(pt2), Vector3d.ZAxis);
                            str.Rotation = angle;

                        }
                        else
                        {
                            ObjectId pipedId = str.get_ConnectedPipe(0);
                            Pipe pipe = transaction.GetObject(pipedId, OpenMode.ForRead) as Pipe;
                            Point3d pt1 = pipe.StartPoint;
                            Point3d pt2 = pipe.EndPoint;
                            //double angle = Vector3d.XAxis.GetAngleTo(pt2 - pt1);
                            double angle = Vector3d.XAxis.GetAngleTo(pt1.GetVectorTo(pt2), Vector3d.ZAxis);
                            str.Rotation = angle;

                        }


                    }
                }&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 24 Jan 2024 12:12:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12517614#M2589</guid>
      <dc:creator>hosneyalaa</dc:creator>
      <dc:date>2024-01-24T12:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: want to rotate structures with pipe network</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12519277#M2590</link>
      <description>&lt;P&gt;Thank you, it's working just flawless&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beating_heart:"&gt;💓&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2024 06:15:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/want-to-rotate-structures-with-pipe-network/m-p/12519277#M2590</guid>
      <dc:creator>goswami12897</dc:creator>
      <dc:date>2024-01-25T06:15:08Z</dc:date>
    </item>
  </channel>
</rss>

