public void Execute(UpdaterData data)
        {
            Document doc = data.GetDocument();

            if (doc.IsFamilyDocument)
            {
                try
                {
                    //Get document Name
                    string name = doc.Title;
                    if (String.IsNullOrEmpty(name))
                    {
                        name = "null";
                    }

                    //Get form location info (Varies by type?)
                    foreach (ElementId e in data.GetModifiedElementIds().Concat(data.GetAddedElementIds()))
                    {
                        CurveElement ele  = doc.GetElement(e) as CurveElement;
                        var          bbox = ele.get_BoundingBox(null);
                        if (bbox != null)
                        {
                            var dims       = GetDims(bbox);
                            int prediction = Datatype.ObjectStyle.PredictSingle(name, "line", dims);
                            var subcat     = doc.AddCategories(prediction);
                            ele.LineStyle = subcat.GetGraphicsStyle(GraphicsStyleType.Projection);
                        }
                    }
                }
                catch (Exception e)
                {
                    e.OutputError();
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 尺寸标注双根直线元素间距 -详图线、模型线,要求:方向相同,起点共线方向与轴网方向垂直
        /// </summary>
        public static Dimension DimensionBetweenCurveElements(this Document doc, CurveElement curveElement01, CurveElement curveElement02)
        {
            Dimension dimension = null;

            if (!(((curveElement01 is DetailLine) || (curveElement01 is ModelLine)) && ((curveElement02 is DetailLine) || (curveElement02 is ModelLine))))
            {
                return(dimension);
            }
            ReferenceArray referenceArray = new ReferenceArray();

            referenceArray.Append(curveElement01.GeometryCurve.Reference);
            referenceArray.Append(curveElement02.GeometryCurve.Reference);

            Curve curve01 = curveElement01.GeometryCurve;
            Curve curve02 = curveElement02.GeometryCurve;
            Line  line    = Line.CreateBound(curve01.GetEndPoint(1), curve02.GetEndPoint(1));

            // 【】移动标注线的位置
            //double distanceMove = 2000.0.MilliMeterToFeet();
            //distanceMove = distanceMove.MilliMeterToFeet();
            //line = line.CreateOffset(distanceMove, (curve01 as Line).Direction) as Line;

            using (Transaction trans = new Transaction(doc, "轴网端头尺寸标注"))
            {
                trans.Start();
                dimension = doc.Create.NewDimension(doc.ActiveView, line, referenceArray);
                trans.Commit();
            }
            return(dimension);
        }
Esempio n. 3
0
        public void CreateWallByLine()
        {
            Document   doc   = this.ActiveUIDocument.Document;
            UIDocument uidoc = ActiveUIDocument;

            Level level = doc.GetElement(ViewLevelId()) as Level;

            try {
                while (true)
                {
                    Reference    hasPickOne = uidoc.Selection.PickObject(ObjectType.Element, "選取線:");
                    CurveElement ce         = doc.GetElement(hasPickOne) as CurveElement;
                    Curve        c          = ce.GeometryCurve;
                    Curve        d          = c.CreateOffset(UnitUtils.Convert(100, DisplayUnitType.DUT_MILLIMETERS, DisplayUnitType.DUT_DECIMAL_FEET), new XYZ(0, 0, 1));
                    using (Transaction tx = new Transaction(doc))
                    {
                        tx.Start("Create Gable Wall");

                        //Wall wall = doc.Create.NewWall( // 2012
                        //  profile, wallType, level, true, normal );

                        //Wall wall = Wall.Create( // 2013
                        //  doc, profile, wallType.Id, level.Id, true, normal );

                        Wall wall = Wall.Create(doc, d, level.Id, true);

                        wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).Set(HigherLevelId(level.Id));                                 //牆頂部約束

                        tx.Commit();
                    }
                }
            } catch (Exception) {
                //	throw;
            }
        }
Esempio n. 4
0
        public static CurveElement NearestLinesToFace(PlanarFace face, IList <CurveElement> listLines)
        {
            CurveElement curveElement = null;
            double       num          = 0.0;

            foreach (CurveElement curveElement2 in listLines)
            {
                DetailLine detailLine = curveElement2 as DetailLine;
                bool       flag       = detailLine == null;
                if (!flag)
                {
                    XYZ    endPoint = detailLine.GeometryCurve.GetEndPoint(0);
                    double num2     = Facelibry.PointToFace(endPoint, face);
                    bool   flag2    = curveElement == null;
                    if (flag2)
                    {
                        num          = num2;
                        curveElement = curveElement2;
                    }
                    else
                    {
                        bool flag3 = num2 < num;
                        if (flag3)
                        {
                            num          = num2;
                            curveElement = curveElement2;
                        }
                    }
                }
            }
            return(curveElement);
        }
Esempio n. 5
0
        public static void SelectAllLines(UIDocument uiDoc)
        {
            Document         currentDoc      = uiDoc.Document;
            Selection        Sel             = uiDoc.Selection;
            ElementId        v               = uiDoc.ActiveView.Id;
            ISelectionFilter selectionFilter = new LineSelectionFilter();

            Reference    ChangedObject  = Sel.PickObject(ObjectType.Element, selectionFilter);
            CurveElement ChangedElement = currentDoc.GetElement(ChangedObject.ElementId) as CurveElement;

            FilteredElementCollector lineCollector = new FilteredElementCollector(currentDoc, v);
            ICollection <ElementId>  lines         = lineCollector.OfCategory(BuiltInCategory.OST_Lines).ToElementIds().ToList();

            List <ElementId> linelist = new List <ElementId>();

            foreach (ElementId eid in lines)
            {
                CurveElement ce = currentDoc.GetElement(eid) as CurveElement;
                if (ce.LineStyle.Name == ChangedElement.LineStyle.Name)
                {
                    linelist.Add(eid);
                }
            }
            Sel.SetElementIds(linelist);
        }
Esempio n. 6
0
        public static void CurveAndBsplineCurve(string unparsed)
        {
            Application app = Utilities.ComApp;

            Point3d[] pntArray = new Point3d[5];
            pntArray[0] = app.Point3dFromXY(0, -19);
            pntArray[1] = app.Point3dFromXY(1, -17);
            pntArray[2] = app.Point3dFromXY(2, -19);
            pntArray[3] = app.Point3dFromXY(3, -17);
            pntArray[4] = app.Point3dFromXY(4, -19);
            CurveElement oCurve = app.CreateCurveElement1(null, ref pntArray);

            oCurve.Color      = 0;
            oCurve.LineWeight = 2;
            app.ActiveModelReference.AddElement(oCurve);
            for (int i = 0; i < 5; i++)
            {
                pntArray[i].X += 5;
            }

            InterpolationCurve oInterpolationCurve = new InterpolationCurveClass();

            oInterpolationCurve.SetFitPoints(pntArray);
            BsplineCurveElement oBsplineCurve = app.CreateBsplineCurveElement2(null, oInterpolationCurve);

            oBsplineCurve.Color      = 1;
            oBsplineCurve.LineWeight = 2;
            app.ActiveModelReference.AddElement(oBsplineCurve);
        }
Esempio n. 7
0
        /// <summary>
        /// Checks if the curve element should be exported.
        /// </summary>
        /// <param name="curveElement">
        /// The curve element.
        /// </param>
        /// <returns>
        /// True if the curve element should be exported, false otherwise.
        /// </returns>
        private static bool ShouldCurveElementBeExported(CurveElement curveElement)
        {
            CurveElementType curveElementType = curveElement.CurveElementType;
            bool exported = false;
            if (curveElementType == CurveElementType.ModelCurve || curveElementType == CurveElementType.CurveByPoints)
                exported = true;

            if (exported)
            {
                // Confirm curve is not used by another element
                exported = !ExporterIFCUtils.IsCurveFromOtherElementSketch(curveElement);

                // Confirm the geometry curve is valid.
                Curve curve = curveElement.GeometryCurve;

                if (curve == null)
                    exported = false;
                else if (curve is Line)
                {
                    if (!curve.IsBound)
                        exported = false;
                    else
                    {
                        XYZ end1 = curve.GetEndPoint(0);
                        XYZ end2 = curve.GetEndPoint(1);
                        if (end1.IsAlmostEqualTo(end2))
                            exported = false;
                    }
                }
            }

            return exported;
        }
Esempio n. 8
0
File: XYZ.cs Progetto: l2obin/Dynamo
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            double parameter = ((FScheme.Value.Number)args[0]).Item;

            Curve thisCurve = null;
            Edge  thisEdge  = null;

            if (((FScheme.Value.Container)args[1]).Item is Curve)
            {
                thisCurve = ((FScheme.Value.Container)args[1]).Item as Curve;
            }
            else if (((FScheme.Value.Container)args[1]).Item is Edge)
            {
                thisEdge = ((FScheme.Value.Container)args[1]).Item as Edge;
            }
            else if (((FScheme.Value.Container)args[1]).Item is Reference)
            {
                Reference r = (Reference)((FScheme.Value.Container)args[1]).Item;
                if (r != null)
                {
                    Element refElem = dynRevitSettings.Doc.Document.GetElement(r.ElementId);
                    if (refElem != null)
                    {
                        GeometryObject geob = refElem.GetGeometryObjectFromReference(r);
                        thisEdge = geob as Edge;
                        if (thisEdge == null)
                        {
                            thisCurve = geob as Curve;
                        }
                    }
                    else
                    {
                        throw new Exception("Could not accept second in-port for Evaluate curve or edge node");
                    }
                }
            }
            else if (((FScheme.Value.Container)args[1]).Item is CurveElement)
            {
                CurveElement cElem = ((FScheme.Value.Container)args[1]).Item as CurveElement;
                if (cElem != null)
                {
                    thisCurve = cElem.GeometryCurve;
                }
                else
                {
                    throw new Exception("Could not accept second in-port for Evaluate curve or edge node");
                }
            }
            else
            {
                throw new Exception("Could not accept second in-port for Evaluate curve or edge node");
            }

            XYZ result = (thisCurve != null) ? (!curveIsReallyUnbound(thisCurve) ? thisCurve.Evaluate(parameter, true) : thisCurve.Evaluate(parameter, false))
                :
                         (thisEdge == null ? null : thisEdge.Evaluate(parameter));

            return(FScheme.Value.NewContainer(result));
        }
Esempio n. 9
0
        /***************************************************/

        public static CurveElement ToCurveElement(this DraftingInstance draftingInstance, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            CurveElement curveElement = refObjects.GetValue <CurveElement>(document, draftingInstance.BHoM_Guid);

            if (curveElement != null)
            {
                return(curveElement);
            }

            settings = settings.DefaultIfNull();

            if (!(draftingInstance.Location is ICurve))
            {
                return(null);
            }

            ICurve curve = (ICurve)draftingInstance.Location;

            Curve revitCurve = curve.IToRevit();

            if (revitCurve == null)
            {
                return(null);
            }

            if (!BH.Engine.Geometry.Query.IsPlanar(curve as dynamic))
            {
                return(null);
            }

            View view = Query.View(draftingInstance, document);

            if (view == null)
            {
                return(null);
            }

            curveElement = document.Create.NewDetailCurve(view, revitCurve);
            if (curveElement == null)
            {
                return(null);
            }

            if (draftingInstance.Properties != null)
            {
                string name = draftingInstance.Properties.Name;
                if (!string.IsNullOrEmpty(name))
                {
                    Element element = new FilteredElementCollector(document).OfClass(typeof(GraphicsStyle)).ToList().Find(x => x.Name == name);
                    if (element != null)
                    {
                        curveElement.LineStyle = element;
                    }
                }
            }

            refObjects.AddOrReplace(draftingInstance, curveElement);
            return(curveElement);
        }
Esempio n. 10
0
        /***************************************************/

        public static IBHoMObject FromRevit(this CurveElement curveElement, Discipline discipline, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            switch (discipline)
            {
            default:
                return(curveElement.InstanceFromRevit(settings, refObjects));
            }
        }
Esempio n. 11
0
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            var ptA = (XYZ)((FScheme.Value.Container)args[0]).Item;
            var ptB = (XYZ)((FScheme.Value.Container)args[1]).Item;

            // CurveElement c = MakeLine(this.UIDocument.Document, ptA, ptB);
            CurveElement c = MakeLineCBP(dynRevitSettings.Doc.Document, ptA, ptB);

            return(FScheme.Value.NewContainer(c));
        }
