Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to insert the table for these cogopoints created

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
goswami12897
370 Views, 7 Replies

How to insert the table for these cogopoints created

Hello I want to insert the table for the cogopoints created on each alignment separately how to do it?

    public class InsertPointsSop
    {
        [CommandMethod("InsertSOP")]

        public void Insert()
        {
            Document document = Application.DocumentManager.MdiActiveDocument;
            Database database = document.Database;
            Editor editor = document.Editor;

            editor.WriteMessage("\n Select Alignments");

            PromptSelectionResult blockSelected = editor.GetSelection();
            if (blockSelected.Status != PromptStatus.OK)
            {
                editor.WriteMessage("\n Selected wrong Objects. Please restart the command to try again");
                return;
            }
            PromptDoubleOptions intervalInput = new PromptDoubleOptions("\nEnter the interval of stations")
            {
                AllowNegative = false,
                AllowNone = false,
                AllowZero = false,
            };
            PromptDoubleResult intervals = editor.GetDouble(intervalInput);
            if (intervals.Status != PromptStatus.OK)
            {
                editor.WriteMessage("\n Wrong Input");
                return;
            }
            SelectionSet set = blockSelected.Value;
            using (Transaction transaction = database.TransactionManager.StartTransaction())
            {
                CivilDocument cDoc = CivilApplication.ActiveDocument;
                CogoPointCollection cogoPoints = cDoc.CogoPoints;
                foreach (SelectedObject obj in set)
                {
                   
                    if (obj.ObjectId.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Alignment))))
                    {
                        Alignment str = transaction.GetObject(obj.ObjectId, OpenMode.ForRead) as Alignment;
                        for (double j = 0; j < str.Length; j += intervals.Value)
                        {                           
                            Point3d point3D = str.GetPointAtDist(j);
                            ObjectId cgp = cogoPoints.Add(point3D, true);
                            CogoPoint cogoPoint = cgp.GetObject(OpenMode.ForWrite) as CogoPoint;
                            string modifiedName = $"Level : {str.Name}-{j}";
                            cogoPoint.PointName = modifiedName;
                            
                        }
                        
                    }

                }
                transaction.Commit();
            }

        }
    }
}
7 REPLIES 7
Message 2 of 8
hosneyalaa
in reply to: goswami12897

 

This line  , i think not working in civil 2016 and above , check :heavy_check_mark:

ObjectId cgp = cogoPoints.Add(point3D, true);

 

Message 3 of 8
goswami12897
in reply to: hosneyalaa

points are inserted successfully 

Message 4 of 8
hosneyalaa
in reply to: goswami12897

I am sorry, you are right 

Message 5 of 8
Jeff_M
in reply to: goswami12897

@goswami12897 the current API does not provide a method for adding PointTables. To help make it easier after creating the points, I would create a PointGroup for each alignment and add the created points to the associated group. That way the user can use the normal Create Table command and select the point group for the table.

Jeff_M, also a frequent Swamper
EESignature
Message 6 of 8
goswami12897
in reply to: Jeff_M

how can I create groups for each individual alignments cogopoints please help

\

Message 7 of 8
Jeff_M
in reply to: goswami12897

@goswami12897 here is your code with the points added to a new point group with the same name as the alignment:

 

    public class InsertPointsSop
    {
        [CommandMethod("InsertSOP")]
        public void Insert()
        {
            Document document = Application.DocumentManager.MdiActiveDocument;
            Database database = document.Database;
            Editor editor = document.Editor;
            PromptSelectionOptions promptSelectionOptions = new PromptSelectionOptions();
            promptSelectionOptions.MessageForAdding = "\n Select Alignments";
            SelectionFilter ssFilter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "AECC_ALIGNMENT") });
            PromptSelectionResult blockSelected = editor.GetSelection(promptSelectionOptions, ssFilter);
            if (blockSelected.Status != PromptStatus.OK)
            {
                editor.WriteMessage("\n Selected wrong Objects. Please restart the command to try again");
                return;
            }
            PromptDoubleOptions intervalInput = new PromptDoubleOptions("\nEnter the interval of stations")
            {
                AllowNegative = false,
                AllowNone = false,
                AllowZero = false,
            };
            PromptDoubleResult intervals = editor.GetDouble(intervalInput);
            if (intervals.Status != PromptStatus.OK)
            {
                editor.WriteMessage("\n Wrong Input");
                return;
            }
            SelectionSet set = blockSelected.Value;
            using (Transaction transaction = database.TransactionManager.StartTransaction())
            {
                CivilDocument cDoc = CivilApplication.ActiveDocument;
                CogoPointCollection cogoPoints = cDoc.CogoPoints;
                foreach (SelectedObject obj in set)
                {
                    var points = new List<uint>();
                    Alignment str = transaction.GetObject(obj.ObjectId, OpenMode.ForRead) as Alignment;
                    for (double j = 0; j < str.Length; j += intervals.Value)
                    {
                        Point3d point3D = str.GetPointAtDist(j);
                        ObjectId cgp = cogoPoints.Add(point3D, true);
                        CogoPoint cogoPoint = cgp.GetObject(OpenMode.ForWrite) as CogoPoint;
                        string modifiedName = $"Level : {str.Name}-{j}";
                        cogoPoint.PointName = modifiedName;
                        points.Add(cogoPoint.PointNumber);
                    }
                    if (points.Count > 0)
                    {
                        var ptGroupId = cDoc.PointGroups.Add(str.Name);
                        var ptGroup = (PointGroup)transaction.GetObject(ptGroupId, OpenMode.ForWrite);
                        var query = (StandardPointGroupQuery)ptGroup.GetQuery();
                        query.IncludeNumbers = getIncludeList(points);
                        ptGroup.SetQuery(query);
                    }
                }
                transaction.Commit();
            }
        }
        private string getIncludeList(List<uint> points)
        {
            uint[] ptNums = points.ToArray();
            string pointList = "";
            if (ptNums.GetLength(0) == 1)
            {
                pointList = ptNums[0].ToString();
            }
            if (ptNums.GetLength(0) > 1)
            {
                uint i = 0;
                uint startRange;
                int lastIndex = ptNums.GetLength(0) - 1;
                while (i <= lastIndex)
                {
                    startRange = ptNums[i];
                    while ((i < lastIndex) && (ptNums[i + 1] - ptNums[i] == 1))
                    {
                        ++i;
                    }
                    pointList += rangeBetweenNumbers(startRange, ptNums[i]);
                    if (i++ < lastIndex)
                        pointList += ",";
                }
            }
            return pointList;
        }
        private string rangeBetweenNumbers(uint startNum, uint endNum)
        {
            uint diff = endNum - startNum;
            if (diff == 0)
                return startNum.ToString();
            if (diff > 0)
                return startNum.ToString() + "-" + endNum.ToString();
            return "";
        }

 

Jeff_M, also a frequent Swamper
EESignature
Message 8 of 8
goswami12897
in reply to: Jeff_M

Thanks a lot 

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report