it indeed did not help hehe 🙂
in my case all the swept solids were created by sweeping a circle around the path
So for my situation the following solution does the job.
I can ignore the 5 first grip points as they will always be the grip points of the sweep element (a circle)
i then stay left with the grip points of the sweep path
i further then check if the grips are the middle grips or not, in case they are i remove them from my list where i store all the grips
here is the code i ended up for now (that is by far not an optimized solution, but it does its job for now, if anyone has better solutions/ideas just keep them comin:) 😞
/// <summary>
/// gets the middle of two points
/// </summary>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <returns></returns>
public static Point3d GetMiddlePoint(Point3d p1, Point3d p2)
{
LineSegment3d temporaryLine = new LineSegment3d(p1, p2);
return temporaryLine.MidPoint;
}
/// <summary>
/// checks if the point is a middle point of the previous and following point
/// </summary>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <param name="testingPoint"></param>
/// <returns></returns>
public static bool IsMidPointOfVertices(Point3d p1, Point3d p2, Point3d testingPoint)
{
if (GetMiddlePoint(p1, p2) == testingPoint)
return true;
return false;
}
/// <summary>
/// Label all the vertex points in a swept 3d solid
/// only works if the sweep element is a circle
/// </summary>
[CommandMethod("GripPoint")]
static public void GripPoint()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
// Prompt for selection of a solid to be traversed
PromptEntityOptions prEntOpt = new PromptEntityOptions("\nSelect a 3D solid:");
prEntOpt.SetRejectMessage("\nMust be a 3D solid.");
prEntOpt.AddAllowedClass(typeof(Solid3d), true);
PromptEntityResult prEntRes = ed.GetEntity(prEntOpt);
ObjectId[] objIds = { prEntRes.ObjectId };
Solid3d en = (Solid3d)tr.GetObject(prEntRes.ObjectId, OpenMode.ForRead);
// declaring needed variables for GetGripPoints() method
GripDataCollection gripsTotalAmount = new GripDataCollection();
double curViewUnitSize = 0;
int gripSize = 0;
Vector3d curViewDir = doc.Editor.GetCurrentView().ViewDirection;
GetGripPointsFlags bitFlags = GetGripPointsFlags.GripPointsOnly;
en.GetGripPoints(gripsTotalAmount, curViewUnitSize, gripSize, curViewDir, bitFlags);
// if we have more than 8 vertices than we have a proper polyline (5 alone for the sweepcircle)
// so only if we have more than 8 we swap it into our list (from 5 till end of grips)
if (gripsTotalAmount.Count > 7)
{
List<GripData> polyLineGrips = new List<GripData>();
for (int counter = 5; counter < gripsTotalAmount.Count; counter++)
polyLineGrips.Add(gripsTotalAmount[counter]);
// loop through all polyline grips and see if we have middlepoint grips
// if we do, we remove them from the list
// starting from maxcount and going down so RemoveAt wont change the order
int whileCounter = polyLineGrips.Count - 2;
while (whileCounter > 0)
{
// check if current point is middlepoint and remove it fromt he list
// if that is the case
if (IsMidPointOfVertices(polyLineGrips[whileCounter - 1].GripPoint,
polyLineGrips[whileCounter + 1].GripPoint,
polyLineGrips[whileCounter].GripPoint))
{
polyLineGrips.RemoveAt(whileCounter);
}
whileCounter--;
}
// temporary for loop to showcase labelling (testing purpose only)
for (int counter = 0; counter < polyLineGrips.Count; counter++)
{
// Open the Block table record Model space for write
BlockTable acBlkTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
// Create a single-line text object
DBText acText = new DBText();
acText.SetDatabaseDefaults();
acText.Position = polyLineGrips[counter].GripPoint;
acText.Height = 0.05;
acText.TextString = Convert.ToString(counter + 1);
// Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acText);
tr.AddNewlyCreatedDBObject(acText, true);
}
}
tr.Commit();
}
catch (System.Exception ex)
{
ed.WriteMessage("\nException during traversal: {0}", ex.Message);
}
}
}