Esempio n. 12
0
        private ElementId PlaceBeam(CurveElement line, Level level, FamilySymbol beamType)
        {
            LocationCurve lc = line.Location as LocationCurve;

            if (!beamType.IsActive)
            {
                beamType.Activate();
            }
            FamilyInstance fi = _doc.Create.NewFamilyInstance(lc.Curve, beamType, level, STBEAM);

            ;
            return(fi.Id);
        }
Esempio n. 13
0
        /// <summary>
        /// 从选择的Curve Elements中,获得连续排列的多段曲线(不一定要封闭)。
        /// </summary>
        /// <param name="doc">曲线所在文档</param>
        /// <param name="SelectedCurves">多条曲线元素所对应的Reference,可以通过Selection.PickObjects返回。
        /// 注意,SelectedCurves中每一条曲线都必须是有界的(IsBound),否则,其GetEndPoint会报错。</param>
        /// <returns>如果输入的曲线可以形成连续的多段线,则返回重新排序后的多段线集合;
        /// 如果输入的曲线不能形成连续的多段线,则返回Nothing!</returns>
        public static IList <Curve> GetContiguousCurvesFromCurves(Document doc, IList <Reference> SelectedCurves)
        {
            IList <Curve> curves = new List <Curve>();

            // Build a list of curves from the curve elements
            foreach (Reference reference in SelectedCurves)
            {
                CurveElement curveElement = doc.GetElement(reference) as CurveElement;
                curves.Add(curveElement.GeometryCurve.Clone());
            }
            //
            curves = CurvesFormator.GetContiguousCurvesFromCurves(curves);
            return(curves);
        }
