Example #1
0
        public Result Execute(
            ExternalCommandData revit,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = revit.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;
            Selection     sel   = uidoc.Selection;

            Reference ref1 = sel.PickObject(
                ObjectType.Element, "Please pick a floor.");

            Floor f = doc.GetElement(ref1) as Floor;

            if (f == null)
            {
                return(Result.Failed);
            }

            // Retrieve floor edge model line elements.

            ICollection <ElementId> deleted_ids;

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Temporarily Delete Floor");

                deleted_ids = doc.Delete(f.Id);

                tx.RollBack();
            }

            // Grab the first floor edge model line.

            ModelLine ml = null;

            foreach (ElementId id in deleted_ids)
            {
                ml = doc.GetElement(id) as ModelLine;

                if (null != ml)
                {
                    break;
                }
            }

            if (null != ml)
            {
                using (Transaction tx = new Transaction(doc))
                {
                    tx.Start("Change Slope Angle");

                    // This parameter is read only. Therefore,
                    // the change does not work and we cannot
                    // change the floor slope angle after the
                    // floor is created.

                    ml.get_Parameter(
                        BuiltInParameter.CURVE_IS_SLOPE_DEFINING)
                    .Set(1);

                    ml.get_Parameter(
                        BuiltInParameter.ROOF_SLOPE)
                    .Set(1.2);

                    tx.Commit();
                }
            }
            return(Result.Succeeded);
        }
        private void Stream( ArrayList data, ModelLine modelCrv )
        {
            data.Add( new Snoop.Data.ClassSeparator( typeof( ModelLine ) ) );

              // no data at this level
        }
        public void Execute(UIApplication uiapp)
        {
            try
            {
                UIDocument uidoc = uiapp.ActiveUIDocument;
                Document   doc   = uidoc.Document; // myListView_ALL_Fam_Master.Items.Add(doc.GetElement(uidoc.Selection.GetElementIds().First()).Name);

                if (doc.ActiveView.GetType() != typeof(View3D))
                {
                    MessageBox.Show("ActiveView is not typeof View3D.");
                    return;
                }

                FamilyInstance myFamilyInstance_NerfGun = null;
                if (uidoc.Selection.GetElementIds().Count == 0)
                {
                    string myString_RememberLast = doc.ProjectInformation.get_Parameter(BuiltInParameter.PROJECT_NUMBER).AsString();
                    int    n;
                    if (int.TryParse(myString_RememberLast, out n))
                    {
                        myFamilyInstance_NerfGun = doc.GetElement(new ElementId(n)) as FamilyInstance;
                    }
                }
                else
                {
                    myFamilyInstance_NerfGun = doc.GetElement(uidoc.Selection.GetElementIds().First()) as FamilyInstance;
                }


                if (myFamilyInstance_NerfGun == null)
                {
                    MessageBox.Show("Please perform step 5 of 19 first." + Environment.NewLine + Environment.NewLine + "(Placing Nerf Gun)");
                    return;
                }

                ///            TECHNIQUE 14 OF 19 (EE14_Draw3D_IntersectorLines.cs)
                ///↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ DRAW INTERSECTOR LINES FROM NERF GUN ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
                ///
                /// Interfaces and ENUM's:
                ///     BuiltInParameter.POINT_ELEMENT_DRIVEN
                ///     IFailuresPreprocessor
                ///
                ///
                /// Demonstrates classes:
                ///     ReferencePoint
                ///     AdaptiveComponentInstanceUtils
                ///     Transform
                ///     TransactionGroup
                ///     Random*
                ///     ElementMulticategoryFilter
                ///     ReferenceIntersector
                ///
                ///
                /// Key methods:
                ///     AdaptiveComponentInstanceUtils.GetInstancePointElementRefIds(
                ///     myReferencePoint.GetCoordinateSystem(
                ///     refIntersector.FindNearest(
                ///     myReferenceWithContext.GetReference(
                ///     uidoc.RefreshActiveView();
                ///
                ///
                ///
                /// * class is actually part of the .NET framework (not Revit API)
                ///
                ///
                ///	https://github.com/joshnewzealand/Revit-API-Playpen-CSharp

                uidoc.Selection.SetElementIds(new List <ElementId>());

                ReferencePoint myReferencePoint = doc.GetElement(AdaptiveComponentInstanceUtils.GetInstancePointElementRefIds(myFamilyInstance_NerfGun).First()) as ReferencePoint;

                Transform myTransform_FromNurfGun = myReferencePoint.GetCoordinateSystem();


                using (TransactionGroup transGroup = new TransactionGroup(doc))
                {
                    transGroup.Start("Transaction Group");

                    if (!myReferencePoint.get_Parameter(BuiltInParameter.POINT_ELEMENT_DRIVEN).IsReadOnly)
                    {
                        using (Transaction tx = new Transaction(doc))
                        {
                            tx.Start("Unhost");

                            myReferencePoint.get_Parameter(BuiltInParameter.POINT_ELEMENT_DRIVEN).Set(0);

                            tx.Commit();
                            uidoc.RefreshActiveView();
                        }
                    }

                    MyPreProcessor preproccessor = new MyPreProcessor();

                    for (int i = 1; i <= 100; i++)
                    {
                        if (i > 100)
                        {
                            MessageBox.Show("Stopped at 'i > 100' because more will cause Revit to 'freeze up'.");
                            break;
                        }

                        Random rnd = new Random();
                        OverrideGraphicSettings ogs = new OverrideGraphicSettings();
                        ogs.SetProjectionLineColor(new Autodesk.Revit.DB.Color((byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256)));

                        using (Transaction tx = new Transaction(doc))
                        {
                            FailureHandlingOptions options = tx.GetFailureHandlingOptions();
                            options.SetFailuresPreprocessor(preproccessor);
                            tx.SetFailureHandlingOptions(options);

                            tx.Start("Splatter Gun");

                            Line myLine_BasisX = Line.CreateUnbound(myTransform_FromNurfGun.Origin, myTransform_FromNurfGun.BasisX);
                            myReferencePoint.Location.Rotate(myLine_BasisX, GetRandomNumber());

                            Line myLine_BasisZ = Line.CreateUnbound(myTransform_FromNurfGun.Origin, myTransform_FromNurfGun.BasisZ);
                            myReferencePoint.Location.Rotate(myLine_BasisZ, GetRandomNumber());

                            myTransform_FromNurfGun = myReferencePoint.GetCoordinateSystem();

                            List <BuiltInCategory> builtInCats = new List <BuiltInCategory>();
                            builtInCats.Add(BuiltInCategory.OST_Roofs);
                            builtInCats.Add(BuiltInCategory.OST_Ceilings);
                            builtInCats.Add(BuiltInCategory.OST_Floors);
                            builtInCats.Add(BuiltInCategory.OST_Walls);
                            builtInCats.Add(BuiltInCategory.OST_Doors);
                            builtInCats.Add(BuiltInCategory.OST_Windows);
                            builtInCats.Add(BuiltInCategory.OST_CurtainWallPanels);
                            builtInCats.Add(BuiltInCategory.OST_CurtainWallMullions);

                            ElementMulticategoryFilter intersectFilter = new ElementMulticategoryFilter(builtInCats);
                            ReferenceIntersector       refIntersector  = new ReferenceIntersector(intersectFilter, FindReferenceTarget.Face, doc.ActiveView as View3D);

                            ReferenceWithContext myReferenceWithContext = refIntersector.FindNearest(myTransform_FromNurfGun.Origin, myTransform_FromNurfGun.BasisZ);

                            if (myReferenceWithContext != null)
                            {
                                Reference myReferenceHosting_Normal = myReferenceWithContext.GetReference();

                                Element myElement_ContainingFace = doc.GetElement(myReferenceHosting_Normal.ElementId);
                                Face    myFace = myElement_ContainingFace.GetGeometryObjectFromReference(myReferenceHosting_Normal) as Face;
                                if (myFace.GetType() != typeof(PlanarFace))
                                {
                                    return;                                        // continue;
                                }
                                Plane       plane       = Plane.CreateByNormalAndOrigin(myTransform_FromNurfGun.BasisX, myTransform_FromNurfGun.Origin);
                                SketchPlane sketchPlane = SketchPlane.Create(doc, plane);

                                if (myTransform_FromNurfGun.Origin.DistanceTo(myReferenceHosting_Normal.GlobalPoint) > 0.0026)//minimum lenth check
                                {
                                    Line line = Line.CreateBound(myTransform_FromNurfGun.Origin, myReferenceHosting_Normal.GlobalPoint);

                                    ModelLine myModelLine = doc.Create.NewModelCurve(line, sketchPlane) as ModelLine;

                                    doc.ActiveView.SetElementOverrides(myModelLine.Id, ogs);

                                    myWindow1.myListElementID_SketchPlanesToDelete.Add(sketchPlane.Id);

                                    Transform myXYZ_FamilyTransform = Transform.Identity;

                                    if (myReferenceHosting_Normal.ConvertToStableRepresentation(doc).Contains("INSTANCE"))
                                    {
                                        myXYZ_FamilyTransform = (myElement_ContainingFace as FamilyInstance).GetTotalTransform();
                                    }

                                    PlanarFace myPlanarFace = myFace as PlanarFace;

                                    Transform myTransform = Transform.Identity;
                                    myTransform.Origin = myReferenceHosting_Normal.GlobalPoint;
                                    myTransform.BasisX = myXYZ_FamilyTransform.OfVector(myPlanarFace.XVector);
                                    myTransform.BasisY = myXYZ_FamilyTransform.OfVector(myPlanarFace.YVector);
                                    myTransform.BasisZ = myXYZ_FamilyTransform.OfVector(myPlanarFace.FaceNormal);

                                    SketchPlane mySketchPlane = SketchPlane.Create(doc, myReferenceHosting_Normal);

                                    // Create a geometry circle in Revit application
                                    XYZ    xVec        = myTransform.OfVector(XYZ.BasisX);
                                    XYZ    yVec        = myTransform.OfVector(XYZ.BasisY);
                                    double startAngle2 = 0;
                                    double endAngle2   = 2 * Math.PI;
                                    double radius2     = 1.23;
                                    Arc    geomPlane3  = Arc.Create(myTransform.OfPoint(new XYZ(0, 0, 0)), radius2, startAngle2, endAngle2, xVec, yVec);

                                    ModelArc arc = doc.Create.NewModelCurve(geomPlane3, mySketchPlane) as ModelArc;
                                    //doc.Delete(sketch2.Id);

                                    doc.ActiveView.SetElementOverrides(arc.Id, ogs);
                                }
                            }
                            tx.Commit();
                            uidoc.RefreshActiveView();
                        }
                    }
                    transGroup.Assimilate();
                }
            }

            #region catch and finally
            catch (Exception ex)
            {
                _952_PRLoogleClassLibrary.DatabaseMethods.writeDebug("EE05_Part1" + Environment.NewLine + ex.Message + Environment.NewLine + ex.InnerException, true);
            }
            finally
            {
            }
            #endregion
        }
