Exemplo n.º 1
0
        /// <summary>
        /// 获取文档中所有可读族的拉伸体信息
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        private Dictionary <string, List <SketchData> > GetProfileDictFromDocument(Document doc)
        {
            Dictionary <string, List <SketchData> > dictFamilyProfile = new Dictionary <string, List <SketchData> >();

            FilteredElementCollector elemTypeCtor = (new FilteredElementCollector(doc)).WhereElementIsNotElementType();
            var elems = elemTypeCtor.ToElements();

            foreach (var elem in elems)
            {
                var fml = elem as Family;
                if (fml != null)
                {
                    try
                    {
                        var fmldoc = doc.EditFamily(fml);
                        if (fmldoc != null)
                        {
                            var        fec        = (new FilteredElementCollector(fmldoc)).WhereElementIsNotElementType();
                            var        tmpElems   = fec.ToElements();
                            SketchData sketchData = null;
                            foreach (var tmpElem in tmpElems)
                            {
                                if (tmpElem is GenericForm)
                                {
                                    if (tmpElem is Sweep)
                                    {
                                        sketchData = GetDataFromProfile((tmpElem as Sweep).ProfileSketch);
                                    }
                                    else if (tmpElem is Extrusion)
                                    {
                                        sketchData = GetDataFromProfile((tmpElem as Extrusion).Sketch);
                                    }
                                }
                            }

                            if (sketchData != null)
                            {
                                if (dictFamilyProfile.ContainsKey(fml.Name))
                                {
                                    dictFamilyProfile[fml.Name].Add(sketchData);
                                }
                                else
                                {
                                    dictFamilyProfile[fml.Name] = new List <SketchData> {
                                        sketchData
                                    }
                                };
                            }

                            fmldoc.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }

            return(dictFamilyProfile);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取指定拉伸体的拉伸面信息
        /// </summary>
        /// <param name="skt"></param>
        /// <returns></returns>
        private SketchData GetDataFromProfile(Sketch skt)
        {
            if (skt == null)
            {
                return(null);
            }

            var sketchData = new SketchData();

            foreach (object curArr in skt.Profile)
            {
                if (curArr is CurveArray)
                {
                    foreach (var cur in (CurveArray)curArr)
                    {
                        var curve = (Curve)cur;
                        if (curve != null && curve.IsBound)
                        {
                            CurveData curvedata = new CurveData();

                            if (curve is Arc)
                            {
                                var arc = (Arc)curve;
                                curvedata.IsArc          = true;
                                curvedata.Center         = new PointData(arc.Center.X, arc.Center.Y, arc.Center.Z);
                                curvedata.Normal         = new PointData(arc.Normal.X, arc.Normal.Y, arc.Normal.Z);
                                curvedata.StartParameter = arc.GetEndParameter(0);
                                curvedata.EndParameter   = arc.GetEndParameter(1);
                                curvedata.Radius         = arc.Radius;
                                var pt = arc.GetEndPoint(0);
                                curvedata.Points.Add(new PointData(pt.X, pt.Y, pt.Z));
                                pt = arc.GetEndPoint(1);
                                curvedata.Points.Add(new PointData(pt.X, pt.Y, pt.Z));
                            }
                            else
                            {
                                curvedata.IsArc = false;
                                var points = curve.Tessellate();
                                foreach (var point in points)
                                {
                                    curvedata.Points.Add(new PointData(point.X, point.Y, point.Z));
                                }
                            }

                            sketchData.Curves.Add(curvedata);
                        }
                    }
                }
            }

            if (sketchData.Curves.Count < 1)
            {
                return(null);
            }

            var plan = skt.SketchPlane.GetPlane();

            sketchData.Normal  = new PointData(plan.Normal.X, plan.Normal.Y, plan.Normal.Z);
            sketchData.Origin  = new PointData(plan.Origin.X, plan.Origin.Y, plan.Origin.Z);
            sketchData.XVector = new PointData(plan.XVec.X, plan.XVec.Y, plan.XVec.Z);
            sketchData.YVector = new PointData(plan.YVec.X, plan.YVec.Y, plan.YVec.Z);

            return(sketchData);
        }