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();
}
}
}
}
Solved! Go to Solution.
Solved by Jeff_M. Go to Solution.
This line , i think not working in civil 2016 and above , check :heavy_check_mark:
ObjectId cgp = cogoPoints.Add(point3D, true);
@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.
how can I create groups for each individual alignments cogopoints please help
\
@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 "";
}
Can't find what you're looking for? Ask the community or share your knowledge.