Beispiel #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Grevit.Types.Component component = null;

            DA.GetData <Grevit.Types.Component>("GrevitComponent", ref component);

            if (component == null)
            {
                DA.SetData("ID", new GH_String(""));
            }
            else
            {
                DA.SetData("ID", new GH_String(component.GID));
            }
        }
        /// <summary>
        /// Invoke the Components Create Method
        /// </summary>
        /// <param name="component"></param>
        public static void Build(this Grevit.Types.Component component, bool useReferenceElement)
        {
            // Create a new transaction
            //Transaction transaction = new Transaction(GrevitBuildModel.document, "GrevitCreate");
            //transaction.Start();

            // Get the components type
            Type type = component.GetType();

            // Get the Create extension Method using reflection
            IEnumerable <System.Reflection.MethodInfo> methods = Grevit.Reflection.Utilities.GetExtensionMethods(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Assembly, type);

            // Check all extensions methods (should only be Create() anyway)
            foreach (System.Reflection.MethodInfo method in methods)
            {
                // get the methods parameters
                object[] parameters = new object[method.GetParameters().Length];

                // As it is an extension method, the first parameter is the component itself
                parameters[0] = component;



                #region usingReferenceElement

                // if we should use a reference element to invoke the Create method
                // and parameter length equals 2
                // get the components referenceGID, see if it has been created already
                // use this element as a parameter to invoke Create(Element element)
                if (useReferenceElement && parameters.Length == 2)
                {
                    // Get the components reference GID
                    System.Reflection.PropertyInfo propertyReferenceGID = type.GetProperty("referenceGID");

                    // Return if there is no reference GID property
                    if (propertyReferenceGID == null)
                    {
                        return;
                    }

                    // Get the referene GID string value
                    string referenceGID = (string)propertyReferenceGID.GetValue(component);

                    // If the reference has been created already, get
                    // the Element from the document and apply it as parameter two
                    if (GrevitBuildModel.created_Elements.ContainsKey(referenceGID))
                    {
                        Element referenceElement = GrevitBuildModel.document.GetElement(GrevitBuildModel.created_Elements[referenceGID]);
                        parameters[1] = referenceElement;
                    }
                }

                #endregion



                // If the create method exists
                if (method != null && method.Name.EndsWith("Create"))
                {
                    // Invoke the Create Method without parameters
                    Element createdElement = (Element)method.Invoke(component, parameters);

                    // If the return value is valud set the parameters
                    if (createdElement != null)
                    {
                        component.SetParameters(createdElement);
                        component.StoreGID(createdElement.Id);
                    }
                }
            }

            // commit and dispose the transaction
            //transaction.Commit();
            //transaction.Dispose();
        }
Beispiel #3
0
        /// <summary>
        /// Converts a List of Grevit Curves to Revit Curves
        /// </summary>
        /// <param name="document">Active Document</param>
        /// <param name="grevitCurves">List of Grevit Curves</param>
        /// <returns>List of Revit Curves</returns>
        public static List<Curve> GrevitCurvesToRevitCurves(Component component)
        {
            List<Curve> curvesOut = new List<Curve>();

            if (component.GetType() == typeof(Grevit.Types.Line))
            {
                Grevit.Types.Line line = (Grevit.Types.Line)component;
                curvesOut.Add(Autodesk.Revit.DB.Line.CreateBound(line.from.ToXYZ(), line.to.ToXYZ()));
            }
            else if (component.GetType() == typeof(Grevit.Types.Arc))
            {
                Grevit.Types.Arc arc = (Grevit.Types.Arc)component;
                curvesOut.Add(Autodesk.Revit.DB.Arc.Create(arc.center.ToXYZ(), arc.radius, arc.start, arc.end, XYZ.BasisX, XYZ.BasisY));
            }
            else if (component.GetType() == typeof(Grevit.Types.Curve3Points))
            {
                Grevit.Types.Curve3Points curve3points = (Grevit.Types.Curve3Points)component;
                curvesOut.Add(Autodesk.Revit.DB.Arc.Create(curve3points.a.ToXYZ(), curve3points.c.ToXYZ(), curve3points.b.ToXYZ()));
            }
            else if (component.GetType() == typeof(Grevit.Types.PLine))
            {
                Grevit.Types.PLine pline = (Grevit.Types.PLine)component;

                for (int i = 0; i < pline.points.Count - 1; i++)
                {
                    curvesOut.Add(Autodesk.Revit.DB.Line.CreateBound(pline.points[i].ToXYZ(), pline.points[i + 1].ToXYZ()));
                }
            }
            else if (component.GetType() == typeof(Spline))
            {
                Spline spline = (Spline)component;
                IList<XYZ> points = new List<XYZ>();
                foreach (Grevit.Types.Point point in spline.controlPoints) points.Add(point.ToXYZ());
                NurbSpline ns = NurbSpline.Create(points, spline.weights);
                ns.isClosed = spline.isClosed;
                curvesOut.Add(ns);
            }

            return curvesOut;
        }
Beispiel #4
0
 public Wall(string familyOrStyle, string typeOrLayer, List<Parameter> parameters, Component curve, string levelbottom, double height, bool join, bool flip)
 {
     this.FamilyOrStyle = familyOrStyle;
     this.TypeOrLayer = typeOrLayer;
     this.parameters = parameters;
     this.curve = curve;
     this.levelbottom = levelbottom;
     this.height = height;
     this.join = join;
     this.flip = flip;
 }