Esempio n. 1
0
 public static void StoreGID(this Grevit.Types.Component c, ObjectId id)
 {
     if (c.GID != null && id != ObjectId.Null && !Command.created_objects.ContainsKey(c.GID))
     {
         Command.created_objects.Add(c.GID, id);
     }
 }
 /// <summary>
 /// Store GID in create elements List
 /// </summary>
 /// <param name="component"></param>
 /// <param name="elementId">ElementId of created element</param>
 public static void StoreGID(this Grevit.Types.Component component, Autodesk.Revit.DB.ElementId elementId)
 {
     if (elementId != null &&
         component.GID != null &&
         !GrevitBuildModel.created_Elements.ContainsKey(component.GID))
     {
         GrevitBuildModel.created_Elements.Add(component.GID, elementId);
     }
 }
Esempio n. 3
0
        public static void SetParameters(this Grevit.Types.Component component, DBObject dbobject)
        {
            Document    doc = Application.DocumentManager.MdiActiveDocument;
            Database    db  = doc.Database;
            Transaction tr  = db.TransactionManager.StartTransaction();

            using (tr)
            {
                List <Grevit.Types.Parameter> parameters = component.parameters;

                if (parameters != null && parameters.Count > 0)
                {
                    ObjectIdCollection source_setIds = PropertyDataServices.GetPropertySets(dbobject);

                    foreach (Grevit.Types.Parameter param in parameters)
                    {
                        foreach (ObjectId source_id in source_setIds)
                        {
                            PropertySet source_pset            = (PropertySet)tr.GetObject(source_id, OpenMode.ForWrite, false, false);
                            PropertySetDataCollection allProps = source_pset.PropertySetData;
                            foreach (PropertySetData ii in allProps)
                            {
                                int    id    = ii.Id;
                                string name  = source_pset.PropertyIdToName(id);
                                object value = source_pset.GetAt(id);

                                if (name == param.name)
                                {
                                    if (value.GetType() == typeof(string))
                                    {
                                        source_pset.SetAt(id, param.value);
                                    }
                                    if (value.GetType() == typeof(double))
                                    {
                                        source_pset.SetAt(id, param.value);
                                    }
                                    if (value.GetType() == typeof(int))
                                    {
                                        source_pset.SetAt(id, param.value);
                                    }
                                    if (value.GetType() == typeof(bool))
                                    {
                                        source_pset.SetAt(id, param.value);
                                    }
                                }
                            }
                        }
                    }
                }

                tr.Commit();
            }
        }
Esempio n. 4
0
        public static void AddXData(this DBObject dbobject, Grevit.Types.Component comp, Transaction tr)
        {
            AddRegAppTableRecord("Grevit", tr);

            Entity ent = (Entity)tr.GetObject(dbobject.Id, OpenMode.ForWrite);

            ResultBuffer rbs = new ResultBuffer(new TypedValue(1001, "Grevit"), new TypedValue(1000, comp.GID));

            ent.XData = rbs;
            rbs.Dispose();

            ent.Dispose();
        }
Esempio n. 5
0
        public static Curve3dCollection To3dCurve(this Grevit.Types.Component curve)
        {
            Curve3dCollection curveArray = new Curve3dCollection();

            if (curve.GetType() == typeof(Grevit.Types.Line))
            {
                Grevit.Types.Line baseline = (Grevit.Types.Line)curve;
                curveArray.Add(new Line3d(baseline.from.ToPoint3d(), baseline.to.ToPoint3d()));
            }
            else if (curve.GetType() == typeof(Grevit.Types.Arc))
            {
                Grevit.Types.Arc baseline = (Grevit.Types.Arc)curve;
                curveArray.Add(new Arc(baseline.center.ToPoint3d(), baseline.radius, baseline.start, baseline.end).GetGeCurve());
            }
            else if (curve.GetType() == typeof(Grevit.Types.Curve3Points))
            {
                Grevit.Types.Curve3Points baseline = (Grevit.Types.Curve3Points)curve;
                curveArray.Add(new CircularArc3d(baseline.a.ToPoint3d(), baseline.c.ToPoint3d(), baseline.b.ToPoint3d()));
            }
            else if (curve.GetType() == typeof(Grevit.Types.PLine))
            {
                Grevit.Types.PLine baseline = (Grevit.Types.PLine)curve;
                for (int i = 0; i < baseline.points.Count - 1; i++)
                {
                    curveArray.Add(new Line3d(baseline.points[i].ToPoint3d(), baseline.points[i + 1].ToPoint3d()));
                }
            }
            else if (curve.GetType() == typeof(Grevit.Types.Spline))
            {
                Grevit.Types.Spline s      = (Grevit.Types.Spline)curve;
                Point3dCollection   points = new Point3dCollection();
                foreach (Grevit.Types.Point p in s.controlPoints)
                {
                    points.Add(p.ToPoint3d());
                }
                DoubleCollection dc = new DoubleCollection();
                foreach (double dbl in s.weights)
                {
                    dc.Add(dbl);
                }
                Spline sp = new Spline(s.degree, s.isRational, s.isClosed, s.isPeriodic, points, new DoubleCollection(), dc, 0, 0);
                curveArray.Add(sp.GetGeCurve());
            }

            return(curveArray);
        }
