.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Convert Polyline to Conduit or Cable Tray

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
jtm2020hyo
2571 Views, 7 Replies

Convert Polyline to Conduit or Cable Tray

as the title says, this is possible?

 

PD: I am using AUTOCAD MEP

7 REPLIES 7
Message 2 of 8
Keith.Brown
in reply to: jtm2020hyo

I do not believe that it is.  Some tools available in other disciplines are not always available in all disciplines.

Message 3 of 8
Keith.Brown
in reply to: Keith.Brown

I am sorry, I opened this from my email and did not realize that this was the .NET forum and thought you were asking about normal MEP process.

 

Of course this is possible with .NET.  You have to analyze the polyline and get the vector directions of each vertice that changes direction in the polyline.  Then you need to select a conduit or a cable tray routing preference and select the appropriate part for the bend.  Then you would create the part and place it in the correct direction at the change of direction vertices of the polyline.  Once you have inserted all of your bends, then you would connect them with straight conduit or cable tray.  Don't forget you would need to also assign a size to the conduit or cable tray along with a system.

 

I would classify this as a very advanced process to undertake and you would need to conquer the basics first such as understanding routing preferences, system definitions, and how to select parts from the catalogs.  There are examples in the sample directory on how to select and place parts.  The routing preferences and system definitions are somewhat easier.

Message 4 of 8
jtm2020hyo
in reply to: Keith.Brown

Hi, sorry for the late answers.

 

I do not know how to start in .NET, so I was searching for a solved post, no luck. I have a question, why this is not a default in AutoCAD MEP? exist an option for convert polyline to pipes, pipe flex, wire, etc, but why not add a conversion polyline to conduit? exist some restrictions?

Message 5 of 8
jtm2020hyo
in reply to: Keith.Brown


@Keith.Brown wrote:

I am sorry, I opened this from my email and did not realize that this was the .NET forum and thought you were asking about normal MEP process.

 

Of course this is possible with .NET.  You have to analyze the polyline and get the vector directions of each vertice that changes direction in the polyline.  Then you need to select a conduit or a cable tray routing preference and select the appropriate part for the bend.  Then you would create the part and place it in the correct direction at the change of direction vertices of the polyline.  Once you have inserted all of your bends, then you would connect them with straight conduit or cable tray.  Don't forget you would need to also assign a size to the conduit or cable tray along with a system.

 

I would classify this as a very advanced process to undertake and you would need to conquer the basics first such as understanding routing preferences, system definitions, and how to select parts from the catalogs.  There are examples in the sample directory on how to select and place parts.  The routing preferences and system definitions are somewhat easier.


hi, again Mr.

can you share any sample? or example? or maybe if possible a video?

... because, I do not where start.

Message 6 of 8
Keith.Brown
in reply to: jtm2020hyo

This is some code that when ran in AutoCAD MEP will insert 3 straight cable tray fittings, an elbow, and three more straight fittings.  There is plenty on the internet to select a polyline and traverse.  

 

I threw this code together super fast and there is no error checking.  Ran and tested in AutoCAD MEP 2021.

First the command method to run the code.

        [CommandMethod("KabMepExamples", "KabCableTrayAdd", CommandFlags.Modal)]
        public void CableTrayAddExampleCommand()
        {
            ElectricCableTray.CableTrayAdd(new Point3d(0, 0, 0), new Point3d(60, 0, 0));
            ElectricCableTray.CableTrayAdd(new Point3d(60, 0, 0), new Point3d(120, 0, 0));
            ElectricCableTray.CableTrayAdd(new Point3d(120, 0, 0), new Point3d(180, 0, 0));
            ElectricCableTray.CableTrayFittingAdd(new Point3d(180.0, -18, 0));
            ElectricCableTray.CableTrayAdd(new Point3d(198, -18, 0), new Point3d(198, -78, 0));
            ElectricCableTray.CableTrayAdd(new Point3d(198, -78, 0), new Point3d(198, -138, 0));
            ElectricCableTray.CableTrayAdd(new Point3d(198, -138, 0), new Point3d(198, -208, 0));
        }

 

And then the main class that adds the cable tray and the fitting.

 

namespace Kab.Mep.Examples
{
    using System;

    using Autodesk.Aec.Building.ApplicationServices;
    using Autodesk.Aec.Building.DatabaseServices;
    using Autodesk.Aec.Building.Elec.DatabaseServices;
    using Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.Geometry;

    using Kab.Acad.Core;

