/// <summary>
 /// Adds tracking ids to a body faces and edges. This is not the best way to
 /// do this in a repeatable way but works quickly.
 /// </summary>
 /// <param name="macroFeatureData"></param>
 /// <param name="body"></param>
 public static int AddIdsToBody(this IMacroFeatureData macroFeatureData, IBody2 body, int i = 1)
 {
     if (body == null)
     {
         throw new ArgumentNullException(nameof(body));
     }
     {
         object FacesNeedId;
         object EdgesNeedId;
         macroFeatureData.GetEntitiesNeedUserId((object)body, out FacesNeedId, out EdgesNeedId);
         var edgesNeedId = (object[])EdgesNeedId;
         var facesNeedId = (object[])FacesNeedId;
         var empty       = new object[] {};
         foreach (var edge in edgesNeedId ?? empty)
         {
             if (!macroFeatureData.SetEdgeUserId((Edge)edge, i, 0))
             {
                 throw new Exception("SetUserIdFailed");
             }
             i++;
         }
         foreach (var face in facesNeedId ?? empty)
         {
             if (!macroFeatureData.SetFaceUserId((Face2)face, i, 0))
             {
                 throw new Exception("SetUserIdFailed");
             }
             i++;
         }
     }
     return(i);
 }
        private object GetBodyResult(ISldWorks app, IEnumerable <IBody2> bodies, IMacroFeatureData featData, bool updateEntityIds)
        {
            if (bodies != null)
            {
                if (CompatibilityUtils.IsVersionNewerOrEqual(app, SwVersion_e.Sw2013, 5))
                {
                    featData.EnableMultiBodyConsume = true;
                }

                if (updateEntityIds)
                {
                    if (featData == null)
                    {
                        throw new ArgumentNullException(nameof(featData));
                    }

                    foreach (var body in bodies)
                    {
                        object faces;
                        object edges;
                        featData.GetEntitiesNeedUserId(body, out faces, out edges);

                        if (faces is object[])
                        {
                            int nextId = 0;

                            foreach (Face2 face in faces as object[])
                            {
                                featData.SetFaceUserId(face, nextId++, 0);
                            }
                        }

                        if (edges is object[])
                        {
                            int nextId = 0;

                            foreach (Edge edge in edges as object[])
                            {
                                featData.SetEdgeUserId(edge, nextId++, 0);
                            }
                        }
                    }
                }

                if (bodies.Count() == 1)
                {
                    return(bodies.First());
                }
                else
                {
                    return(bodies.ToArray());
                }
            }
            else
            {
                throw new ArgumentNullException(nameof(bodies));
            }
        }
Exemple #3
0
        internal protected MacroFeatureRebuildBodyResult(IMacroFeatureData featData,
                                                         bool updateEntityIds, params IBody2[] bodies) : base(GetBodyResult(bodies))
        {
            if (Context.CurrentApp.IsVersionNewerOrEqual(SwVersion_e.Sw2013, 5))
            {
                featData.EnableMultiBodyConsume = true;
            }

            if (updateEntityIds)
            {
                if (featData == null)
                {
                    throw new ArgumentNullException(nameof(featData));
                }

                for (int i = 0; i < bodies.Length; i++)
                {
                    var body = bodies[i];

                    object faces;
                    object edges;
                    featData.GetEntitiesNeedUserId(body, out faces, out edges);

                    if (faces is object[])
                    {
                        int nextId = 0;

                        foreach (Face2 face in faces as object[])
                        {
                            featData.SetFaceUserId(face, nextId++, 0);
                        }
                    }

                    if (edges is object[])
                    {
                        int nextId = 0;

                        foreach (Edge edge in edges as object[])
                        {
                            featData.SetEdgeUserId(edge, nextId++, 0);
                        }
                    }
                }
            }
        }
Exemple #4
0
        private object GetBodyResult(ISldWorks app, IModelDoc2 model, IEnumerable <IBody2> bodies,
                                     IMacroFeatureData featData, bool updateEntityIds)
        {
            if (bodies != null)
            {
                if (CompatibilityUtils.IsVersionNewerOrEqual(app, SwVersion_e.Sw2013, 5))
                {
                    featData.EnableMultiBodyConsume = true;
                }

                if (updateEntityIds)
                {
                    if (featData == null)
                    {
                        throw new ArgumentNullException(nameof(featData));
                    }

                    foreach (var body in bodies)
                    {
                        object faces;
                        object edges;
                        featData.GetEntitiesNeedUserId(body, out faces, out edges);

                        if (faces is object[])
                        {
                            var faceIds = (faces as object[]).ToDictionary(x => (Face2)x, x => new MacroFeatureEntityId());

                            AssignFaceIds(app, model, faceIds);

                            foreach (var faceId in faceIds)
                            {
                                featData.SetFaceUserId(faceId.Key, faceId.Value.FirstId, faceId.Value.SecondId);
                            }
                        }

                        if (edges is object[])
                        {
                            var edgeIds = (edges as object[]).ToDictionary(x => (Edge)x, x => new MacroFeatureEntityId());

                            AssignEdgeIds(app, model, edgeIds);

                            foreach (var edgeId in edgeIds)
                            {
                                featData.SetEdgeUserId(edgeId.Key, edgeId.Value.FirstId, edgeId.Value.SecondId);
                            }
                        }
                    }
                }

                if (bodies.Count() == 1)
                {
                    return(bodies.First());
                }
                else
                {
                    return(bodies.ToArray());
                }
            }
            else
            {
                throw new ArgumentNullException(nameof(bodies));
            }
        }