Esempio n. 6
0
        public static Curve2dCollection To2dCurve(this Grevit.Types.Component curve)
        {
            Curve2dCollection curveArray = new Curve2dCollection();

            if (curve.GetType() == typeof(Grevit.Types.Line))
            {
                Grevit.Types.Line baseline = (Grevit.Types.Line)curve;
                curveArray.Add(new Line2d(baseline.from.ToPoint2d(), baseline.to.ToPoint2d()));
            }
            else if (curve.GetType() == typeof(Grevit.Types.Arc))
            {
                Grevit.Types.Arc baseline = (Grevit.Types.Arc)curve;
                curveArray.Add(new CircularArc2d(baseline.center.ToPoint2d(), baseline.radius, baseline.start, baseline.end, Vector2d.XAxis, true));
            }
            else if (curve.GetType() == typeof(Grevit.Types.Curve3Points))
            {
                Grevit.Types.Curve3Points baseline = (Grevit.Types.Curve3Points)curve;
                curveArray.Add(new CircularArc2d(baseline.a.ToPoint2d(), baseline.c.ToPoint2d(), baseline.b.ToPoint2d()));
            }
            else if (curve.GetType() == typeof(Grevit.Types.PLine))
            {
                Grevit.Types.PLine baseline = (Grevit.Types.PLine)curve;
                for (int i = 0; i < baseline.points.Count - 1; i++)
                {
                    curveArray.Add(new Line2d(baseline.points[i].ToPoint2d(), baseline.points[i + 1].ToPoint2d()));
                }
            }
            else if (curve.GetType() == typeof(Grevit.Types.Spline))
            {
                Grevit.Types.Spline s      = (Grevit.Types.Spline)curve;
                Point2dCollection   points = new Point2dCollection();
                foreach (Grevit.Types.Point p in s.controlPoints)
                {
                    points.Add(p.ToPoint2d());
                }
                DoubleCollection dc = new DoubleCollection();
                foreach (double dbl in s.weights)
                {
                    dc.Add(dbl);
                }
                NurbCurve2d sp = new NurbCurve2d(s.degree, new KnotCollection(), points, dc, s.isPeriodic);
                curveArray.Add(sp);
            }

            return(curveArray);
        }
        /// <summary>
        /// Sets Parameter Values
        /// </summary>
        /// <param name="component"></param>
        /// <param name="element">The Element to apply parameters to</param>
        public static void SetParameters(this Grevit.Types.Component component, Element element)
        {
            if (element != null)
            {
                if (component.parameters != null)
                {
                    foreach (Grevit.Types.Parameter componentParameter in component.parameters)
                    {
                        int iid;
                        Autodesk.Revit.DB.Parameter elementParameter = null;

                        if (int.TryParse(componentParameter.name, out iid))
                        {
                            foreach (Autodesk.Revit.DB.Parameter p in element.Parameters)
                            {
                                if (p.Id.IntegerValue == iid)
                                {
                                    elementParameter = p;
                                }
                            }
                        }
                        else
                        {
                            elementParameter = element.LookupParameter(componentParameter.name);
                        }

                        if (elementParameter != null)
                        {
                            switch (elementParameter.StorageType)
                            {
                            case StorageType.Double:
                                if (componentParameter.value.GetType() == typeof(double))
                                {
                                    elementParameter.Set((double)componentParameter.value);
                                }
                                break;

                            case StorageType.Integer:
                                if (componentParameter.value.GetType() == typeof(int))
                                {
                                    elementParameter.Set((int)componentParameter.value);
                                }
                                break;

                            case StorageType.String:
                                if (componentParameter.value.GetType() == typeof(string))
                                {
                                    elementParameter.Set((string)componentParameter.value);
                                }
                                break;

                            case StorageType.ElementId:
                                if (componentParameter.value.GetType() == typeof(Grevit.Types.ElementID))
                                {
                                    Grevit.Types.ElementID grvid = (Grevit.Types.ElementID)componentParameter.value;
                                    ElementId id = new ElementId(grvid.ID);
                                    if (GrevitBuildModel.document.GetElement(id) != null)
                                    {
                                        elementParameter.Set(id);
                                    }
                                }
                                else if (componentParameter.value.GetType() == typeof(Grevit.Types.SearchElementID))
                                {
                                    Grevit.Types.SearchElementID grvid = (Grevit.Types.SearchElementID)componentParameter.value;
                                    Element e = GrevitBuildModel.document.GetElementByName(grvid.Name);
                                    if (e != null)
                                    {
                                        elementParameter.Set(e.Id);
                                    }
                                }

                                break;
                            }
                        }
                    }
                }


                Autodesk.Revit.DB.Parameter grevitIdParameter = element.LookupParameter("GID");

                if (grevitIdParameter == null)
                {
                    GrevitBuildModel.document.GrevitAddSharedParameter();
                    grevitIdParameter = element.LookupParameter("GID");
                }

                if (grevitIdParameter != null && !grevitIdParameter.IsReadOnly)
                {
                    grevitIdParameter.Set(component.GID);
                }
            }
        }