Esempio n. 14
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            try
            {
                IList <Reference> linesToDelete = uidoc.Selection.PickObjects(ObjectType.Element, "Select linestyles to delete");

                Category c = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);

                CategoryNameMap subcats = c.SubCategories;

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

                    foreach (Reference line in linesToDelete)
                    {
                        CurveElement curveEle = doc.GetElement(line) as CurveElement;

                        foreach (Category cat in subcats)
                        {
                            if (cat.Name == curveEle.LineStyle.Name)
                            {
                                doc.Delete(cat.Id);
                                break;
                            }
                        }
                        //Category cat = subcats.Where( x => x.Name == curveEle.LineStyle.Name).First();

                        doc.Delete(curveEle.LineStyle.Id);
                        doc.Delete(line.ElementId);
                    }
                    t.Commit();
                }

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Error", ex.Message);
                return(Result.Failed);
            }
        }
Esempio n. 15
0
        /***************************************************/

        public static IBHoMObject FromRevit(this CurveElement curveElement, Discipline discipline, Transform transform = null, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            BH.oM.Adapters.Revit.Elements.IInstance result = null;
            switch (discipline)
            {
            default:
                result = curveElement.InstanceFromRevit(settings, refObjects);
                break;
            }

            if (result is BH.oM.Adapters.Revit.Elements.ModelInstance && transform?.IsIdentity == false)
            {
                TransformMatrix bHoMTransform = transform.FromRevit();
                result = result.Transform(bHoMTransform);
            }

            return(result);
        }
Esempio n. 16
0
            public static CurveElement RequestCurveElementSelection(string message)
            {
                var doc = dynRevitSettings.Doc;

                CurveElement c = null;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                choices.Elements.Clear();

                //MessageBox.Show(message);
                DynamoLogger.Instance.Log(message);

                Reference curveRef = doc.Selection.PickObject(ObjectType.Element);

                c = dynRevitSettings.Revit.ActiveUIDocument.Document.GetElement(curveRef) as CurveElement;

                return(c);
            }
