public void ConvertToSketchSegments(IModelDoc2 model, IBody2 body)
        {
            var transform = model.SketchManager.ActiveSketch.ModelToSketchTransform;

            model.SketchManager.AddToDB = true;

            foreach (var edge in (body.GetEdges() as object[]).Cast <IEdge>())
            {
                var curve = edge.IGetCurve();
                curve.ApplyTransform(transform);

                double start;
                double end;
                bool   isClosed;
                bool   isPeriodic;
                curve.GetEndParams(out start, out end, out isClosed, out isPeriodic);

                var startPt = curve.Evaluate2(start, 0) as double[];
                var endPt   = curve.Evaluate2(end, 0) as double[];

                if (curve.IsLine())
                {
                    model.SketchManager.CreateLine(startPt[0], startPt[1], startPt[2],
                                                   endPt[0], endPt[1], endPt[2]);
                }
                else if (curve.IsCircle())
                {
                    var circParam = curve.CircleParams as double[];
                    model.SketchManager.CreateArc(circParam[0], circParam[1], circParam[2],
                                                  startPt[0], startPt[1], startPt[2], endPt[0], endPt[1], endPt[2], (short)circParam[5]);
                }
                else
                {
                    throw new NotSupportedException();
                }
            }

            model.SketchManager.AddToDB = false;
        }
        private void CreateBodyForPreview(int trackCookie, ref List <IEdge> edges, ref IBody2 body)
        {
            var inputEdges = edges;

            try
            {
                for (int i = 0; i < inputEdges.Count; i++)
                {
                    var status = (swTrackingIDError_e)inputEdges[i].SetTrackingID(trackCookie, i);
                    if (status != swTrackingIDError_e.swTrackingIDError_NoError)
                    {
                        Logger.Log($"Failed to set tracking id: {status}");
                        throw new UserErrorException("Failed to track entity");
                    }
                }

                body = body.ICopy();

                var copiedEdges = body.GetEdges() as object[];

                if (copiedEdges != null)
                {
                    var trackedEdges = copiedEdges.Where(e =>
                    {
                        object trackIds;
                        if ((e as IEdge).GetTrackingIDs(trackCookie, out trackIds)
                            == (int)swTrackingIDError_e.swTrackingIDError_NoError)
                        {
                            if (trackIds != null && (trackIds as int[]).Length == 1)
                            {
                                if ((trackIds as int[]).First() < inputEdges.Count)
                                {
                                    return(true);
                                }
                            }

                            return(true);
                        }

                        return(false);
                    });

                    if (trackedEdges.Count() == inputEdges.Count)
                    {
                        edges = trackedEdges.Cast <IEdge>().ToList();
                    }
                    else
                    {
                        throw new UserErrorException("Failed to track entity");
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
                throw;
            }
            finally
            {
                inputEdges.ForEach(e =>
                {
                    var status = (swTrackingIDError_e)e.RemoveTrackingID(trackCookie);
                    if (status != swTrackingIDError_e.swTrackingIDError_NoError)
                    {
                        Logger.Log($"Failed to remove tracking id: {status}");
                        throw new UserErrorException("Failed to track entity");
                    }
                });
            }
        }