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));
            }
        }
Example #2
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));
            }
        }