Esempio n. 17
0
 /// <summary>
 /// Returns the end point of a Curve based Element.
 /// </summary>
 /// <typeparam name="T">The type of the Element in question.</typeparam>
 /// <param name="obj">The Element where to extract the end point.</param>
 /// <param name="trf">The transform of the Origo.</param>
 /// <returns>The end point of the Element's Curve as XYZ.</returns>
 private static XYZ EndPoint <T>(T obj, Transform trf) where T : Element
 {
     if (obj == null)
     {
         return(null);
     }
     if (obj is FamilyInstance)
     {
         FamilyInstance fi  = obj as FamilyInstance;
         LocationCurve  loc = fi.Location as LocationCurve;
         return(trf.OfPoint(loc.Curve.GetEndPoint(1)));
     }
     if (obj is CurveElement)
     {
         CurveElement cu = obj as CurveElement;
         return(trf.OfPoint(cu.GeometryCurve.GetEndPoint(1)));
     }
     throw new Exception("Type not handled!");
 }
        public void Execute(UpdaterData data)
        {
            Document doc = data.GetDocument();

            if (doc.IsFamilyDocument)
            {
                try
                {
                    //Get document Name
                    string name = doc.Title;
                    if (String.IsNullOrEmpty(name))
                    {
                        name = "null";
                    }
                    //Get form location info (Varies by type?)
                    foreach (ElementId e in data.GetModifiedElementIds())
                    {
                        CurveElement ele  = doc.GetElement(e) as CurveElement;
                        var          bbox = ele.get_BoundingBox(null);
                        if (bbox != null)
                        {
                            var dims       = GetDims(bbox);
                            int prediction = Datatype.ObjectStyle.PredictSingle(name, "line", dims);
                            var gs         = ele.LineStyle as GraphicsStyle;
                            if (!gs.Name.Contains(Enum.GetNames(typeof(ObjectCategory))[prediction]))
                            {
                                if (Enum.GetNames(typeof(ObjectCategory)).Any(x => gs.Name.Contains(x)))
                                {
                                    Datatype.ObjectStyle.PropogateSingle(Enum.GetNames(typeof(ObjectCategory)).ToList().IndexOf(
                                                                             Enum.GetNames(typeof(ObjectCategory)).Where(x => gs.Name.Contains(x)).First()),
                                                                         new WriteToCMDLine(WriteNull), name, "line", dims);
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    e.OutputError();
                }
            }
        }
        /// <summary>
        /// Checks if the curve element should be exported.
        /// </summary>
        /// <param name="curveElement">
        /// The curve element.
        /// </param>
        /// <returns>
        /// True if the curve element should be exported, false otherwise.
        /// </returns>
        private static bool ShouldCurveElementBeExported(CurveElement curveElement)
        {
            CurveElementType curveElementType = curveElement.CurveElementType;
            bool             exported         = false;

            if (curveElementType == CurveElementType.ModelCurve || curveElementType == CurveElementType.CurveByPoints)
            {
                exported = true;
            }

            if (exported)
            {
                // Confirm curve is not used by another element
                exported = !ExporterIFCUtils.IsCurveFromOtherElementSketch(curveElement);

                // Confirm the geometry curve is valid.
                Curve curve = curveElement.GeometryCurve;

                if (curve == null)
                {
                    exported = false;
                }
                else if (curve is Line)
                {
                    if (!curve.IsBound)
                    {
                        exported = false;
                    }
                    else
                    {
                        XYZ end1 = curve.GetEndPoint(0);
                        XYZ end2 = curve.GetEndPoint(1);
                        if (end1.IsAlmostEqualTo(end2))
                        {
                            exported = false;
                        }
                    }
                }
            }

            return(exported);
        }
Esempio n. 20
0
        /// <summary>
        /// 尺寸标注单根直线元素-详图线 模型线
        /// </summary>
        public static Dimension DimensionLineElement(this Document doc, CurveElement curveElement)
        {
            Dimension dimension = null;

            if (!(curveElement is DetailLine) && !(curveElement is ModelLine))
            {
                return(dimension);
            }

            ReferenceArray referenceArray = new ReferenceArray();

            // 方法一
            //Options options = new Options();
            //options.View = doc.ActiveView;
            //options.ComputeReferences = true;
            //GeometryElement geometryElement = curveElement.get_Geometry(options);
            //Line line = geometryElement.First() as Line;

            // 方法二
            Line line = curveElement.GeometryCurve as Line;

            referenceArray.Append(line.GetEndPointReference(0));
            referenceArray.Append(line.GetEndPointReference(1));
            // 方法三 无效
            // Line line = (curveElement.Location as LocationCurve).Curve as Line;

            // 【】移动标注线的位置
            //double distanceMove = 2000.0.MilliMeterToFeet();
            //distanceMove = distanceMove.MilliMeterToFeet();

            //XYZ xyzDirection = line.Direction.CrossProduct(new XYZ(0,0,1)).Normalize();

            //line = line.CreateOffset(distanceMove, xyzDirection) as Line;

            using (Transaction trans = new Transaction(doc, "轴网端头尺寸标注"))
            {
                trans.Start();
                dimension = doc.Create.NewDimension(doc.ActiveView, line, referenceArray);
                trans.Commit();
            }
            return(dimension);
        }
Esempio n. 21
0
        /// <summary>
        /// Gets a list of curves which are ordered correctly and oriented correctly to form a closed loop.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="boundaries">The list of curve element references which are the boundaries.</param>
        /// <returns>The list of curves.</returns>
        public static IList <Curve> GetContiguousCurvesFromSelectedCurveElements(Document doc, IList <Reference> boundaries)
        {
            List <Curve> curves = new List <Curve>();

            // Build a list of curves from the curve elements
            foreach (Reference reference in boundaries)
            {
                CurveElement curveElement = doc.GetElement(reference) as CurveElement;
                curves.Add(curveElement.GeometryCurve.Clone());
            }

            // Walk through each curve (after the first) to match up the curves in order
            for (int i = 0; i < curves.Count; i++)
            {
                Curve curve    = curves[i];
                XYZ   endPoint = curve.GetEndPoint(1);

                // find curve with start point = end point
                for (int j = i + 1; j < curves.Count; j++)
                {
                    // Is there a match end->start, if so this is the next curve
                    if (curves[j].GetEndPoint(0).IsAlmostEqualTo(endPoint, 1e-05))
                    {
                        Curve tmpCurve = curves[i + 1];
                        curves[i + 1] = curves[j];
                        curves[j]     = tmpCurve;
                        continue;
                    }
                    // Is there a match end->end, if so, reverse the next curve
                    else if (curves[j].GetEndPoint(1).IsAlmostEqualTo(endPoint, 1e-05))
                    {
                        Curve tmpCurve = curves[i + 1];
                        curves[i + 1] = CreateReversedCurve(curves[j]);
                        curves[j]     = tmpCurve;
                        continue;
                    }
                }
            }

            return(curves);
        }
        public bool AllowElement(Element element)
        {
            // Allow only curve elements
            CurveElement curveElement = element as CurveElement;

            if (curveElement == null)
            {
                return(false);
            }

            Curve curve = curveElement.GeometryCurve;

            // Curves must support the utilities used by the tool (e.g. ReverseCurve)
            if (!FreeFormElementUtils.SupportsLoopUtilities(curve))
            {
                return(false);
            }

            // Curves must be in XY plane
            return(FreeFormElementUtils.IsCurveInXYPlane(curve));
        }
Esempio n. 23
0
        /// <summary>
        /// Return a list of curves which are correctly
        /// ordered and oriented to form a closed loop.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="boundaries">The list of curve element references which are the boundaries.</param>
        /// <returns>The list of curves.</returns>
        public static IList <Curve> GetContiguousCurvesFromSelectedCurveElements(
            Document doc,
            IList <Reference> boundaries,
            bool debug_output)
        {
            List <Curve> curves = new List <Curve>();

            // Build a list of curves from the curve elements

            foreach (Reference reference in boundaries)
            {
                CurveElement curveElement = doc.GetElement(
                    reference) as CurveElement;

                curves.Add(curveElement.GeometryCurve.Clone());
            }

            SortCurvesContiguous(doc.Application.Create,
                                 curves, debug_output);

            return(curves);
        }
Esempio n. 24
0
        public static void ListLineStyles(UIDocument uiDoc)
        {
            Document  currentDoc = uiDoc.Document;
            Selection sel        = uiDoc.Selection;
            XYZ       BasePt     = sel.PickPoint();

            FilteredElementCollector LineCollector = new FilteredElementCollector(currentDoc);
            List <ElementId>         Lines         = LineCollector.OfCategory(BuiltInCategory.OST_Lines).ToElementIds().ToList();
            FilteredElementCollector txtCollector  = new FilteredElementCollector(currentDoc);
            ElementId txtnoteTypeId = txtCollector.OfCategory(BuiltInCategory.OST_TextNotes).FirstElement().GetTypeId();

            int adjustment = 10;
            Dictionary <string, CurveElement> LineStyles = new Dictionary <string, CurveElement>();

            for (int i = 0; i < Lines.Count(); i++)
            {
                CurveElement l = currentDoc.GetElement(Lines[i]) as CurveElement;
                if (!LineStyles.Keys.Contains(l.LineStyle.Name))
                {
                    LineStyles.Add(l.LineStyle.Name, l);
                }
            }
            List <string> StyleName = LineStyles.Keys.ToList();

            StyleName.Sort();
            for (int i = 0; i < StyleName.Count(); i++)
            {
                XYZ startpoint = new XYZ(BasePt.X, (BasePt.Y - (adjustment * i)), 0);
                XYZ endpoint   = new XYZ((BasePt.X + (adjustment * 3)), (BasePt.Y - (adjustment * i)), 0);
                XYZ TextPoint  = new XYZ(BasePt.X + (adjustment * 4), (BasePt.Y - (adjustment * i)), 0);

                Curve       baseCurve = Line.CreateBound(startpoint, endpoint) as Curve;
                DetailCurve addedLine = currentDoc.Create.NewDetailCurve(uiDoc.ActiveView, baseCurve);

                TextNote txNote = TextNote.Create(currentDoc, uiDoc.ActiveView.Id, TextPoint, StyleName[i], txtnoteTypeId);
                addedLine.LineStyle = LineStyles[StyleName[i]].LineStyle;
            }
        }
Esempio n. 25
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static IInstance InstanceFromRevit(this CurveElement curveElement, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            settings = settings.DefaultIfNull();

            IInstance instance = refObjects.GetValue <ModelInstance>(curveElement.Id);

            if (instance != null)
            {
                return(instance);
            }

            InstanceProperties instanceProperties = (curveElement.LineStyle as GraphicsStyle).InstancePropertiesFromRevit(settings, refObjects) as InstanceProperties;

            if (curveElement.ViewSpecific)
            {
                View view = curveElement.Document.GetElement(curveElement.OwnerViewId) as View;
                if (view == null)
                {
                    return(null);
                }

                instance = BH.Engine.Adapters.Revit.Create.DraftingInstance(instanceProperties, view.Name, curveElement.GeometryCurve.IFromRevit());
            }
            else
            {
                instance = BH.Engine.Adapters.Revit.Create.ModelInstance(instanceProperties, curveElement.GeometryCurve.IFromRevit());
            }

            instance.Name = curveElement.Name;

            //Set identifiers, parameters & custom data
            instance.SetIdentifiers(curveElement);
            instance.CopyParameters(curveElement, settings.ParameterSettings);
            instance.SetProperties(curveElement, settings.ParameterSettings);

            refObjects.AddOrReplace(curveElement.Id, instance);
            return(instance);
        }
Esempio n. 26
0
        public IList <Curve> GetCurves(UIDocument uidoc)
        {
            IList <Curve>     c     = new List <Curve>();
            IList <Reference> rList = uidoc.Selection.PickObjects(ObjectType.Element);

            foreach (Reference reference in rList)
            {
                Element r = uidoc.Document.GetElement(reference);
                if (r is CurveElement)
                {
                    CurveElement m     = r as CurveElement;
                    Curve        curve = m.GeometryCurve;
                    c.Add(curve);
                }
                //else if(r is DetailCurve)
                //{
                //    DetailCurve m = r as DetailCurve;
                //    Curve curve = m.GeometryCurve;
                //    c.Add(curve);
                //}//只能拾取单体线段
            }
            return(c);
        }
Esempio n. 27
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var    input = args[0];
            double xi;                         //, x0, xs;

            xi = ((Value.Number)args[1]).Item; // Number
            //x0 = ((Value.Number)args[2]).Item;// Starting Coord
            //xs = ((Value.Number)args[3]).Item;// Spacing

            DividedPath      divPath;
            List <Reference> refList = new List <Reference>();

            // this node can take one or more curve elements and create one or more divided path elements
            // input is one or more user-selected curves for now
            // todo: - create a utility function that can handle curve loops and convert them into lists, perhaps makes this a node or just an allowed input of this node
            //       - enhance curve by selection node to handle multiple picks
            //       - allow selection of a family instance to extract a curve loop or reference list
            //
            // process input curve elements
            // - if we pass in a single curve element, we will extract it's reference and pass that into the divided path creation method
            // - if we pass in a collection of curve elements, we want to make a divided path for each curve from that collection
            //    for each curve element in list,
            //      manage curve list (determine whether we already had used that curve before to make this divided path, add new curves, remove old curves)
            //      extract curve refs for each curve element and create divided path
            //      update params of for the div path
            //  this.Elements should only hold divided paths not curves.
            // node should return a list of divided paths

            if (input.IsList)
            {
                refList.Clear();

                var curveList = (input as Value.List).Item;

                //Counter to keep track of how many references and divided path. We'll use this to delete old
                //elements later.
                int count = 0;


                //We create our output by...
                var result = Utils.SequenceToFSharpList(
                    curveList.Select(
                        //..taking each curve in the list and...
                        delegate(Value x)
                {
                    //Reference r;
                    CurveElement c;

                    //...check to see if we already have a divided node made by this curve in a previous run
                    if (this.Elements.Count > count)
                    {
                        Element e;

                        //...we attempt to fetch it from the document...
                        if (dynUtils.TryGetElement(this.Elements[count], typeof(DividedPath), out e))
                        {
                            //...if we find a divided path and if we're successful matching it to the doc, update it's properties...
                            divPath = e as DividedPath;

                            if (divPath != null)
                            {
                                divPath.FixedNumberOfPoints = (int)xi;
                            }
                            else
                            {
                                //...otherwise, we can make a new divided path and replace it in the list of
                                //previously created divided paths.
                                //...we extract a curve element from the container.
                                c = (CurveElement)((Value.Container)x).Item;
                                //...we create a new curve ref
                                Curve crvRef = c.GeometryCurve;
                                refList.Add(crvRef.Reference);
                                divPath = Autodesk.Revit.DB.DividedPath.Create(this.UIDocument.Document, refList);
                                divPath.FixedNumberOfPoints = (int)xi;
                                this.Elements[count]        = divPath.Id;
                                refList.Clear();
                            }
                        }
                        else
                        {
                            //...otherwise, we can make a new divided path and replace it in the list of
                            //previously created divided paths.
                            //...we extract a curve element from the container.
                            c = (CurveElement)((Value.Container)x).Item;
                            //...we create a new curve ref
                            Curve crvRef = c.GeometryCurve;
                            refList.Add(crvRef.Reference);
                            divPath = Autodesk.Revit.DB.DividedPath.Create(this.UIDocument.Document, refList);
                            divPath.FixedNumberOfPoints = (int)xi;
                            this.Elements[count]        = divPath.Id;
                            refList.Clear();
                        }
                    }
                    //...otherwise...
                    else
                    {
                        //...we extract a curve element from the container.
                        c = (CurveElement)((Value.Container)x).Item;
                        //...we create a new curve ref
                        Curve crvRef = c.GeometryCurve;
                        refList.Add(crvRef.Reference);
                        divPath = Autodesk.Revit.DB.DividedPath.Create(this.UIDocument.Document, refList);
                        divPath.FixedNumberOfPoints = (int)xi;
                        //...and store the element in the element list for future runs.
                        this.Elements.Add(divPath.Id);
                        refList.Clear();
                    }
                    //Finally, we update the counter, and return a new Value containing the reference list.

                    count++;
                    return(Value.NewContainer(divPath));
                }
                        )
                    );

                //Now that we've added all the divided paths from this run, we delete all of the
                //extra ones from the previous run.
                foreach (var eid in this.Elements.Skip(count))
                {
                    this.DeleteElement(eid); // remove unused divided paths
                }


                return(Value.NewList(result));
            }

            //If we're not receiving a list, we will just assume we received one curve.
            else
            {
                refList.Clear();

                CurveElement c = (CurveElement)((Value.Container)input).Item;


                FSharpList <Value> result = FSharpList <Value> .Empty;

                //double x = x0;
                Curve crvRef = c.GeometryCurve;

                refList.Add(crvRef.Reference);

                //If we've made any elements previously...
                if (this.Elements.Any())
                {
                    Element e;
                    //...try to get the first one...
                    if (dynUtils.TryGetElement(this.Elements[0], typeof(DividedPath), out e))
                    {
                        //..and if we do, update it's data.
                        divPath = e as DividedPath;
                        divPath.FixedNumberOfPoints = (int)xi;
                    }
                    else
                    {
                        //...otherwise, just make a new one and replace it in the list.
                        divPath = Autodesk.Revit.DB.DividedPath.Create(this.UIDocument.Document, refList);
                        divPath.FixedNumberOfPoints = (int)xi;
                        this.Elements[0]            = divPath.Id;
                    }

                    //We still delete all extra elements, since in the previous run we might have received a list.
                    foreach (var el in this.Elements.Skip(1))
                    {
                        this.DeleteElement(el);
                    }
                }
                //...otherwise...
                else
                {
                    //...just make a divided curve and store it.
                    divPath = Autodesk.Revit.DB.DividedPath.Create(this.UIDocument.Document, refList);
                    divPath.FixedNumberOfPoints = (int)xi;
                    this.Elements.Add(divPath.Id);
                }
                refList.Clear();

                //Fin
                return(Value.NewContainer(divPath));
            }
        }
Esempio n. 28
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;          //取得当前活动文档

            UIApplication uiApp = commandData.Application;

            //载入族轮廓并激活
            string file1 = @"C:\Users\zyx\Desktop\2RevitArcBridge\Test\Test\xxxx.rfa"; //轮廓族的文件路径来这里输入一下
            string file2 = @"C:\Users\zyx\Desktop\2RevitArcBridge\Test\Test\aaaa.rfa"; //轮廓族的文件路径来这里输入一下

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            IList <Reference> modelLines = null;

            //新建一个窗口
            Window1 window1 = new Window1();

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


            //按键会改变window的属性,通过对属性的循环判断来实现对按键的监测
            while (!window1.Done)
            {
                //选择平曲线
                if (window1.FlatCurveSelected)
                {
                    //因为要对原有模型线进行一个删除是对文件进行一个删除,故要创建一个事件
                    using (Transaction transaction = new Transaction(uiDoc.Document))
                    {
                        transaction.Start("选择平曲线");

                        //选择平曲线
                        Selection sel = uiDoc.Selection;
                        modelLines = sel.PickObjects(ObjectType.Element, "选一组模型线");

                        //2、重置window1.FlatCurve

                        window1.FlatCurveSelected = false;


                        transaction.Commit();
                    }
                }

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



            List <FamilySymbol> fList1 = new List <FamilySymbol>();
            List <FamilySymbol> fList2 = new List <FamilySymbol>();

            //对每条模型线进行放样拉伸
            foreach (Reference reference in modelLines)
            {
                Element      elem         = revitDoc.GetElement(reference);
                CurveElement curveElement = elem as CurveElement;

                //在项目中创建公制常规模型
                FamilySymbol familySymbol1 = createSweepFamilySymbol(commandData, curveElement, file1, true);
                FamilySymbol familySymbol2 = createSweepFamilySymbol(commandData, curveElement, file2, false);

                fList1.Add(familySymbol1);
                fList2.Add(familySymbol2);
            }



            //族实例激活并放到指定位置;剪切
            for (int i = 0; i < fList1.Count(); i++)
            {
                FamilyInstance familyInstance2;
                string         tName = i + "族实例放样";
                using (Transaction transaction = new Transaction(revitDoc))
                {
                    transaction.Start(tName);

                    //在项目中激活族并放置到位
                    fList1[i].Activate();
                    fList2[i].Activate();

                    FamilyInstance familyInstance1 = revitDoc.Create.NewFamilyInstance(XYZ.Zero, fList1[i], Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                    familyInstance2 = revitDoc.Create.NewFamilyInstance(XYZ.Zero, fList2[i], Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

                    transaction.Commit();
                }

                tName = i + "剪切";
                using (Transaction transaction = new Transaction(revitDoc))
                {
                    transaction.Start(tName);

                    Selection selend   = uiDoc.Selection;
                    Reference refend   = selend.PickObject(ObjectType.Element, "选择族实例");
                    Element   elemet1  = revitDoc.GetElement(refend);
                    Element   element2 = revitDoc.GetElement(familyInstance2.Id);

                    InstanceVoidCutUtils.AddInstanceVoidCut(revitDoc, elemet1, element2);//空心剪切

                    transaction.Commit();
                }
            }


            return(Result.Succeeded);
        }
Esempio n. 29
0
        private FamilySymbol createSweepFamilySymbol(ExternalCommandData commandData, CurveElement curveElement, string filePath, bool v)
        {
            Document    revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档
            Application revitApp = commandData.Application.Application;               //取得应用程序
            UIDocument  uiDoc    = commandData.Application.ActiveUIDocument;          //取得当前活动文档

            //创建一个族文档
            Document familyDoc = revitDoc.Application.NewFamilyDocument(@"C:\ProgramData\Autodesk\RVT 2020\Family Templates\Chinese\公制常规模型.rft");

            FamilySymbol profileFamilySymbol;

            //在族文件中载入轮廓族
            using (Transaction transaction = new Transaction(familyDoc))
            {
                transaction.Start("载入族");

                string ProfilePath = filePath;                                             //轮廓族的路径来这里输入一下
                bool   loadSuccess = familyDoc.LoadFamily(ProfilePath, out Family family); //在族文件中载入轮廓族
                string familyName  = family.Name;
                //获取族文件的族类型
                if (loadSuccess)
                {
                    //假如成功导入
                    //得到族模板
                    ElementId        elementId;
                    ISet <ElementId> symbols = family.GetFamilySymbolIds();
                    elementId           = symbols.First();
                    profileFamilySymbol = familyDoc.GetElement(elementId) as FamilySymbol;
                }
                else
                {
                    //假如已经导入,则通过名字找到这个族
                    FilteredElementCollector collector = new FilteredElementCollector(familyDoc);
                    collector.OfClass(typeof(Family));//过滤得到文档中所有的族
                    IList <Element> families = collector.ToElements();
                    profileFamilySymbol = null;
                    foreach (Element e in families)
                    {
                        Family f = e as Family;
                        //通过名字进行筛选
                        if (f.Name == familyName)
                        {
                            profileFamilySymbol = familyDoc.GetElement(f.GetFamilySymbolIds().First()) as FamilySymbol;
                            break;
                        }
                    }
                }

                transaction.Commit();
            }

            //在族文件中拉伸放样,并进行一些参数设置
            using (Transaction transaction = new Transaction(familyDoc))
            {
                transaction.Start("内建模型");

                SweepProfile sweepProfile = familyDoc.Application.Create.NewFamilySymbolProfile(profileFamilySymbol);    //从轮廓族里面获取到轮廓

                //在族平面内画一条线,该线的位置与在项目文件中的位置完全一致
                Plane       plane       = curveElement.SketchPlane.GetPlane();
                SketchPlane sketchPlane = SketchPlane.Create(familyDoc, plane);
                ModelCurve  modelCurve  = familyDoc.FamilyCreate.NewModelCurve(curveElement.GeometryCurve, sketchPlane);
                //将线设置为放样路径
                ReferenceArray path = new ReferenceArray();
                path.Append(modelCurve.GeometryCurve.Reference);
                //创建放样
                Sweep sweep1 = familyDoc.FamilyCreate.NewSweep(v, path, sweepProfile, 0, ProfilePlaneLocation.Start);


                //设置该族文件中的空心放样可以去切割别的实例,为空心放样做准备
                Parameter p = familyDoc.OwnerFamily.get_Parameter(BuiltInParameter.FAMILY_ALLOW_CUT_WITH_VOIDS);
                p.Set(1);

                transaction.Commit();
            }

            //获取族类型
            Family       loadFamily   = familyDoc.LoadFamily(revitDoc);                                               //在项目中载入这个族
            FamilySymbol familySymbol = revitDoc.GetElement(loadFamily.GetFamilySymbolIds().First()) as FamilySymbol; //获取到组类型

            return(familySymbol);
        }
Esempio n. 30
0
        private void Stream( ArrayList data, CurveElement curElem )
        {
            data.Add( new Snoop.Data.ClassSeparator( typeof( CurveElement ) ) );

              data.Add( new Snoop.Data.Object( "Geometry curve", curElem.GeometryCurve ) );
              data.Add( new Snoop.Data.Object( "Line style", curElem.LineStyle ) );
              data.Add( new Snoop.Data.Enumerable( "Line styles", curElem.GetLineStyleIds(), curElem.Document ) );
              data.Add( new Snoop.Data.Object( "Sketch plane", curElem.SketchPlane ) );

              CurveByPoints curPts = curElem as CurveByPoints;
              if( curPts != null )
              {
            Stream( data, curPts );
            return;
              }

              DetailCurve detCurve = curElem as DetailCurve;
              if( detCurve != null )
              {
            Stream( data, detCurve );
            return;
              }

              ModelCurve modelCurve = curElem as ModelCurve;
              if( modelCurve != null )
              {
            Stream( data, modelCurve );
            return;
              }

              SymbolicCurve symCurve = curElem as SymbolicCurve;
              if( symCurve != null )
              {
            Stream( data, symCurve );
            return;
              }
        }
        /// <summary>
        /// Exports a curve element to IFC curve annotation.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="curveElement">
        /// The curve element to be exported.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="productWrapper">
        /// The ProductWrapper.
        /// </param>
        public static void ExportCurveElement(ExporterIFC exporterIFC, CurveElement curveElement, GeometryElement geometryElement,
                                              ProductWrapper productWrapper)
        {
            if (geometryElement == null || !ShouldCurveElementBeExported(curveElement))
            {
                return;
            }

            SketchPlane sketchPlane = curveElement.SketchPlane;

            if (sketchPlane == null)
            {
                return;
            }

            // Check the intended IFC entity or type name is in the exclude list specified in the UI
            Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcAnnotation;
            if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, curveElement))
                {
                    IFCAnyHandle localPlacement = setter.LocalPlacement;
                    IFCAnyHandle axisPlacement  = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement);

                    Plane planeSK      = sketchPlane.GetPlane();
                    XYZ   projDir      = planeSK.Normal;
                    XYZ   origin       = planeSK.Origin;
                    bool  useOffsetTrf = false;
                    if (projDir.IsAlmostEqualTo(XYZ.BasisZ))
                    {
                        XYZ offset = XYZ.BasisZ * setter.Offset;
                        origin -= offset;
                    }
                    else
                    {
                        useOffsetTrf = true;
                    }

                    Transform curveLCS = GeometryUtil.CreateTransformFromPlane(planeSK);
                    curveLCS.Origin = origin;

                    IList <IFCAnyHandle> curves = null;

                    if (ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView)
                    {
                        Transform trf = null;
                        if (useOffsetTrf)
                        {
                            XYZ offsetOrig = -XYZ.BasisZ * setter.Offset;
                            trf = Transform.CreateTranslation(offsetOrig);
                        }

                        curves = new List <IFCAnyHandle>();
                        //Curve curve = (geometryElement as GeometryObject) as Curve;
                        List <Curve> curvesFromGeomElem = GeometryUtil.GetCurvesFromGeometryElement(geometryElement);
                        foreach (Curve curve in curvesFromGeomElem)
                        {
                            IFCAnyHandle curveHnd = GeometryUtil.CreatePolyCurveFromCurve(exporterIFC, curve, trf);
                            //IList<int> segmentIndex = null;
                            //IList<IList<double>> pointList = GeometryUtil.PointListFromCurve(exporterIFC, curve, trf, null, out segmentIndex);

                            //// For now because of no support in creating IfcLineIndex and IfcArcIndex yet, it is set to null
                            ////IList<IList<int>> segmentIndexList = new List<IList<int>>();
                            ////segmentIndexList.Add(segmentIndex);
                            //IList<IList<int>> segmentIndexList = null;

                            //IFCAnyHandle pointListHnd = IFCInstanceExporter.CreateCartesianPointList3D(file, pointList);
                            //IFCAnyHandle curveHnd = IFCInstanceExporter.CreateIndexedPolyCurve(file, pointListHnd, segmentIndexList, false);

                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(curveHnd))
                            {
                                curves.Add(curveHnd);
                            }
                        }
                    }
                    else
                    {
                        IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, curveLCS, projDir, false);

                        if (useOffsetTrf)
                        {
                            XYZ       offsetOrig = -XYZ.BasisZ * setter.Offset;
                            Transform trf        = Transform.CreateTranslation(offsetOrig);
                            ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false, trf);
                        }
                        else
                        {
                            ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false);
                        }

                        curves = info.GetCurves();
                    }

                    if (curves.Count != 1)
                    {
                        throw new Exception("IFC: expected 1 curve when export curve element.");
                    }

                    HashSet <IFCAnyHandle> curveSet   = new HashSet <IFCAnyHandle>(curves);
                    IFCAnyHandle           repItemHnd = IFCInstanceExporter.CreateGeometricCurveSet(file, curveSet);

                    IFCAnyHandle curveStyle = file.CreateStyle(exporterIFC, repItemHnd);

                    CurveAnnotationCache annotationCache = ExporterCacheManager.CurveAnnotationCache;
                    IFCAnyHandle         curveAnno       = annotationCache.GetAnnotation(sketchPlane.Id, curveStyle);
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(curveAnno))
                    {
                        AddCurvesToAnnotation(curveAnno, curves);
                    }
                    else
                    {
                        curveAnno = CreateCurveAnnotation(exporterIFC, curveElement, curveElement.Category.Id, sketchPlane.Id, curveLCS, curveStyle, setter, localPlacement, repItemHnd);
                        productWrapper.AddAnnotation(curveAnno, setter.LevelInfo, true);

                        annotationCache.AddAnnotation(sketchPlane.Id, curveStyle, curveAnno);
                    }
                }
                transaction.Commit();
            }
        }
