Ejemplo n.º 1
0
        static private bool RecursionObject(GeometryElement geometryElement, ref List <GeometryObject> geometryObjects)
        {
            if (geometryElement == null)
            {
                return(false);
            }

            IEnumerator <GeometryObject> geometryObjectEnum = geometryElement.GetEnumerator();

            while (geometryObjectEnum.MoveNext())
            {
                GeometryObject currentGeometryObject = geometryObjectEnum.Current;
                var            type = currentGeometryObject.GetType();
                if (type.Equals(typeof(GeometryInstance)))
                {
                    RecursionObject((currentGeometryObject as GeometryInstance).GetInstanceGeometry(), ref geometryObjects);
                }
                else if (type.Equals(typeof(GeometryElement)))
                {
                    RecursionObject(currentGeometryObject as GeometryElement, ref geometryObjects);
                }
                else/* if (type.Equals(typeof(Solid)))*/
                {
                    geometryObjects.Add(currentGeometryObject);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        private void UpdateGeometry(List <object> geomObjs)
        {
            if (geomObjs.Count != _previousIds.Count || geomObjs.Count != _previousRefs.Count)
            {
                throw new InvalidOperationException("Cannot update geometry, counts dont match");
            }

            Transaction trans = new Transaction(_document);

            trans.Start("pipe_pull_update");
            for (int i = 0; i < geomObjs.Count; i++)
            {
                Element        elem    = _document.GetElement(_previousIds[i]);
                GeometryObject oldGeom = elem.GetGeometryObjectFromReference(_previousRefs[i]);
                if (oldGeom.GetType() != geomObjs[i].GetType())
                {
                    continue;
                }
                if (typeof(ModelCurve).IsAssignableFrom(elem.GetType()) && typeof(Curve).IsAssignableFrom(geomObjs[i].GetType()))
                {
                    ModelCurve curveElem = (ModelCurve)elem;
                    curveElem.SetGeometryCurve((Curve)geomObjs[i], true);
                }
            }
            trans.Commit();
        }
Ejemplo n.º 3
0
        private bool GeometryTypeMatch()
        {
            if (_receivedObjects.Count == 0)
            {
                return(false);
            }
            if (_receivedObjects.Count != _previousIds.Count)
            {
                return(false);
            }
            if (_receivedObjects.Count != _previousRefs.Count)
            {
                return(false);
            }
            for (int i = 0; i < _receivedObjects.Count; i++)
            {
                Element oldElem = _document.GetElement(_previousIds[i]);
                if (oldElem == null)
                {
                    return(false);
                }
                GeometryObject oldGeom = oldElem.GetGeometryObjectFromReference(_previousRefs[i]);
                if (oldGeom.GetType() != _receivedObjects[i].GetType())
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        //其他方法
        private void GeometryData(Element e)
        {
            if (e == null)
            {
                return;
            }
            Options op = CommandData.Application.Application.Create.NewGeometryOptions();

            //opt.View = currentView;
            op.ComputeReferences = false;
            GeometryElement ge = e.get_Geometry(op);

            IEnumerator <GeometryObject> os = ge.GetEnumerator();

            while (os.MoveNext())
            {
                GeometryObject o       = os.Current;
                string         geoType = o.GetType().Name;
                switch (geoType)
                {
                case "Solid":
                    SolidData(o);
                    break;

                case "Face":
                    break;

                case "Mesh":
                    MeshData(o);
                    break;

                case "Curve":
                case "Line":
                case "Arc":
                    break;

                case "Profile":
                    break;

                case "Element":
                    break;

                case "Instance":
                    break;

                case "Edge":
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// iterate GeometryObject in GeometryObjectArray and generate data accordingly
        /// </summary>
        /// <param name="objects"></param>
        /// <param name="transform"></param>
        private void AddGeometryObjects(IEnumerator <GeometryObject> objects, Transform transform)
        {
            //foreach (GeometryObject o in objects)
            while (objects.MoveNext())
            {
                GeometryObject o = objects.Current;

                //if the type of the geometric primitive is Solid
                string geoType = o.GetType().Name;
                switch (geoType)
                {
                case "Solid":
                    AddSolid(o, transform);
                    break;

                case "Face":
                    AddFace(o, transform);
                    break;

                case "Mesh":
                    AddMesh(o, transform);
                    break;

                case "Curve":
                case "Line":
                case "Arc":
                    AddCurve(o, transform);
                    break;

                case "Profile":
                    AddProfile(o, transform);
                    break;

                case "Element":
                    AddGeoElement(o, transform);
                    break;

                case "Instance":
                    AddInstance(o, transform);
                    break;

                case "Edge":
                    AddEdge(o, transform);
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 6
0
        private void Stream(ArrayList data, GeometryObject geomObj)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(GeometryObject)));

            data.Add(new Snoop.Data.Bool("IsElementGeometry", geomObj.IsElementGeometry));

            data.Add(new Snoop.Data.String("Visibility", geomObj.Visibility.ToString()));
            data.Add(new Snoop.Data.ElementId("GraphicStyleId", geomObj.GraphicsStyleId, m_activeDoc));

            data.Add(new Snoop.Data.String("Type", geomObj.GetType().Name));

            Curve crv = geomObj as Curve;
            if (crv != null)
            {
                Stream(data, crv);
                return;
            }

            Edge edg = geomObj as Edge;
            if (edg != null)
            {
                Stream(data, edg);
                return;
            }

            GeometryElement elem = geomObj as GeometryElement;
            if (elem != null)
            {
                Stream(data, elem);
                return;
            }

            Face face = geomObj as Face;
            if (face != null)
            {
                Stream(data, face);
                return;
            }

            GeometryInstance inst = geomObj as GeometryInstance;
            if (inst != null)
            {
                Stream(data, inst);
                return;
            }

            Mesh mesh = geomObj as Mesh;
            if (mesh != null)
            {
                Stream(data, mesh);
                return;
            }

            Profile prof = geomObj as Profile;
            if (prof != null)
            {
                Stream(data, prof);
                return;
            }

            Solid solid = geomObj as Solid;
            if (solid != null)
            {
                Stream(data, solid);
                return;
            }

            Point point = geomObj as Point;
            if (point != null)
            {
                Stream(data, point);
                return;
            }
        }
        private void WriteElementGeometry(int elementId)
        {
            FilteredElementCollector viewCollector = new FilteredElementCollector(m_doc);

            viewCollector.OfClass(typeof(ViewPlan));
            Func <ViewPlan, bool> isLevel1FloorPlan = v => !v.IsTemplate && v.Name == "Level 1" && v.ViewType == ViewType.FloorPlan;

            m_targetView = viewCollector.Cast <ViewPlan>().First <ViewPlan>(isLevel1FloorPlan);

            Transaction createCurve = new Transaction(m_doc, "Create reference curves");

            createCurve.Start();
            const double xReferenceLocation = 30;
            Line         vLine = Line.CreateBound(new XYZ(xReferenceLocation, 0, 0), new XYZ(xReferenceLocation, 20, 0));

            m_vLine = m_doc.Create.NewDetailCurve(m_targetView, vLine);

            const double yReferenceLocation = -10;
            Line         hLine = Line.CreateBound(new XYZ(0, yReferenceLocation, 0), new XYZ(20, yReferenceLocation, 0));

            m_hLine = m_doc.Create.NewDetailCurve(m_targetView, hLine);
            createCurve.Commit();

            Element e = m_doc.GetElement(new ElementId(elementId));

            Options options = new Options();

            options.ComputeReferences        = true;
            options.IncludeNonVisibleObjects = true;
            options.View = m_targetView;

            GeometryElement geomElem = e.get_Geometry(options);

            foreach (GeometryObject geomObj in geomElem)
            {
                if (geomObj is Solid)
                {
                    WriteSolid((Solid)geomObj);
                }
                else if (geomObj is GeometryInstance)
                {
                    TraverseGeometryInstance((GeometryInstance)geomObj);
                }
                else
                {
                    m_writer.WriteLine("Something else - " + geomObj.GetType().Name);
                }
            }

            foreach (Curve curve in m_referencePlaneReferences)
            {
                // Try to get the geometry object from reference
                Reference      curveReference = curve.Reference;
                GeometryObject geomObj        = e.GetGeometryObjectFromReference(curveReference);

                if (geomObj != null)
                {
                    m_writer.WriteLine("Curve reference leads to: " + geomObj.GetType().Name);
                }
            }

            // Dimension to reference curves
            foreach (Curve curve in m_referencePlaneReferences)
            {
                DetailCurve targetLine = m_vLine;

                Line line           = (Line)curve;
                XYZ  lineStartPoint = line.GetEndPoint(0);
                XYZ  lineEndPoint   = line.GetEndPoint(1);
                XYZ  direction      = lineEndPoint - lineStartPoint;
                Line dimensionLine  = null;
                if (Math.Abs(direction.Y) < 0.0001)
                {
                    targetLine = m_hLine;
                    XYZ dimensionLineStart = new XYZ(lineStartPoint.X + 5, lineStartPoint.Y, 0);
                    XYZ dimensionLineEnd   = new XYZ(dimensionLineStart.X, dimensionLineStart.Y + 10, 0);

                    dimensionLine = Line.CreateBound(dimensionLineStart, dimensionLineEnd);
                }
                else
                {
                    targetLine = m_vLine;
                    XYZ dimensionLineStart = new XYZ(lineStartPoint.X, lineStartPoint.Y + 5, 0);
                    XYZ dimensionLineEnd   = new XYZ(dimensionLineStart.X + 10, dimensionLineStart.Y, 0);
                    dimensionLine = Line.CreateBound(dimensionLineStart, dimensionLineEnd);
                }

                ReferenceArray references = new ReferenceArray();
                references.Append(curve.Reference);
                references.Append(targetLine.GeometryCurve.Reference);

                Transaction t = new Transaction(m_doc, "Create dimension");
                t.Start();
                m_doc.Create.NewDimension(m_targetView, dimensionLine, references);
                t.Commit();
            }
        }
Ejemplo n.º 8
0
        Stream(ArrayList data, GeometryObject geomObj)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(GeometryObject)));

            data.Add(new Snoop.Data.Bool("IsElementGeometry", geomObj.IsElementGeometry));

            data.Add(new Snoop.Data.String("Visibility", geomObj.Visibility.ToString()));
            data.Add(new Snoop.Data.ElementId("GraphicStyleId", geomObj.GraphicsStyleId, m_activeDoc));

            data.Add(new Snoop.Data.String("Type", geomObj.GetType().Name));

            Curve crv = geomObj as Curve;

            if (crv != null)
            {
                Stream(data, crv);
                return;
            }

            Edge edg = geomObj as Edge;

            if (edg != null)
            {
                Stream(data, edg);
                return;
            }

            GeometryElement elem = geomObj as GeometryElement;

            if (elem != null)
            {
                Stream(data, elem);
                return;
            }

            Face face = geomObj as Face;

            if (face != null)
            {
                Stream(data, face);
                return;
            }

            GeometryInstance inst = geomObj as GeometryInstance;

            if (inst != null)
            {
                Stream(data, inst);
                return;
            }

            Mesh mesh = geomObj as Mesh;

            if (mesh != null)
            {
                Stream(data, mesh);
                return;
            }

            Profile prof = geomObj as Profile;

            if (prof != null)
            {
                Stream(data, prof);
                return;
            }

            Solid solid = geomObj as Solid;

            if (solid != null)
            {
                Stream(data, solid);
                return;
            }

            Point point = geomObj as Point;

            if (point != null)
            {
                Stream(data, point);
                return;
            }
        }
Ejemplo n.º 9
0
 public bool Filter(GeometryObject go)
 {
     return(go.GetType() == Type);
 }