public SetRevitDataForm(LyrebirdChannel c, GHClient p)
        {
            parent = p;
            channel = c;

            InitializeComponent();

            // Position the form.
            Left = 0;
            Top = 0;
            //MessageBox.Show(string.Format("The system is {0} and the endpoint is:\n{1}", client.State.ToString(), client.Endpoint.Address.ToString()));
            if (channel != null)
            {
                try
                {
                    string test = channel.DocumentName();
                    if (test == null)
                    {
                        MessageBox.Show("Error!!!!!!!!!!");
                    }
                    RevitObject[] temp = channel.FamilyNames().ToArray();
                    if (temp != null && temp.Any())
                        familyNames = channel.FamilyNames().ToList();
                    else
                    {
                        MessageBox.Show("The Lyrebird Service for Revit could not be found.  Make sure the service is turned on and try again.");
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error\n" + ex.ToString());
                }
                if (familyNames != null && familyNames.Count > 0)
                {
                    familyComboBox.ItemsSource = familyNames;
                    familyComboBox.DisplayMemberPath = "FamilyName";
                    bool check = false;
                    if (parent.FamilyName != null)
                    {
                        for (int i = 0; i < familyNames.Count; i++)
                        {
                            string famName = familyNames[i].FamilyName;
                            if (famName == parent.FamilyName)
                            {
                                familyComboBox.SelectedIndex = i;
                                check = true;
                            }
                        }
                    }
                    if (!check)
                    {
                        familyComboBox.SelectedIndex = 0;
                    }
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            // Create the client connection
            LyrebirdChannel channel = new LyrebirdChannel(1);
            channel.Create();
            string message = channel.DocumentName();
            channel.Dispose();

            Console.WriteLine("Finished: " + message);
        }
Пример #3
0
        // Simple test to see if the communication is working  Just gets the project document name
        private void Menu_TestClicked(object sender, EventArgs e)
        {
            // Currently removed from the menu
            try
            {
                LyrebirdChannel channel = new LyrebirdChannel(appVersion);
                channel.Create();
                string test = channel.DocumentName() ?? "Failed to Collect Document Name";
                string write = "Document: " + test;
                System.Windows.Forms.MessageBox.Show(write);

                channel.Dispose();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
Пример #4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            bool runCommand = false;
            GH_Structure<GH_Point> origPoints = new GH_Structure<GH_Point>();
            GH_Structure<GH_Point> adaptPoints = new GH_Structure<GH_Point>();
            GH_Structure<GH_Curve> curves = new GH_Structure<GH_Curve>();
            GH_Structure<GH_Vector> orientations = new GH_Structure<GH_Vector>();
            GH_Structure<GH_Vector> faceOrientations = new GH_Structure<GH_Vector>();
            DA.GetData(0, ref runCommand);
            DA.GetDataTree(1, out origPoints);
            DA.GetDataTree(2, out adaptPoints);
            DA.GetDataTree(3, out curves);
            DA.GetDataTree(4, out orientations);
            DA.GetDataTree(5, out faceOrientations);

            // Make sure the family and type is set before running the command.
            if (runCommand && (familyName == null || familyName == "Not Selected"))
            {
                message = "Please select a family/type by double-clicking on the component before running the command.";
            }
            else if (runCommand)
            {
                // Get the scale
                GHInfo ghi = new GHInfo();
                GHScale scale = ghi.GetScale(Rhino.RhinoDoc.ActiveDoc);

                // Send to Revit
                LyrebirdChannel channel = new LyrebirdChannel(appVersion);
                channel.Create();

                if (channel != null)
                {
                    string documentName = channel.DocumentName();
                    if (documentName != null)
                    {
                        // Create RevitObjects
                        List<RevitObject> obj = new List<RevitObject>();

                        #region OriginPoint Based
                        if (origPoints != null && origPoints.Branches.Count > 0)
                        {
                            List<RevitObject> tempObjs = new List<RevitObject>();
                            // make sure the branches match the datacount
                            if (origPoints.Branches.Count == origPoints.DataCount)
                            {
                                for (int i = 0; i < origPoints.Branches.Count; i++)
                                {
                                    GH_Point ghpt = origPoints[i][0];
                                    LyrebirdPoint point = new LyrebirdPoint
                                    {
                                        X = ghpt.Value.X,
                                        Y = ghpt.Value.Y,
                                        Z = ghpt.Value.Z
                                    };

                                    RevitObject ro = new RevitObject
                                    {
                                        Origin = point,
                                        FamilyName = familyName,
                                        TypeName = typeName,
                                        Category = category,
                                        CategoryId = categoryId,
                                        GHPath = origPoints.Paths[i].ToString(),
                                        GHScaleFactor = scale.ScaleFactor,
                                        GHScaleName = scale.ScaleName
                                    };

                                    tempObjs.Add(ro);
                                }
                                obj = tempObjs;
                            }
                            else
                            {
                                // Inform the user they need to graft their inputs.  Only one point per branch
                                System.Windows.Forms.MessageBox.Show("Warning:\n\nEach Branch represents an object, " +
                                    "so origin point based elements should be grafted so that each point is on it's own branch.");
                            }
                        }
                        #endregion

                        #region AdaptiveComponents
                        else if (adaptPoints != null && adaptPoints.Branches.Count > 0)
                        {
                            // generate adaptive components
                            List<RevitObject> tempObjs = new List<RevitObject>();
                            for (int i = 0; i < adaptPoints.Branches.Count; i++)
                            {
                                RevitObject ro = new RevitObject();
                                List<LyrebirdPoint> points = new List<LyrebirdPoint>();
                                for (int j = 0; j < adaptPoints.Branches[i].Count; j++)
                                {
                                    LyrebirdPoint point = new LyrebirdPoint(adaptPoints.Branches[i][j].Value.X, adaptPoints.Branches[i][j].Value.Y, adaptPoints.Branches[i][j].Value.Z);
                                    points.Add(point);
                                }
                                ro.AdaptivePoints = points;
                                ro.FamilyName = familyName;
                                ro.TypeName = typeName;
                                ro.Origin = null;
                                ro.Category = category;
                                ro.CategoryId = categoryId;
                                ro.GHPath = adaptPoints.Paths[i].ToString();
                                ro.GHScaleFactor = scale.ScaleFactor;
                                ro.GHScaleName = scale.ScaleName;
                                tempObjs.Add(ro);
                            }
                            obj = tempObjs;

                        }
                        #endregion

                        #region Curve Based
                        else if (curves != null && curves.Branches.Count > 0)
                        {
                            // Get curves for curve based components

                            // Determine if we're profile or line based
                            if (curves.Branches.Count == curves.DataCount)
                            {
                                // Determine if the curve is a closed planar curve
                                Curve tempCrv = curves.Branches[0][0].Value;
                                if (tempCrv.IsPlanar(0.00000001) && tempCrv.IsClosed)
                                {
                                    // Closed planar curve
                                    List<RevitObject> tempObjs = new List<RevitObject>();
                                    for (int i = 0; i < curves.Branches.Count; i++)
                                    {
                                        Curve crv = curves[i][0].Value;
                                        List<Curve> rCurves = new List<Curve>();
                                        bool getCrvs = CurveSegments(rCurves, crv, true);
                                        if (rCurves.Count > 0)
                                        {
                                            RevitObject ro = new RevitObject();
                                            List<LyrebirdCurve> lbCurves = new List<LyrebirdCurve>();
                                            for (int j = 0; j < rCurves.Count; j++)
                                            {
                                                LyrebirdCurve lbc;
                                                lbc = GetLBCurve(rCurves[j]);
                                                lbCurves.Add(lbc);
                                            }
                                            ro.Curves = lbCurves;
                                            ro.FamilyName = familyName;
                                            ro.Category = category;
                                            ro.CategoryId = categoryId;
                                            ro.TypeName = typeName;
                                            ro.Origin = null;
                                            ro.GHPath = curves.Paths[i].ToString();
                                            ro.GHScaleFactor = scale.ScaleFactor;
                                            ro.GHScaleName = scale.ScaleName;
                                            tempObjs.Add(ro);
                                        }
                                    }
                                    obj = tempObjs;

                                }
                                else if (!tempCrv.IsClosed)
                                {
                                    // Line based.  Can only be arc or linear curves
                                    List<RevitObject> tempObjs = new List<RevitObject>();
                                    for (int i = 0; i < curves.Branches.Count; i++)
                                    {

                                        Curve ghc = curves.Branches[i][0].Value;
                                        // Test that there is only one curve segment
                                        PolyCurve polycurve = ghc as PolyCurve;
                                        if (polycurve != null)
                                        {
                                            Curve[] segments = polycurve.Explode();
                                            if (segments.Count() != 1)
                                            {
                                                break;
                                            }
                                        }
                                        if (ghc != null)
                                        {
                                            //List<LyrebirdPoint> points = new List<LyrebirdPoint>();
                                            LyrebirdCurve lbc = GetLBCurve(ghc);
                                            List<LyrebirdCurve> lbcurves = new List<LyrebirdCurve> { lbc };

                                            RevitObject ro = new RevitObject
                                            {
                                                Curves = lbcurves,
                                                FamilyName = familyName,
                                                Category = category,
                                                CategoryId = categoryId,
                                                TypeName = typeName,
                                                Origin = null,
                                                GHPath = curves.Paths[i].ToString(),
                                                GHScaleFactor = scale.ScaleFactor,
                                                GHScaleName = scale.ScaleName
                                            };

                                            tempObjs.Add(ro);
                                        }
                                    }
                                    obj = tempObjs;
                                }
                            }
                            else
                            {
                                // Make sure all of the curves in each branch are closed
                                bool allClosed = true;
                                DataTree<CurveCheck> crvTree = new DataTree<CurveCheck>();
                                for (int i = 0; i < curves.Branches.Count; i++)
                                {
                                    List<GH_Curve> ghCrvs = curves.Branches[i];
                                    List<CurveCheck> checkedcurves = new List<CurveCheck>();
                                    GH_Path path = new GH_Path(i);
                                    for (int j = 0; j < ghCrvs.Count; j++)
                                    {
                                        Curve c = ghCrvs[j].Value;
                                        if (c.IsClosed)
                                        {
                                            AreaMassProperties amp = AreaMassProperties.Compute(c);
                                            if (amp != null)
                                            {
                                                double area = amp.Area;
                                                CurveCheck cc = new CurveCheck(c, area);
                                                checkedcurves.Add(cc);
                                            }
                                        }
                                        else
                                        {
                                            allClosed = false;
                                        }
                                    }
                                    if (allClosed)
                                    {
                                        // Sort the curves by area
                                        checkedcurves.Sort((x, y) => x.Area.CompareTo(y.Area));
                                        checkedcurves.Reverse();
                                        foreach (CurveCheck cc in checkedcurves)
                                        {
                                            crvTree.Add(cc, path);
                                        }
                                    }
                                }

                                if (allClosed)
                                {
                                    // Determine if the smaller profiles are within the larger
                                    bool allInterior = true;
                                    List<RevitObject> tempObjs = new List<RevitObject>();
                                    for (int i = 0; i < crvTree.Branches.Count; i++)
                                    {
                                        try
                                        {
                                            List<int> crvSegmentIds = new List<int>();
                                            List<LyrebirdCurve> lbCurves = new List<LyrebirdCurve>();
                                            List<CurveCheck> checkedCrvs = crvTree.Branches[i];
                                            Curve outerProfile = checkedCrvs[0].Curve;
                                            double outerArea = checkedCrvs[0].Area;
                                            List<Curve> planarCurves = new List<Curve>();
                                            planarCurves.Add(outerProfile);
                                            double innerArea = 0.0;
                                            for (int j = 1; j < checkedCrvs.Count; j++)
                                            {
                                                planarCurves.Add(checkedCrvs[j].Curve);
                                                innerArea += checkedCrvs[j].Area;
                                            }
                                            // Try to create a planar surface
                                            IEnumerable<Curve> surfCurves = planarCurves;
                                            Brep[] b = Brep.CreatePlanarBreps(surfCurves);
                                            if (b.Count() == 1)
                                            {
                                                // Test the areas
                                                double brepArea = b[0].GetArea();
                                                double calcArea = outerArea - innerArea;
                                                double diff = (brepArea - calcArea) / calcArea;

                                                if (diff < 0.1)
                                                {
                                                    // The profiles probably are all interior
                                                    foreach (CurveCheck cc in checkedCrvs)
                                                    {
                                                        Curve c = cc.Curve;
                                                        List<Curve> rCurves = new List<Curve>();
                                                        bool getCrvs = CurveSegments(rCurves, c, true);

                                                        if (rCurves.Count > 0)
                                                        {
                                                            int crvSeg = rCurves.Count;
                                                            crvSegmentIds.Add(crvSeg);
                                                            foreach (Curve rc in rCurves)
                                                            {
                                                                LyrebirdCurve lbc;
                                                                lbc = GetLBCurve(rc);
                                                                lbCurves.Add(lbc);
                                                            }
                                                        }
                                                    }
                                                    RevitObject ro = new RevitObject();
                                                    ro.Curves = lbCurves;
                                                    ro.FamilyName = familyName;
                                                    ro.Category = category;
                                                    ro.CategoryId = categoryId;
                                                    ro.TypeName = typeName;
                                                    ro.Origin = null;
                                                    ro.GHPath = crvTree.Paths[i].ToString();
                                                    ro.GHScaleFactor = scale.ScaleFactor;
                                                    ro.GHScaleName = scale.ScaleName;
                                                    ro.CurveIds = crvSegmentIds;
                                                    tempObjs.Add(ro);
                                                }
                                            }
                                            else
                                            {
                                                allInterior = false;
                                                message = "Warning:\n\nEach Branch represents an object, " +
                                                "so curve based elements should be grafted so that each curve is on it's own branch, or all curves on a branch should " +
                                                "be interior to the largest, outer boundary.";
                                            }
                                        }
                                        catch
                                        {
                                            allInterior = false;
                                            // Inform the user they need to graft their inputs.  Only one curve per branch
                                            message = "Warning:\n\nEach Branch represents an object, " +
                                                "so curve based elements should be grafted so that each curve is on it's own branch, or all curves on a branch should " +
                                                "be interior to the largest, outer boundary.";
                                        }
                                    }
                                    if (tempObjs.Count > 0)
                                    {
                                        obj = tempObjs;
                                    }
                                }
                            }
                        }
                        #endregion

                        // Orientation
                        if (orientations != null && orientations.Branches.Count > 0)
                        {
                            List<RevitObject> tempList = AssignOrientation(obj, orientations);
                            obj = tempList;
                        }

                        // face orientation
                        if (faceOrientations != null && faceOrientations.Branches.Count > 0)
                        {
                            List<RevitObject> tempList = AssignFaceOrientation(obj, faceOrientations);
                            obj = tempList;
                        }

                        // Parameters...
                        if (Params.Input.Count > 6)
                        {
                            List<RevitObject> currentObjs = obj;
                            List<RevitObject> tempObjs = new List<RevitObject>();
                            for (int r = 0; r < currentObjs.Count; r++)
                            {
                                RevitObject ro = currentObjs[r];
                                List<RevitParameter> revitParams = new List<RevitParameter>();
                                for (int i = 6; i < Params.Input.Count; i++)
                                {

                                    RevitParameter rp = new RevitParameter();
                                    IGH_Param param = Params.Input[i];
                                    string paramInfo = param.Description;
                                    string[] pi = paramInfo.Split(new[] { "\n", ":" }, StringSplitOptions.None);
                                    string paramName = null;
                                    try
                                    {
                                        paramName = pi[1].Substring(1);
                                        string paramStorageType = pi[5].Substring(1);
                                        rp.ParameterName = paramName;
                                        rp.StorageType = paramStorageType;
                                    }
                                    catch (Exception ex)
                                    {
                                        Debug.WriteLine(ex.Message);
                                    }
                                    if (paramName != null)
                                    {
                                        GH_Structure<IGH_Goo> data = null;
                                        try
                                        {
                                            DA.GetDataTree(i, out data);
                                        }
                                        catch (Exception ex)
                                        {
                                            Debug.WriteLine(ex.Message);
                                        }
                                        if (data != null)
                                        {
                                            string value = data[r][0].ToString();
                                            rp.Value = value;
                                            revitParams.Add(rp);
                                        }
                                    }

                                }
                                ro.Parameters = revitParams;
                                tempObjs.Add(ro);
                            }
                            obj = tempObjs;
                        }

                        // Send the data to Revit to create and/or modify family instances.
                        if (obj != null && obj.Count > 0)
                        {
                            try
                            {
                                string docName = channel.DocumentName();
                                if (docName == null || docName == string.Empty)
                                {
                                    message = "Could not contact the lyrebird server.  Make sure it's running and try again.";
                                }
                                else
                                {
                                    string nn = NickName;
                                    if (nn == null || nn.Length == 0)
                                    {
                                        nn = "LBOut";
                                    }
                                    channel.CreateOrModify(obj, InstanceGuid, NickName);
                                    message = obj.Count.ToString() + " objects sent to the lyrebird server.";
                                }
                            }
                            catch
                            {
                                message = "Could not contact the lyrebird server.  Make sure it's running and try again.";
                            }
                        }
                        channel.Dispose();
                        try
                        {
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                    }
                    else
                    {
                        message = "Error\n" + "The Lyrebird Service could not be found.  Ensure Revit is running, the Lyrebird server plugin is installed, and the server is active.";
                    }
                }
            }
            else
            {
                message = null;
            }

            // Check if the revit information is set
            if (familyName != null || (familyName != "Not Selected" && typeName != "Not Selected"))
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Family: " + familyName);
                sb.AppendLine("Type: " + typeName);
                sb.AppendLine("Category: " + category);
                for (int i = 0; i < inputParameters.Count; i++)
                {
                    RevitParameter rp = inputParameters[i];
                    string type = "Instance";
                    if (rp.IsType)
                    {
                        type = "Type";
                    }
                    sb.AppendLine(string.Format("Parameter{0}: {1}  /  {2}  /  {3}", (i + 1).ToString(CultureInfo.InvariantCulture), rp.ParameterName, rp.StorageType, type));
                }
                objMessage = sb.ToString();
            }
            else
            {
                objMessage = "No data type set.  Double-click to set data type";
            }

            DA.SetData(0, objMessage);
            DA.SetData(1, message);
        }
Пример #5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            bool runCommand = false;
            int category = 3;
            DA.GetData(0, ref runCommand);
            DA.GetData(1, ref category);

            try
            {
                ElementIdCategory eicTemp = (ElementIdCategory)category;
                if (eic != eicTemp)
                {
                    eic = (ElementIdCategory)category;
                }
            }
            catch { }
            
            if (runCommand)
            {
                try
                {
                    elements = new List<string>();
                    elements.Clear();
                    // Open the Channel to Revit
                    
                    LyrebirdChannel channel = new LyrebirdChannel(appVersion);
                    
                    channel.Create();
                    
                    if (channel != null)
                    {
                        string documentName = channel.DocumentName();
                        if (documentName != null)
                        {
                            elements = channel.GetCategoryElements(eic);
                        }

                        channel.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("Error\n" + ex.Message);
                }
            }
            DA.SetDataList(0, elements);
        }