Example #4
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp      = commandData.Application;
            UIDocument    uidoc      = uiapp.ActiveUIDocument;
            Application   app        = uiapp.Application;
            Document      doc        = uidoc.Document;
            View          activeView = doc.ActiveView;


            //ICollection<Reference> selectedLines = uidoc.Selection.PickObjects(ObjectType.Element, "Select Lines");

            Reference refFace         = uidoc.Selection.PickObject(ObjectType.Face, "Select Surface");
            Element   selectedElement = doc.GetElement(refFace);


            GeometryObject obj = selectedElement.GetGeometryObjectFromReference(refFace);

            Face face = obj as Face;


            ICollection <Reference> refLines = uidoc.Selection.PickObjects(ObjectType.Element, "Select Line");

            Level lvl = null;

            ICollection <Element> allLevels = new FilteredElementCollector(doc).OfClass(typeof(Level)).ToElements();

            foreach (Level l in allLevels)
            {
                if (l.Name == "Level 1")
                {
                    lvl = l;
                }
            }

            using (Transaction t = new Transaction(doc, "test"))
            {
                t.Start();

                foreach (Reference refLine in refLines)
                {
                    try
                    {
                        LocationCurve locCurve = doc.GetElement(refLine.ElementId).Location as LocationCurve;
                        Line          line     = locCurve.Curve as Line;

                        XYZ q = line.GetEndPoint(1);
                        XYZ p = line.GetEndPoint(0);

                        XYZ v = q - p;

                        XYZ rayDirection = new XYZ(0, 0, 1);

                        XYZ normal = line.Direction.CrossProduct(rayDirection);

                        Plane verticalPlane = Plane.CreateByNormalAndOrigin(normal, p);

                        SketchPlane splane = SketchPlane.Create(doc, verticalPlane);

                        XYZ qProjected = ProjectPoint(doc, refFace, q, rayDirection);

                        XYZ pProjected = ProjectPoint(doc, refFace, p, rayDirection);

                        Line projectedLine = Line.CreateBound(pProjected, qProjected);

                        ModelLine verticalmLine = doc.Create.NewModelCurve(projectedLine, splane) as ModelLine;
                    }
                    catch (Exception ex)
                    {
                        TaskDialog.Show("result", ex.Message);
                    }
                }



                t.Commit();
            }

            return(Result.Succeeded);
        }
        void SetTangentLockInProfileSketch2(
            Document famdoc,
            Form[] extrusions)
        {
            ICollection <ElementId> delIds = null;
            List <ElementId>        enmIDs = new List <ElementId>();

            using (SubTransaction delTrans = new SubTransaction(famdoc))
            {
                try
                {
                    delTrans.Start();
                    delIds = famdoc.Delete(extrusions[0].Id);
                    delTrans.RollBack();
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(ex.ToString());
                }
            }

            // Get the model lines in the profile and use the end
            // points for reference the sketch dimensions diameter

            List <ModelArc>  mArcsR1 = new List <ModelArc>();
            List <ModelArc>  mArcsR2 = new List <ModelArc>();
            List <ModelLine> mLines  = new List <ModelLine>();

            foreach (ElementId id in delIds)
            {
                enmIDs.Add(id);
            }

            for (int i = 0; i < enmIDs.Count; i++)
            {
                Element ele = famdoc.GetElement(enmIDs[i]);
                if (ele is ModelArc)
                {
                    ModelArc ma = ele as ModelArc;
                    Curve    c  = ma.GeometryCurve;
                    Arc      a  = c as Arc;

                    if (Math.Round(r1, 6) == Math.Round(a.Radius, 6))
                    {
                        mArcsR1.Add(ma);
                    }
                    if (Math.Round(r2, 6) == Math.Round(a.Radius, 6))
                    {
                        mArcsR2.Add(ma);
                    }
                }
                if (ele is ModelLine)
                {
                    ModelLine ml       = ele as ModelLine;
                    ElementId beforeId = null;
                    ElementId afterId  = null;

                    ISet <ElementId> joinedBefore = ml.GetAdjoinedCurveElements(0);
                    foreach (ElementId id in joinedBefore)
                    {
                        Element joinedEle = famdoc.GetElement(id);

                        if (joinedEle is ModelArc)
                        {
                            beforeId = id;
                            break;
                        }
                    }
                    ISet <ElementId> joinedAfter = ml.GetAdjoinedCurveElements(1);
                    foreach (ElementId id in joinedAfter)
                    {
                        Element joinedEle = famdoc.GetElement(id);

                        if (joinedEle is ModelArc)
                        {
                            afterId = id;
                            break;
                        }
                    }

                    if (beforeId != null &&
                        afterId != null &&
                        ml.HasTangentJoin(0, beforeId) &&
                        ml.HasTangentJoin(1, afterId))
                    {
                        ml.SetTangentLock(0, beforeId, true);
                        ml.SetTangentLock(1, afterId, true);
                    }
                }
            }
        }
        void SetTangentLockInProfileSketch1(
            Document famdoc,
            Form [] extrusions)
        {
            ICollection <ElementId> delIds = null;
            List <ElementId>        enmIDs = new List <ElementId>();

            using (SubTransaction delTrans = new SubTransaction(famdoc))
            {
                try
                {
                    delTrans.Start();
                    delIds = famdoc.Delete(extrusions[0].Id);
                    delTrans.RollBack();
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(ex.ToString());
                }
            }

            // Get the model lines in the profile and use the
            // end points for reference the sketch dimensions diameter

            List <ModelArc>  mArcsR1 = new List <ModelArc>();
            List <ModelArc>  mArcsR2 = new List <ModelArc>();
            List <ModelLine> mLines  = new List <ModelLine>();

            foreach (ElementId id in delIds)
            {
                enmIDs.Add(id);
            }

            for (int i = 0; i < enmIDs.Count; i++)
            {
                Element ele = famdoc.GetElement(enmIDs[i]);
                if (ele is ModelArc)
                {
                    ModelArc ma = ele as ModelArc;
                    Curve    c  = ma.GeometryCurve;
                    Arc      a  = c as Arc;

                    if (Math.Round(r1, 6) == Math.Round(a.Radius, 6))
                    {
                        mArcsR1.Add(ma);
                    }
                    if (Math.Round(r2, 6) == Math.Round(a.Radius, 6))
                    {
                        mArcsR2.Add(ma);
                    }
                }
                if (ele is ModelLine)
                {
                    ModelLine ml       = ele as ModelLine;
                    Element   before   = null;
                    Element   after    = null;
                    ElementId beforeId = null;
                    ElementId afterId  = null;

                    if (i > 0)
                    {
                        before   = famdoc.GetElement(enmIDs[i - 1]);
                        beforeId = enmIDs[i - 1];
                    }
                    else
                    {
                        before   = famdoc.GetElement(enmIDs[enmIDs.Count - 1]);
                        beforeId = enmIDs[enmIDs.Count - 1];
                    }
                    if (i == enmIDs.Count - 1)
                    {
                        after   = famdoc.GetElement(enmIDs[0]);
                        afterId = enmIDs[0];
                    }
                    else
                    {
                        after   = famdoc.GetElement(enmIDs[i + 1]);
                        afterId = enmIDs[i + 1];
                    }

                    if (before is ModelArc && after is ModelArc)
                    {
                        ml.SetTangentLock(0, beforeId, true);
                        ml.SetTangentLock(1, afterId, true);
                    }
                }
            }
        }
        // Token: 0x06000092 RID: 146 RVA: 0x00003FDC File Offset: 0x000021DC
        private void okButton_Click(object sender, EventArgs e)
        {
            string         text           = null;
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.InitialDirectory = "c:\\";
            saveFileDialog.Filter           = "cs files (*.cs)|*.cs|All files (*.*)|*.*";
            saveFileDialog.FilterIndex      = 1;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.FileName         = null;
            bool flag = saveFileDialog.ShowDialog() == DialogResult.OK;

            if (flag)
            {
                try
                {
                    Stream stream;
                    bool   flag2 = (stream = saveFileDialog.OpenFile()) != null;
                    if (flag2)
                    {
                        using (stream)
                        {
                            text = saveFileDialog.FileName;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file. Original error: " + ex.Message);
                }
            }
            string text2                    = "_MouseOver";
            string directoryName            = Path.GetDirectoryName(text);
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text);
            string text3                    = fileNameWithoutExtension + text2;
            string path = null;

            path = string.Concat(new string[]
            {
                directoryName,
                "\\",
                fileNameWithoutExtension,
                text2,
                ".cs"
            });
            string        arg           = "using UnityEngine;\nusing System.Collections.Generic;";
            string        value         = "";
            StringBuilder stringBuilder = new StringBuilder();
            bool          flag3         = File.Exists(text);

            if (flag3)
            {
                File.Delete(text);
            }
            bool flag4 = File.Exists(path);

            if (flag4)
            {
                File.Delete(path);
            }
            List <string> list       = new List <string>();
            List <string> list2      = new List <string>();
            List <string> list3      = new List <string>();
            List <double> list4      = new List <double>();
            List <string> list5      = new List <string>();
            List <string> list6      = new List <string>();
            List <string> list7      = new List <string>();
            List <string> list8      = new List <string>();
            List <string> list9      = new List <string>();
            List <string> list10     = new List <string>();
            List <string> list11     = new List <string>();
            Hashtable     hashtable  = new Hashtable();
            Hashtable     hashtable2 = new Hashtable();
            Hashtable     hashtable3 = new Hashtable();
            Hashtable     hashtable4 = new Hashtable();
            List <string> list12     = new List <string>();
            Hashtable     hashtable5 = new Hashtable();

            try
            {
                Autodesk.Revit.ApplicationServices.Application application = this.p_commandData.Application.Application;
                Document document = this.p_commandData.Application.ActiveUIDocument.Document;
                FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);
                ICollection <Element>    collection = filteredElementCollector.OfClass(typeof(Wall)).ToElements();
                FilteredElementCollector filteredElementCollector2 = new FilteredElementCollector(document);
                ICollection <Element>    collection2 = filteredElementCollector2.OfClass(typeof(View3D)).ToElements();
                View3D view3D = null;
                FilteredElementCollector filteredElementCollector3 = new FilteredElementCollector(document);
                ICollection <Element>    collection3  = filteredElementCollector3.OfClass(typeof(FamilySymbol)).ToElements();
                FamilySymbol             familySymbol = null;
                double    angle     = 270.0;
                double    num       = ExpAnimForm.DegreeToRadian(angle);
                Transform transform = Transform.CreateRotation(XYZ.BasisX, num);
                this.m_AllViews.ExportProperties = true;
                bool flag5 = document.ActiveView.ViewType == ViewType.ThreeD & !document.ActiveView.IsTemplate;
                if (flag5)
                {
                    view3D = (document.ActiveView as View3D);
                }
                FilteredElementCollector filteredElementCollector4 = new FilteredElementCollector(document, view3D.Id);
                ICollection <Element>    collection4    = filteredElementCollector4.OfClass(typeof(FamilyInstance)).ToElements();
                FamilyInstance           familyInstance = null;
                bool flag6 = text != null;
                if (flag6)
                {
                    foreach (Element element in collection3)
                    {
                        familySymbol = (element as FamilySymbol);
                        bool flag7 = familySymbol.Category != null;
                        if (flag7)
                        {
                            bool flag8 = string.Concat(new string[]
                            {
                                familySymbol.Category.Name,
                                " : ",
                                familySymbol.Family.Name,
                                " : ",
                                familySymbol.Name
                            }) == this.FamilySymbolNames;
                            if (flag8)
                            {
                                break;
                            }
                        }
                    }
                    foreach (Element element2 in collection4)
                    {
                        familyInstance = (element2 as FamilyInstance);
                        bool flag9 = familyInstance.Symbol.Id == familySymbol.Id;
                        if (flag9)
                        {
                            foreach (Element element3 in collection)
                            {
                                Wall wall   = (Wall)element3;
                                bool flag10 = wall.Id == familyInstance.Host.Id;
                                if (flag10)
                                {
                                    Wall wall2 = wall;
                                    this.ProjY = wall2.Width;
                                }
                            }
                            bool flag11 = familySymbol != null;
                            if (flag11)
                            {
                                Document document2 = document.EditFamily(familySymbol.Family);
                                FilteredElementCollector filteredElementCollector5 = new FilteredElementCollector(document2);
                                ICollection <Element>    collection5 = filteredElementCollector5.OfClass(typeof(Dimension)).ToElements();
                                FilteredElementCollector filteredElementCollector6 = new FilteredElementCollector(document2);
                                ICollection <Element>    collection6 = filteredElementCollector6.OfClass(typeof(FamilyInstance)).ToElements();
                                FilteredElementCollector filteredElementCollector7 = new FilteredElementCollector(document2);
                                ICollection <Element>    collection7 = filteredElementCollector7.OfClass(typeof(Wall)).ToElements();
                                List <ElementId>         list13      = new List <ElementId>();
                                XYZ  xyz    = null;
                                XYZ  xyz2   = null;
                                bool flag12 = collection6 != null;
                                if (flag12)
                                {
                                    foreach (Element element4 in collection6)
                                    {
                                        bool flag13 = element4 != null;
                                        if (flag13)
                                        {
                                            FamilyInstance familyInstance2 = element4 as FamilyInstance;
                                            bool           flag14          = familyInstance2.GroupId.IntegerValue.ToString() == "-1";
                                            if (flag14)
                                            {
                                                list13.Add(familyInstance2.Id);
                                            }
                                        }
                                    }
                                }
                                bool flag15 = document2 != null && document2.IsFamilyDocument;
                                if (flag15)
                                {
                                    int  num2   = 0;
                                    bool flag16 = familyInstance.Category.Id.IntegerValue == -2000023;
                                    if (flag16)
                                    {
                                        foreach (Element element5 in collection7)
                                        {
                                            Wall wall3  = (Wall)element5;
                                            bool flag17 = wall3 != null;
                                            if (flag17)
                                            {
                                                bool flag18 = num2 < 2;
                                                if (flag18)
                                                {
                                                    Wall wall4 = wall3;
                                                    this.FamY = wall4.Width;
                                                    num2++;
                                                }
                                            }
                                        }
                                        bool flag19 = document2.FamilyManager.Types.Size == 1;
                                        if (flag19)
                                        {
                                            Transaction transaction = new Transaction(document2);
                                            transaction.Start("Add Type");
                                            string text4 = familyInstance.Name.ToString() + "_Anim";
                                            document2.FamilyManager.NewType(text4);
                                            transaction.Commit();
                                        }
                                    }
                                    double      num3         = (this.ProjY - this.FamY) / 2.0;
                                    Transaction transaction2 = new Transaction(document2);
                                    transaction2.Start("Anim Data");
                                    foreach (object obj in document2.FamilyManager.Types)
                                    {
                                        FamilyType familyType = (FamilyType)obj;
                                        bool       flag20     = familyType.Name == familyInstance.Name;
                                        if (flag20)
                                        {
                                            document2.FamilyManager.CurrentType = familyType;
                                            foreach (object obj2 in document2.FamilyManager.Parameters)
                                            {
                                                FamilyParameter familyParameter = (FamilyParameter)obj2;
                                                bool            flag21          = familyParameter != null && !familyParameter.IsReadOnly;
                                                if (flag21)
                                                {
                                                    bool flag22 = familyParameter.StorageType != StorageType.ElementId && familyParameter.StorageType > 0;

                                                    if (flag22)
                                                    {
                                                        bool flag23 = familyParameter.Definition.Name.ToString() == this.FamilyParameter;
                                                        if (flag23)
                                                        {
                                                            foreach (Element element6 in collection5)
                                                            {
                                                                Dimension dimension = element6 as Dimension;
                                                                bool      flag24    = dimension != null & dimension.DimensionShape == DimensionShape.Angular;

                                                                if (flag24)
                                                                {
                                                                    bool flag25 = dimension.get_Parameter((BuiltInParameter)(-1004510)) != null;
                                                                    if (flag25)
                                                                    {
                                                                        string b      = dimension.get_Parameter((BuiltInParameter)(-1004510)).AsValueString().ToString();
                                                                        bool   flag26 = this.FamilyParameter == b;
                                                                        if (flag26)
                                                                        {
                                                                            Curve curve  = dimension.Curve;
                                                                            bool  flag27 = curve is Arc;
                                                                            if (flag27)
                                                                            {
                                                                                Arc arc = curve as Arc;
                                                                                xyz = arc.Center;
                                                                                break;
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            bool flag28 = xyz != null;
                                                            if (flag28)
                                                            {
                                                                Transform transform2 = familyInstance.GetTransform();
                                                                bool      flag29     = (familyInstance.FacingFlipped && !familyInstance.HandFlipped) || (!familyInstance.FacingFlipped && familyInstance.HandFlipped);
                                                                if (flag29)
                                                                {
                                                                    transform2.BasisY = -transform2.BasisY;
                                                                }
                                                                XYZ xyz3 = transform2.OfPoint(xyz);
                                                                XYZ xyz4 = new XYZ(xyz3.X, xyz3.Y, xyz3.Z);
                                                                XYZ xyz5 = new XYZ(xyz3.X + 2.0, xyz3.Y, xyz3.Z);
                                                                xyz3 = transform.OfPoint(xyz3);
                                                                xyz3 = new XYZ(-xyz3.X, xyz3.Y, xyz3.Z);
                                                                double value2 = xyz3.X;
                                                                double value3 = xyz3.Y;
                                                                double value4 = xyz3.Z;
                                                                value2 = Math.Round(value2, this.rnd);
                                                                value3 = Math.Round(value3, this.rnd);
                                                                value4 = Math.Round(value4, this.rnd);
                                                                string text5  = value2.ToString();
                                                                string text6  = text5.Replace(",", ".");
                                                                string text7  = value3.ToString();
                                                                string text8  = text7.Replace(",", ".");
                                                                string text9  = value4.ToString();
                                                                string text10 = text9.Replace(",", ".");
                                                                string str    = string.Concat(new string[]
                                                                {
                                                                    text6,
                                                                    "f, ",
                                                                    text8,
                                                                    "f, ",
                                                                    text10,
                                                                    "f"
                                                                });
                                                                value = "\n" + str + "\n";
                                                                Transaction transaction3 = new Transaction(document);
                                                                transaction3.Start("AddLine");
                                                                Line        line        = Line.CreateBound(xyz4, xyz5);
                                                                SketchPlane sketchPlane = SketchPlane.Create(document, Plane.CreateByOriginAndBasis(xyz4, XYZ.BasisX, XYZ.BasisY));
                                                                ModelLine   modelLine   = document.Create.NewModelCurve(line, sketchPlane) as ModelLine;
                                                                transaction3.Commit();
                                                            }
                                                            bool flag30 = xyz == null;
                                                            if (flag30)
                                                            {
                                                                foreach (ElementId elementId in list13)
                                                                {
                                                                    bool flag31 = elementId != null;
                                                                    if (flag31)
                                                                    {
                                                                        Element        element7        = document2.GetElement(elementId);
                                                                        FamilyInstance familyInstance3 = element7 as FamilyInstance;
                                                                        foreach (object obj3 in familyInstance3.Parameters)
                                                                        {
                                                                            Parameter parameter = (Parameter)obj3;
                                                                            bool      hasValue  = parameter.HasValue;
                                                                            if (hasValue)
                                                                            {
                                                                                bool flag32 = parameter.Definition.Name == this.FamilyParameter;
                                                                                if (flag32)
                                                                                {
                                                                                    Location      location      = familyInstance3.Location;
                                                                                    LocationPoint locationPoint = location as LocationPoint;
                                                                                    xyz2 = locationPoint.Point;
                                                                                    XYZ xyz6 = new XYZ(xyz2.X, xyz2.Y + num3, xyz2.Z);
                                                                                    xyz2 = xyz6;
                                                                                    break;
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            bool flag33 = xyz2 != null;
                                                            if (flag33)
                                                            {
                                                                Transform transform3 = familyInstance.GetTransform();
                                                                bool      flag34     = (familyInstance.FacingFlipped && !familyInstance.HandFlipped) || (!familyInstance.FacingFlipped && familyInstance.HandFlipped);
                                                                if (flag34)
                                                                {
                                                                    transform3.BasisY = -transform3.BasisY;
                                                                }
                                                                XYZ xyz7 = transform3.OfPoint(xyz2);
                                                                XYZ xyz8 = new XYZ(xyz7.X, xyz7.Y, xyz7.Z);
                                                                XYZ xyz9 = new XYZ(xyz7.X + 2.0, xyz7.Y, xyz7.Z);
                                                                xyz7 = transform.OfPoint(xyz7);
                                                                xyz7 = new XYZ(-xyz7.X, xyz7.Y, xyz7.Z);
                                                                double value5 = xyz7.X;
                                                                double value6 = xyz7.Y;
                                                                double value7 = xyz7.Z;
                                                                value5 = Math.Round(value5, this.rnd);
                                                                value6 = Math.Round(value6, this.rnd);
                                                                value7 = Math.Round(value7, this.rnd);
                                                                string text11 = value5.ToString();
                                                                string text12 = text11.Replace(",", ".");
                                                                string text13 = value6.ToString();
                                                                string text14 = text13.Replace(",", ".");
                                                                string text15 = value7.ToString();
                                                                string text16 = text15.Replace(",", ".");
                                                                string str2   = string.Concat(new string[]
                                                                {
                                                                    text12,
                                                                    "f, ",
                                                                    text14,
                                                                    "f, ",
                                                                    text16,
                                                                    "f"
                                                                });
                                                                value = "\n" + str2 + "\n\n";
                                                                Transaction transaction4 = new Transaction(document);
                                                                transaction4.Start("AddLine");
                                                                Line        line2        = Line.CreateBound(xyz8, xyz9);
                                                                SketchPlane sketchPlane2 = SketchPlane.Create(document, Plane.CreateByOriginAndBasis(xyz8, XYZ.BasisX, XYZ.BasisY));
                                                                ModelLine   modelLine2   = document.Create.NewModelCurve(line2, sketchPlane2) as ModelLine;
                                                                transaction4.Commit();
                                                            }
                                                            string text17 = Convert.ToString(Convert.ToString(familyInstance.get_Parameter((BuiltInParameter)(-1002050)).AsValueString()));
                                                            string text18 = text17.Replace(" ", "_");
                                                            string str3   = text18.Replace("\"", "\\\"");
                                                            string value8 = str3 + "_Anim[" + familyInstance.Id.ToString() + "]";
                                                            stringBuilder.Append(value8);
                                                            stringBuilder.Append(value);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    transaction2.Commit();
                                    document2.Close(false);
                                }
                            }
                        }
                    }
                    string value9 = arg + stringBuilder;
                    using (StreamWriter streamWriter = new StreamWriter(path, true))
                    {
                        streamWriter.WriteLine(value9);
                    }
                }
                Transaction transaction5 = new Transaction(document);
                transaction5.Start("WriteToText");
                document.Regenerate();
                transaction5.Commit();
                base.DialogResult = DialogResult.OK;
                base.Close();
            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message);
            }
        }
Example #8
0
        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document    revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档
            Application revitApp = commandData.Application.Application;               //取得应用程序
            UIDocument  uiDoc    = commandData.Application.ActiveUIDocument;          //取得当前活动文档

            Document document = commandData.Application.ActiveUIDocument.Document;

            Window1 window1 = new Window1();

            //载入族
            FamilySymbol familySymbol;

            using (Transaction tran = new Transaction(uiDoc.Document))
            {
                tran.Start("载入族");

                //载入弦杆族
                string file = @"C:\Users\zyx\Desktop\2RevitArcBridge\CrossBeam\CrossBeam\source\crossBeam.rfa";
                familySymbol = loadFaimly(file, commandData);
                familySymbol.Activate();

                tran.Commit();
            }


            //把这组模型线通过获取首尾点,生成dynamo里的curve
            List <XYZ> ps = new List <XYZ>();

            using (Transaction transaction = new Transaction(uiDoc.Document))
            {
                transaction.Start("选取模型线生成Curve");

                Selection         sel        = uiDoc.Selection;
                IList <Reference> modelLines = sel.PickObjects(ObjectType.Element, "选一组模型线");

                foreach (Reference reference in modelLines)
                {
                    Element   elem            = revitDoc.GetElement(reference);
                    ModelLine modelLine       = elem as ModelLine;
                    Autodesk.Revit.DB.Curve c = modelLine.GeometryCurve;

                    ps.Add(c.GetEndPoint(0));
                    ps.Add(c.GetEndPoint(1));
                }

                for (int i = ps.Count - 1; i > 0; i--)
                {
                    XYZ p1 = ps[i];
                    XYZ p2 = ps[i - 1];

                    //注意此处重合点有一个闭合差
                    if (p1.DistanceTo(p2) < 0.0001)
                    {
                        ps.RemoveAt(i);
                    }
                }

                transaction.Commit();
            }


            //做一个revit和dynamo点的转换
            DG.CoordinateSystem coordinateSystem = DG.CoordinateSystem.ByOrigin(0, 0, 0);//标准坐标系
            List <DG.Point>     DGps             = new List <DG.Point>();

            foreach (XYZ p in ps)
            {
                DGps.Add(p.ToPoint(false));
            }

            DG.PolyCurve polyCurve = DG.PolyCurve.ByPoints(DGps);
            DG.Curve     curve     = polyCurve as DG.Curve;

            List <DG.Point> DGCBps      = new List <DG.Point>();//横梁的放置点位列表
            double          StartLength = 0;

            if (window1.ShowDialog() == true)
            {
                //窗口打开并停留,只有点击按键之后,窗口关闭并返回true
            }


            //按键会改变window的属性,通过对属性的循环判断来实现对按键的监测
            while (!window1.Done)
            {
                //选择起点
                if (window1.StartPointSelected)
                {
                    using (Transaction transaction = new Transaction(uiDoc.Document))
                    {
                        transaction.Start("选择起点");

                        double   r1   = SelectPoint(commandData);
                        DG.Point dgp1 = curve.PointAtParameter(r1);
                        DGCBps.Add(dgp1);
                        StartLength = curve.SegmentLengthAtParameter(r1);


                        transaction.Commit();
                    }

                    //2、重置window1.StartPointSelected

                    window1.StartPointSelected = false;
                }

                if (window1.ShowDialog() == true)
                {
                    //窗口打开并停留,只有点击按键之后,窗口关闭并返回true
                }
            }



            //在这里根据间距获取到各个点
            for (int i = 1; i < window1.cbNumber; i++)
            {
                double   L     = StartLength + window1.cbDistance * i;
                DG.Point point = curve.PointAtSegmentLength(L);
                DGCBps.Add(point);
                MessageBox.Show(i.ToString());
            }

            List <FamilyInstance> instances = new List <FamilyInstance>();

            using (Transaction transaction = new Transaction(uiDoc.Document))
            {
                transaction.Start("创建横梁实例");

                foreach (DG.Point p in DGCBps)
                {
                    FamilyInstance familyInstance;
                    familyInstance = CreateFamlyInstance(p, curve, familySymbol, commandData);
                    instances.Add(familyInstance);
                }


                transaction.Commit();
            }


            //给每个族实例设置参数
            using (Transaction transaction = new Transaction(uiDoc.Document))
            {
                transaction.Start("族实例参数设置");

                foreach (FamilyInstance instance in instances)
                {
                    double h1 = instance.LookupParameter("l1/2").AsDouble();
                    instance.LookupParameter("l1/2").Set(window1.l1 / 2);
                    instance.LookupParameter("l2").Set(window1.l2);

                    //instance.LookupParameter("h1").Set(window1.l1);
                    //instance.LookupParameter("h2").Set(window1.l1);
                }
                transaction.Commit();
            }

            return(Result.Succeeded);
        }
Example #9
0
        public static void CreateEntitiesForModelLineAndSetValue(
            Document doc, ModelLine line,
            double height, double width, string type, ElementId id)
        {
            // Create Transaction for working with schema
            using (Transaction trans = new Transaction(doc, "Create Extensible Store"))
            {
                trans.Start();

                // Create a schema builder
                SchemaBuilder builder = new SchemaBuilder(Guids.MODELLINE_SCHEMA_GUID);

                // Set read and write access levels
                builder.SetReadAccessLevel(AccessLevel.Public);

                builder.SetWriteAccessLevel(AccessLevel.Public);

                // Set name to this schema builder
                builder.SetSchemaName("BeamDimension");

                builder.SetDocumentation(

                    "Data store for dimension of the potential structural beam");

                // Create field1
                FieldBuilder fieldBuilder1 =
                    builder.AddSimpleField("SectionHeight", typeof(double));

                // Set unit type
                fieldBuilder1.SetUnitType(UnitType.UT_Length);

                // Create field2
                FieldBuilder fieldBuilder2 =
                    builder.AddSimpleField("SectionWidth", typeof(double));

                // Set unit type
                fieldBuilder2.SetUnitType(UnitType.UT_Length);

                // Create field3
                FieldBuilder fieldBuilder3 =
                    builder.AddSimpleField("BeamType", typeof(String));

                // Create field4
                FieldBuilder fieldBuilder4 =
                    builder.AddSimpleField("BeamId", typeof(ElementId));

                // Register the schema object
                Schema schema = builder.Finish();

                // Now create entity (object) for this schema (class)
                Entity ent = new Entity(schema);

                if (null != line)
                {
                    line.SetEntity(ent);
                }
                trans.Commit();

                SetEntityFieldsValue(doc, line, height, width, type, id);
            }
        }
Example #10
0
        public override void Draw()
        {
            //dynDouble x = Inputs[0] as dynDouble;
            //dynDouble y = Inputs[1] as dynDouble;
            //dynDouble z = Inputs[2] as dynDouble;

            //if (x != null && y != null && z != null)
            //{
            //    point = new XYZ(x.D, y.D, z.D);
            //}
            //else
            //{
            //    point = null;
            //}

            if (point != null)
            {

                //generate the planes
                xyPlane = this.Settings.Revit.Application.Create.NewPlane(up, point);
                yzPlane = this.Settings.Revit.Application.Create.NewPlane(xAxis, point);
                xzPlane = this.Settings.Revit.Application.Create.NewPlane(yAxis, point);

                //generate the tick lines
                Line l1 = this.Settings.Revit.Application.Create.NewLineBound(point, point + up);
                Line l2 = this.Settings.Revit.Application.Create.NewLineBound(point, point + xAxis);
                Line l3 = this.Settings.Revit.Application.Create.NewLineBound(point, point + yAxis);

                //generate the sketch planes
                topSketch = this.Settings.Doc.Document.Create.NewSketchPlane(xyPlane);
                lrSketch = this.Settings.Doc.Document.Create.NewSketchPlane(yzPlane);
                fbSketch = this.Settings.Doc.Document.Create.NewSketchPlane(xzPlane);

                ll1 = this.Settings.Doc.Document.Create.NewModelCurve(l1, lrSketch) as ModelLine;
                ll2 = this.Settings.Doc.Document.Create.NewModelCurve(l2, topSketch) as ModelLine;
                ll3 = this.Settings.Doc.Document.Create.NewModelCurve(l3, topSketch) as ModelLine;

                if (xyPlane_out != null && yzPlane_out != null && xzPlane_out != null)
                {
                    //update the outputs
                    xyPlane_out.P = xyPlane;
                    yzPlane_out.P = yzPlane;
                    xzPlane_out.P = xzPlane;
                }
            }
        }
Example #11
0
 //override the destroy method for all point objects
 public override void Destroy()
 {
     try
     {
         if (ll1 != null)
         {
             Settings.Doc.Document.Delete(ll1);
             Settings.Doc.Document.Delete(ll2);
             Settings.Doc.Document.Delete(ll3);
             Settings.Doc.Document.Delete(topSketch);
             Settings.Doc.Document.Delete(fbSketch);
             Settings.Doc.Document.Delete(lrSketch);
             ll1 = null;
             ll2 = null;
             ll3 = null;
             topSketch = null;
             fbSketch = null;
             lrSketch = null;
         }
         if (xyPlane != null)
         {
             point = null;
             xyPlane = null;
             yzPlane = null;
             xzPlane = null;
         }
     }
     catch
     {
         ll1 = null;
         ll2 = null;
         ll3 = null;
         topSketch = null;
         fbSketch = null;
         lrSketch = null;
         point = null;
         xyPlane = null;
         yzPlane = null;
         xzPlane = null;
     }
 }
Example #12
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;


            Reference r = uidoc.Selection.PickObject(ObjectType.Element, "Select Element");

            Options geometryOptions = new Options();

            geometryOptions.ComputeReferences = false;

            GeometryElement geomElem = doc.GetElement(r).get_Geometry(geometryOptions);

            List <NurbSpline> cadSplines = new List <NurbSpline>();

            IList <XYZ>   controlPoints = new List <XYZ>();
            List <double> weights       = new List <double>();
            List <double> knots         = new List <double>();

            if (null != geomElem)
            {
                foreach (var o in geomElem)
                {
                    GeometryInstance gi = o as GeometryInstance;
                    GeometryElement  instanceGeometryElement = gi.GetInstanceGeometry();

                    foreach (GeometryObject instanceObj in instanceGeometryElement)
                    {
                        if (instanceObj.GetType().ToString().Contains("NurbSpline"))
                        {
                            //TaskDialog.Show("r", instanceObj.GetType().ToString());
                            NurbSpline nurb = instanceObj as NurbSpline;
                            cadSplines.Add(nurb);
                            controlPoints = nurb.CtrlPoints;
                            //weights = nurb.Weights;
                            weights = nurb.Weights.Cast <double>().ToList();
                            //knots = nurb.Knots;
                            knots = nurb.Knots.Cast <double>().ToList();
                        }
                        break;
                    }
                }
            }

            double scale = 0.3048;

            #region Test
            //List<XYZ> controlPoints = new List<XYZ>();
            //controlPoints.Add(new XYZ(0 / scale, 0 / scale, 0 / scale));
            //controlPoints.Add(new XYZ(5 / scale, 5 / scale, 2 / scale));
            //controlPoints.Add(new XYZ(10 / scale, 10 / scale, 5 / scale));
            //controlPoints.Add(new XYZ(15 / scale, 10 / scale, 5 / scale));
            //controlPoints.Add(new XYZ(20 / scale, 5 / scale, 4 / scale));
            //controlPoints.Add(new XYZ(25 / scale, 5 / scale, 3 / scale));

            //List<double> weights = new List<double>();
            //weights.Add(1.0);
            //weights.Add(1.0);
            //weights.Add(1.0);
            //weights.Add(1.0);
            //weights.Add(1.0);
            //weights.Add(1.0);

            //List<double> knots = new List<double>();
            //knots.Add(0); //1revit
            //knots.Add(0); //2
            //knots.Add(0); //3
            //knots.Add(0); //4
            //knots.Add(10.76); //5
            //knots.Add(21.51); //6
            //knots.Add(32.27); //7
            //knots.Add(32.27);
            //knots.Add(32.27); //9
            //knots.Add(32.27);//revit
            #endregion

            HermiteSpline hermspline = HermiteSpline.Create(controlPoints, false);

            //Curve nurbSpline = NurbSpline.Create(hermspline);
            Curve nurbSpline = NurbSpline.CreateCurve(3, knots, controlPoints, weights);

            //XYZ startPoint = nurbSpline.GetEndPoint(0);

            Transform nurbsTr = nurbSpline.ComputeDerivatives(0, true);

            XYZ startPoint = nurbsTr.Origin;
            //PrintPoint("a", nurbsTr.Origin);

            #region Test Plane
            //Plane geomPlane = Autodesk.Revit.DB.Plane.CreateByOriginAndBasis(nurbsTr.Origin, nurbsTr.BasisY.Normalize(), nurbsTr.BasisZ.Normalize());
            //Plane geomPlane = Autodesk.Revit.DB.Plane.CreateByOriginAndBasis(nurbSpline.GetEndPoint(0), nurbsTr.BasisY.Normalize(), nurbsTr.BasisZ.Normalize());
            //Frame f = new Frame(nurbSpline.GetEndPoint(0), nurbsTr.BasisY.Normalize(), nurbsTr.BasisZ.Normalize(), nurbsTr.BasisX.Normalize());
            //Plane geomPlane = Autodesk.Revit.DB.Plane.CreateByThreePoints(XYZ.Zero, XYZ.BasisX, XYZ.BasisZ);
            //Plane geomPlane = Plane.CreateByNormalAndOrigin(nurbsTr.BasisX.Normalize(), nurbSpline.GetEndPoint(1)); funziona
            //Plane geomPlane = Plane.CreateByThreePoints(startPoint, startPoint + nurbsTr.BasisX.Normalize(), startPoint + XYZ.BasisZ);
            #endregion
            //XYZ curveDir = controlPoints[1] - controlPoints[0];
            XYZ   curveDir  = nurbsTr.BasisX;
            XYZ   perpDir   = curveDir.CrossProduct(startPoint + XYZ.BasisZ).Normalize();
            Plane perpPlane = Plane.CreateByNormalAndOrigin(curveDir, startPoint);
            //Plane vertPlane = Plane.CreateByThreePoints(startPoint, perpPlane.XVec, XYZ.BasisZ);
            Plane vertPlane = perpPlane;

            //PrintPoint("per", perpDir);

            List <PtCoord> pointsCoordinates = new List <PtCoord>();

            using (var form = new FormAddActiveView("Enter coordinates in clockwise order"))
            {
                form.ShowDialog();

                //if the user hits cancel just drop out of macro
                if (form.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                {
                    return(Result.Cancelled);
                }

                string[] inputs = form.TextString.Split(';');

                foreach (string coord in inputs)
                {
                    string[] xy = coord.Split(',');
                    pointsCoordinates.Add(new PtCoord(Double.Parse(xy[0]) / (scale * 1000), Double.Parse(xy[1]) / (scale * 1000)));
                }
            }

//			List<PtCoord> pointsCoordinates = new List<PtCoord>(){new PtCoord(5,0), new PtCoord(2,2), new PtCoord(-14,0), new PtCoord(2,-2)};

            List <XYZ> pts = VertexPoints(nurbsTr.Origin, pointsCoordinates, vertPlane);

            XYZ pt1 = nurbsTr.Origin;
            XYZ pt2 = pt1 + vertPlane.XVec * 5;
            XYZ pt3 = pt2 + vertPlane.YVec * 2 + vertPlane.XVec * 2;
            XYZ pt4 = pt3 - vertPlane.XVec * 12;
            XYZ pt5 = pt4 - vertPlane.YVec * 2 + vertPlane.XVec * 2;



            Line l1 = Line.CreateBound(pt1, pt2);
            Line l2 = Line.CreateBound(pt2, pt3);
            Line l3 = Line.CreateBound(pt3, pt4);
            Line l4 = Line.CreateBound(pt4, pt5);
            Line l5 = Line.CreateBound(pt5, pt1);
            //
            //			var profileLoop = CurveLoop.Create(new List<Curve>{l1, l2, l3, l4, l5});

            var profileLoop = LoopPoints(pts);

            //double rotAngle = -2.543 * Math.PI / 180;
            double rotAngle  = -15 * Math.PI / 180;
            var    transform = Transform.CreateRotationAtPoint(nurbsTr.BasisX, rotAngle, nurbsTr.Origin);

            profileLoop.Transform(transform);

            var loops = new List <CurveLoop> {
                profileLoop
            };

            var path = CurveLoop.Create(new List <Curve> {
                nurbSpline
            });

            WireframeBuilder builder = new WireframeBuilder();

            builder.AddCurve(nurbSpline);


            //Solid solid = GeometryCreationUtilities.CreateSweptGeometry(path,0,nurbSpline.GetEndParameter(0),loops);
            Solid solid = GeometryCreationUtilities.CreateFixedReferenceSweptGeometry(path, 0, nurbSpline.GetEndParameter(0), loops, XYZ.BasisZ);


            using (Transaction t = new Transaction(doc, "create spline"))
            {
                t.Start();

                ElementId categoryId = new ElementId(BuiltInCategory.OST_Floors);

                DirectShape ds = DirectShape.CreateElement(doc, categoryId);

                ds.SetShape(builder);

                ds.Name = "RhinoSpline";

                SketchPlane sp = SketchPlane.Create(doc, vertPlane);
                uidoc.ActiveView.SketchPlane = sp;

                //uidoc.ActiveView.ShowActiveWorkPlane();

                ModelLine line1 = doc.Create.NewModelCurve(l1, sp) as ModelLine;
                ModelLine line2 = doc.Create.NewModelCurve(l2, sp) as ModelLine;
                ModelLine line3 = doc.Create.NewModelCurve(l3, sp) as ModelLine;
                ModelLine line4 = doc.Create.NewModelCurve(l4, sp) as ModelLine;
                ModelLine line5 = doc.Create.NewModelCurve(l5, sp) as ModelLine;

                List <GeometryObject> gs = new List <GeometryObject>();
                gs.Add(solid);

                //DirectShape directShape = DirectShape.CreateElement(doc, categoryId);
                ds.AppendShape(gs);

                t.Commit();
            }

            return(Result.Succeeded);
        }
Example #13
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            _uiapp = commandData.Application;
            _uidoc = _uiapp.ActiveUIDocument;
            _doc   = _uidoc.Document;

            // TODO : Extract GetAllStructuralLevels the methode
            _strLevels =
                (from l in new FilteredElementCollector(_doc)
                 .OfClass(typeof(Level))
                 where l.GetEntitySchemaGuids().Count != 0
                 select l)
                .Cast <Level>()
                .OrderBy(l => l.Elevation)
                .ToList();

            if (_strLevels.Count == 0)
            {
                TaskDialog.Show("Revit", "Configurer les niveaux structuraux avant de lancer cette commande.");
                return(Result.Cancelled);
            }

            BeamCreationForm form = new BeamCreationForm();

            if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                _axeIsOnArchView = form.AxeIsOnArchView;
            }
            else
            {
                return(Result.Cancelled);
            }

            Transaction t = new Transaction(_doc);

            // Get all the model lines created by plugin
            IList <CurveElement> lines =
                (from line in new FilteredElementCollector(_doc)
                 .OfClass(typeof(CurveElement))
                 .OfCategory(BuiltInCategory.OST_Lines)
                 .Cast <CurveElement>()
                 where (line as ModelLine) != null && line.GetEntitySchemaGuids().Count != 0
                 select line)
                .ToList();
            BeamFamily beamFamily = new BeamFamily(_doc);

            t.Start("Create beams");
            foreach (CurveElement line in lines)
            {
                ModelLine modelLine = line as ModelLine;

                bool modelLineOnLevel = GetLevel(modelLine, out Level level);

                GetParameterFromEntity(
                    modelLine,
                    out string beamSign,
                    out double beamHeight,
                    out double beamWidth,
                    out ElementId beamId);

                if (!modelLineOnLevel)
                {
                    continue;
                }

                if (LineHasRelativeBeam(modelLine, beamSign, beamHeight, beamWidth, beamId))
                {
                    continue;
                }
                // TODO : Material should be choosed when creat model line
                FamilySymbol beamType = beamFamily.GetBeamFamilyTypeOrCreateNew(beamSign, "Béton25", beamHeight, beamWidth);

                ElementId newBeamId = PlaceBeam(line, level, beamType);

                SetBeamIdToModelLine(newBeamId, modelLine).ToString();
            }
            t.Commit();
            return(Result.Succeeded);
        }