Esempio n. 32
0
        /// <summary>
        /// Exports a curve element to IFC curve annotation.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="curveElement">
        /// The curve element to be exported.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void ExportCurveElement(ExporterIFC exporterIFC, CurveElement curveElement, GeometryElement geometryElement,
                                              IFCProductWrapper productWrapper)
        {
            if (geometryElement == null || !ShouldCurveElementBeExported(curveElement))
            {
                return;
            }

            SketchPlane sketchPlane = curveElement.SketchPlane;

            if (sketchPlane == null)
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, curveElement))
                {
                    IFCAnyHandle localPlacement = setter.GetPlacement();
                    IFCAnyHandle axisPlacement  = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement);

                    Plane planeSK      = sketchPlane.Plane;
                    XYZ   projDir      = planeSK.Normal;
                    XYZ   origin       = planeSK.Origin;
                    bool  useOffsetTrf = false;
                    if (projDir.IsAlmostEqualTo(XYZ.BasisZ))
                    {
                        XYZ offset = XYZ.BasisZ * setter.Offset;
                        origin -= offset;
                    }
                    else
                    {
                        useOffsetTrf = true;
                    }

                    Plane           plane = new Plane(planeSK.XVec, planeSK.YVec, origin);
                    IFCGeometryInfo info  = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, plane, projDir, false);

                    if (useOffsetTrf)
                    {
                        XYZ       offsetOrig = -XYZ.BasisZ * setter.Offset;
                        Transform trf        = Transform.get_Translation(offsetOrig);
                        ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false, trf);
                    }
                    else
                    {
                        ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false);
                    }

                    IList <IFCAnyHandle> curves = info.GetCurves();

                    if (curves.Count != 1)
                    {
                        throw new Exception("IFC: expected 1 curve when export curve element.");
                    }

                    HashSet <IFCAnyHandle> curveSet   = new HashSet <IFCAnyHandle>(curves);
                    IFCAnyHandle           repItemHnd = IFCInstanceExporter.CreateGeometricCurveSet(file, curveSet);

                    IFCAnyHandle curveStyle = file.CreateStyle(exporterIFC, repItemHnd);

                    CurveAnnotationCache annotationCache = ExporterCacheManager.CurveAnnotationCache;
                    IFCAnyHandle         curveAnno       = annotationCache.GetAnnotation(sketchPlane.Id, curveStyle);
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(curveAnno))
                    {
                        AddCurvesToAnnotation(curveAnno, curves);
                    }
                    else
                    {
                        curveAnno = CreateCurveAnnotation(exporterIFC, curveElement, curveElement.Category.Id, sketchPlane.Id, plane, curveStyle, setter, localPlacement, repItemHnd);
                        productWrapper.AddAnnotation(curveAnno, setter.GetLevelInfo(), true);

                        annotationCache.AddAnnotation(sketchPlane.Id, curveStyle, curveAnno);
                    }
                }
                transaction.Commit();
            }
        }