Esempio n. 8
0
        public static Point3dCollection To3dPointCollection(this Grevit.Types.Component curve)
        {
            Point3dCollection points = new Point3dCollection();

            if (curve.GetType() == typeof(Grevit.Types.Line))
            {
                Grevit.Types.Line baseline = (Grevit.Types.Line)curve;
                Point3d           p1       = baseline.from.ToPoint3d();
                Point3d           p2       = baseline.to.ToPoint3d();

                if (!points.Contains(p1))
                {
                    points.Add(p1);
                }
                if (!points.Contains(p2))
                {
                    points.Add(p2);
                }
            }
            else if (curve.GetType() == typeof(Grevit.Types.Arc))
            {
            }
            else if (curve.GetType() == typeof(Grevit.Types.Curve3Points))
            {
                Grevit.Types.Curve3Points baseline = (Grevit.Types.Curve3Points)curve;
                Point3d p1 = baseline.a.ToPoint3d();
                Point3d p2 = baseline.b.ToPoint3d();
                Point3d p3 = baseline.c.ToPoint3d();

                if (!points.Contains(p1))
                {
                    points.Add(p1);
                }
                if (!points.Contains(p2))
                {
                    points.Add(p2);
                }
                if (!points.Contains(p3))
                {
                    points.Add(p3);
                }
            }
            else if (curve.GetType() == typeof(Grevit.Types.PLine))
            {
                Grevit.Types.PLine baseline = (Grevit.Types.PLine)curve;
                for (int i = 0; i < baseline.points.Count; i++)
                {
                    Point3d p1 = baseline.points[i].ToPoint3d();
                    if (!points.Contains(p1))
                    {
                        points.Add(p1);
                    }
                }
            }
            else if (curve.GetType() == typeof(Grevit.Types.Spline))
            {
                Grevit.Types.Spline s = (Grevit.Types.Spline)curve;

                foreach (Grevit.Types.Point p in s.controlPoints)
                {
                    Point3d p1 = p.ToPoint3d();
                    if (!points.Contains(p1))
                    {
                        points.Add(p1);
                    }
                }
            }

            return(points);
        }