    internal static class ElectricCableTray
    {
        internal static ObjectId CableTrayFittingAdd(Point3d centerPoint)
        {
            using (Transaction transaction = Active.Database.TransactionManager.StartTransaction())
            {
                CableTrayFitting cableTrayFitting = new CableTrayFitting();
                cableTrayFitting.SetToStandard(Active.Database);
                cableTrayFitting.SetDatabaseDefaults(Active.Database);
                DataQuery dataQuery = new DataQuery();
                dataQuery.Domain = Domain.CableTrayComponent;
                dataQuery.PartGuid = "548C6AF7-E846-42AB-AA6C-34ABD407A6DC";
                dataQuery.AddSizeParameter(Context.CatalogPartSizeName, 0, "12x6 inch 90 degree Cable Tray 12 Inch Radius Elbow Trough US Imperial");
                DataExpandedTable dataExpandedTable = PartManager.GetPartTable(dataQuery, 10);
                DataRecordCollection dataRecordCollection = dataExpandedTable.DataRecords;

                if (dataRecordCollection.Count > 0)
                {
                    DataRecord dataRecord = dataRecordCollection[0];
                    PartManager.CreatePartViaRecord(dataExpandedTable, dataRecord, cableTrayFitting);
                }
                else
                {
                    transaction.Abort();
                    Active.WriteMessage($"\nCable Tray Fitting {dataQuery.PartGuid} is not found in the part catalog.");
                    return ObjectId.Null;
                }

                cableTrayFitting.Rotation = Math.PI / -2;
                cableTrayFitting.Location = centerPoint;
                cableTrayFitting.Normal = Vector3d.ZAxis;
                cableTrayFitting.SetDefaultLayer();

                BlockTable blockTable = transaction.GetObject(Active.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                blockTableRecord.AppendEntity(cableTrayFitting);
                transaction.AddNewlyCreatedDBObject(cableTrayFitting, true);
                transaction.Commit();
                return cableTrayFitting.ObjectId;

            }
        }

        internal static ObjectId CableTrayAdd(Point3d startPoint, Point3d endPoint)
        {
            using (Transaction transaction = Active.Database.TransactionManager.StartTransaction())
            {
                CableTray cableTray = new CableTray();
                cableTray.SetToStandard(Active.Database);
                cableTray.SetDatabaseDefaults(Active.Database);
                DataQuery dataQuery = new DataQuery();
                dataQuery.Domain = Domain.CableTrayComponent;
                dataQuery.PartGuid = "60250FB7-3B15-11D5-8F1F-0010B5481882";
                dataQuery.AddSizeParameter(Context.CatalogPartSizeName, 0, "12x6 inch Cable Trays Trough US Imperial");
                DataExpandedTable dataExpandedTable = PartManager.GetPartTable(dataQuery, 10);
                DataRecordCollection dataRecordCollection = dataExpandedTable.DataRecords;

                if (dataRecordCollection.Count > 0)
                {
                    DataRecord dataRecord = dataRecordCollection[0];
                    PartManager.CreatePartViaRecord(dataExpandedTable, dataRecord, cableTray);
                }
                else
                {
                    transaction.Abort();
                    Active.WriteMessage($"\nCable Tray {dataQuery.PartGuid} is not found in the part catalog.");
                    return ObjectId.Null;
                }

                cableTray.SetBaseCurve(new LineSegment3d(startPoint, endPoint), Vector3d.ZAxis);
                cableTray.SetDefaultLayer();

                BlockTable blockTable = transaction.GetObject(Active.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                blockTableRecord.AppendEntity(cableTray);
                transaction.AddNewlyCreatedDBObject(cableTray, true);
                transaction.Commit();
                return cableTray.ObjectId;
            }
        }
    }
}

 

Finally a small video showing the command being ran.

 

 

I left the traversal of the polyline up to you.  If i have time tomorrow I will write some code that gets the routing preference and uses the cable tray and the cable tray elbow from the preference instead of hard coding it.

Message 7 of 8
jtm2020hyo
in reply to: Keith.Brown

awesome production, now I am a fan. thanks the help, I will do my best to solve this issue.

 

Message 8 of 8
jtm2020hyo
in reply to: Keith.Brown

Hi again Mr.

 

... I found a video related to this post, maybe you are interesting:

 

https://www.youtube.com/watch?v=DKiZPP0Qv14 

 

 

In the video, the creator replaces a polyline with cable tray blocks, with properties like length, angle, width.

 

... this video is part of a conjunct of lisp recollected by the video creator, I did not found the original source of the cable tray, but maybe can be useful for inspiration.

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report