Esempio n. 33
0
        /// <summary>
        /// Exports a curve element to IFC curve annotation.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="curveElement">
        /// The curve element to be exported.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="productWrapper">
        /// The ProductWrapper.
        /// </param>
        public static void ExportCurveElement(ExporterIFC exporterIFC, CurveElement curveElement, GeometryElement geometryElement,
                                               ProductWrapper productWrapper)
        {
            if (geometryElement == null || !ShouldCurveElementBeExported(curveElement))
                return;

            SketchPlane sketchPlane = curveElement.SketchPlane;
            if (sketchPlane == null)
                return;

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction transaction = new IFCTransaction(file))
            {
                using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, curveElement))
                {
                    IFCAnyHandle localPlacement = setter.LocalPlacement;
                    IFCAnyHandle axisPlacement = GeometryUtil.GetRelativePlacementFromLocalPlacement(localPlacement);

                    Plane planeSK = sketchPlane.GetPlane();
                    XYZ projDir = planeSK.Normal;
                    XYZ origin = planeSK.Origin;
                    bool useOffsetTrf = false;
                    if (projDir.IsAlmostEqualTo(XYZ.BasisZ))
                    {
                        XYZ offset = XYZ.BasisZ * setter.Offset;
                        origin -= offset;
                    }
                    else
                        useOffsetTrf = true;

                    Plane plane = new Plane(planeSK.XVec, planeSK.YVec, origin);
                    IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, plane, projDir, false);

                    if (useOffsetTrf)
                    {
                        XYZ offsetOrig = -XYZ.BasisZ * setter.Offset;
                        Transform trf = Transform.CreateTranslation(offsetOrig);
                        ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false, trf);
                    }
                    else
                    {
                        ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false);
                    }

                    IList<IFCAnyHandle> curves = info.GetCurves();

                    if (curves.Count != 1)
                    {
                        throw new Exception("IFC: expected 1 curve when export curve element.");
                    }

                    HashSet<IFCAnyHandle> curveSet = new HashSet<IFCAnyHandle>(curves);
                    IFCAnyHandle repItemHnd = IFCInstanceExporter.CreateGeometricCurveSet(file, curveSet);

                    IFCAnyHandle curveStyle = file.CreateStyle(exporterIFC, repItemHnd);

                    CurveAnnotationCache annotationCache = ExporterCacheManager.CurveAnnotationCache;
                    IFCAnyHandle curveAnno = annotationCache.GetAnnotation(sketchPlane.Id, curveStyle);
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(curveAnno))
                    {
                        AddCurvesToAnnotation(curveAnno, curves);
                    }
                    else
                    {
                        curveAnno = CreateCurveAnnotation(exporterIFC, curveElement, curveElement.Category.Id, sketchPlane.Id, plane, curveStyle, setter, localPlacement, repItemHnd);
                        productWrapper.AddAnnotation(curveAnno, setter.LevelInfo, true);

                        annotationCache.AddAnnotation(sketchPlane.Id, curveStyle, curveAnno);
                    }
                }
                transaction.Commit();
            }
        }
        /// <summary>
        /// Exports a curve element to IFC curve annotation.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="curveElement">
        /// The curve element to be exported.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void ExportCurveElement(ExporterIFC exporterIFC, CurveElement curveElement, GeometryElement geometryElement,
                                               IFCProductWrapper productWrapper, CurveAnnotationCache annotationCache)
        {
            if (geometryElement == null || !ShouldCurveElementBeExported(curveElement))
                return;

            SketchPlane sketchPlane = curveElement.SketchPlane;
            if (sketchPlane == null)
                return;

            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, curveElement))
                {
                    IFCAnyHandle localPlacement = setter.GetPlacement();
                    IFCAnyHandle axisPlacement = file.Create3DAxisFromLocalPlacement(localPlacement);

                    Plane planeSK = sketchPlane.Plane;
                    XYZ projDir = planeSK.Normal;
                    XYZ origin = planeSK.Origin;
                    bool useOffsetTrf = false;
                    if (projDir.IsAlmostEqualTo(XYZ.BasisZ))
                    {
                        XYZ offset = XYZ.BasisZ * setter.Offset;
                        origin -= offset;
                    }
                    else
                        useOffsetTrf = true;

                    Plane plane = new Plane(planeSK.XVec, planeSK.YVec, origin);
                    IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, plane, projDir, false);

                    if (useOffsetTrf)
                    {
                        XYZ offsetOrig = -XYZ.BasisZ * setter.Offset;
                        Transform trf = Transform.get_Translation(offsetOrig);
                        ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false, trf);
                    }
                    else
                    {
                        ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, geometryElement, XYZ.Zero, false);
                    }

                    IList<IFCAnyHandle> curves = info.GetCurves();

                    if (curves.Count != 1)
                    {
                        throw new Exception("IFC: expected 1 curve when export curve element.");
                    }

                    IFCAnyHandle repItemHnd = file.CreateGeometricCurveSet(curves);

                    IFCAnyHandle curveStyle = file.CreateStyle(exporterIFC, repItemHnd);

                    //IFCAnyHandle curveAnno = ExporterIFCUtils.GetCurveAnnotation(exporterIFC, sketchPlane.Id, curveStyle);
                    IFCAnyHandle curveAnno = annotationCache.GetAnnotation(sketchPlane.Id, curveStyle);
                    if (curveAnno != null && curveAnno.HasValue)
                    {
                        ExporterIFCUtils.AddCurveToAnnotation(curveAnno, curves[0]);
                    }
                    else
                    {
                        curveAnno = ExporterIFCUtils.CreateCurveAnnotation(exporterIFC, curveElement.Category.Id, sketchPlane.Id, plane, curveStyle, setter, localPlacement, repItemHnd);

                        annotationCache.AddAnnotation(sketchPlane.Id, curveStyle, curveAnno);
                    }
                }
                tr.Commit();
            }
        }