private void InitRebarBarType(double diameter, Autodesk.Revit.DB.Structure.RebarDeformationType deformationType)
        {
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(document);

            var barTypeElem = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Structure.RebarBarType>(document);

            if (barTypeElem == null)
            {
                barTypeElem = Autodesk.Revit.DB.Structure.RebarBarType.Create(document);
            }

            barTypeElem.BarDiameter     = diameter;
            barTypeElem.DeformationType = deformationType;

            TransactionManager.Instance.TransactionTaskDone();


            if (barTypeElem != null)
            {
                ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement);
            }
            else
            {
                ElementBinder.SetElementForTrace(this.InternalElement);
            }
        }
Example #2
0
        /// <summary>
        /// Initialize a GroupType element from a set of objects ids
        /// </summary>
        /// <param name="ids"></param>
        private void InitGroupType(ICollection <DB.ElementId> ids)
        {
            DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            // This creates a new wall and deletes the old one
            TransactionManager.Instance.EnsureInTransaction(document);

            //Phase 1 - Check to see if the object exists and should be rebound
            var GroupTypeElem = ElementBinder.GetElementFromTrace <DB.GroupType>(document);

            if (GroupTypeElem == null)
            {
                GroupTypeElem = document.Create.NewGroup(ids).GroupType;
            }

            InternalSetGroupType(GroupTypeElem);

            TransactionManager.Instance.TransactionTaskDone();

            if (GroupTypeElem != null)
            {
                ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement);
            }
            else
            {
                ElementBinder.SetElementForTrace(this.InternalElement);
            }
        }
Example #3
0
        private void InitImageView(Autodesk.Revit.DB.ImageExportOptions options)
        {
            // Phase 1 - Check to see if the object exists and should be rebound
            var doc    = DocumentManager.Instance.CurrentDBDocument;
            var oldEle = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ImageView>(doc);

            // Rebind to Element
            if (oldEle != null)
            {
                InternalSetImageView(oldEle);
                return;
            }

            // Phase 2 - There was no existing Element, create new one
            TransactionManager.Instance.EnsureInTransaction(doc);

            var id   = doc.SaveToProjectAsImage(options);
            var view = doc.GetElement(id) as Autodesk.Revit.DB.ImageView;

            InternalSetImageView(view);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);
        }
Example #4
0
        /// <summary>
        /// Place a Group in the model
        /// </summary>
        /// <param name="point">The group instance location</param>
        /// <param name="groupType">The type of the group</param>
        private void InitGroup(DB.XYZ point, DB.GroupType groupType)
        {
            DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            // This creates a new wall and deletes the old one
            TransactionManager.Instance.EnsureInTransaction(document);

            //Phase 1 - Check to see if the object exists and should be rebound
            var groupElem = ElementBinder.GetElementFromTrace <DB.Group>(document);

            if (groupElem == null)
            {
                groupElem = document.Create.PlaceGroup(point, groupType);
            }

            InternalSetGroup(groupElem);

            TransactionManager.Instance.TransactionTaskDone();

            if (groupElem != null)
            {
                ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement);
            }
            else
            {
                ElementBinder.SetElementForTrace(this.InternalElement);
            }
        }
Example #5
0
        private void InitRevision()
        {
            var doc = DocumentManager.Instance.CurrentDBDocument;

            //Phase 1 - Check to see if the object exists and should be rebound
            var oldEle = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Revision>(doc);

            // Rebind to Element
            if (oldEle != null)
            {
                InternalSetRevision(oldEle);
                return;
            }

            //Phase 2 - There was no existing Element, create new one
            TransactionManager.Instance.EnsureInTransaction(doc);

            var r = Autodesk.Revit.DB.Revision.Create(doc);

            InternalSetRevision(r);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);
        }
Example #6
0
        /// <summary>
        /// Internal constructor for the AdaptiveComponent wrapper
        /// </summary>
        /// <param name="pts">Points to use as reference</param>
        /// <param name="f">Face to use as reference</param>
        /// <param name="fs">FamilySymbol to place</param>
        private AdaptiveComponent(double[][] pts, ElementFaceReference f, FamilySymbol fs)
        {
            // if the family instance is present in trace...
            var oldFam =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(Document);

            // just mutate it...
            if (oldFam != null)
            {
                InternalSetFamilyInstance(oldFam);
                if (fs.InternalFamilySymbol.Id != oldFam.Symbol.Id)
                {
                    InternalSetFamilySymbol(fs);
                }
                InternalSetUvsAndFace(pts.ToUvs(), f.InternalReference);
                return;
            }

            // otherwise create a new family instance...
            TransactionManager.Instance.EnsureInTransaction(Document);

            var fam = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(Element.Document, fs.InternalFamilySymbol);

            if (fam == null)
            {
                throw new Exception("An adaptive component could not be found or created.");
            }

            InternalSetFamilyInstance(fam);
            InternalSetUvsAndFace(pts.ToUvs(), f.InternalReference);

            TransactionManager.Instance.TransactionTaskDone();
        }
Example #7
0
        private void InitFamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.XYZ point, Autodesk.Revit.DB.View view)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldFam = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(DocumentManager.Instance.CurrentDBDocument);

            //There was a point, rebind to that, and adjust its position
            if (oldFam != null)
            {
                InternalSetFamilyInstance(oldFam);
                InternalSetFamilySymbol(fs);
                return;
            }

            //Phase 2- There was no existing point, create one
            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

            //If the symbol is not active, then activate it
            if (!fs.IsActive)
            {
                fs.Activate();
            }

            var fi = DocumentManager.Instance.CurrentDBDocument.Create.NewFamilyInstance(point, fs, view);

            InternalSetFamilyInstance(fi);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);
        }
Example #8
0
        private Topography(IList <XYZ> points)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldSurf =
                ElementBinder.GetElementFromTrace <TopographySurface>(Document);

            var document = DocumentManager.Instance.CurrentDBDocument;

            //Phase 2- There was no existing point, create one
            TransactionManager.Instance.EnsureInTransaction(Document);

            var topo = TopographySurface.Create(document, points);

            InternalSetTopographySurface(topo);

            TransactionManager.Instance.TransactionTaskDone();

            if (oldSurf != null)
            {
                ElementBinder.CleanupAndSetElementForTrace(Document, this.InternalElement);
            }
            else
            {
                ElementBinder.SetElementForTrace(this.InternalElement);
            }
        }
Example #9
0
        /// <summary>
        /// Internal constructor for the ModelText
        /// </summary>
        /// <param name="text"></param>
        /// <param name="sketchPlane"></param>
        /// <param name="xCoordinateInPlane"></param>
        /// <param name="yCoordinateInPlane"></param>
        /// <param name="textDepth"></param>
        /// <param name="modelTextType"></param>
        private ModelText(string text, Autodesk.Revit.DB.SketchPlane sketchPlane, double xCoordinateInPlane, double yCoordinateInPlane, double textDepth, Autodesk.Revit.DB.ModelTextType modelTextType)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldEle =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ModelText>(Document);


            // Note: not sure if there's a way to mutate the sketchPlane for a ModelText, so we need
            // to insure the Element hasn't changed position, otherwise, we destroy and rebuild the Element
            if (oldEle != null && PositionUnchanged(oldEle, sketchPlane, xCoordinateInPlane, yCoordinateInPlane))
            {
                // There was an element and it's position hasn't changed
                InternalSetModelText(oldEle);
                InternalSetText(text);
                InternalSetDepth(textDepth);
                InternalSetModelTextType(modelTextType);
                return;
            }

            TransactionManager.Instance.EnsureInTransaction(Document);

            // We have to clean up the old ModelText b/c we can't mutate it's position
            if (oldEle != null)
            {
                DocumentManager.Instance.DeleteElement(new ElementUUID(oldEle.UniqueId));
            }

            var mt = CreateModelText(text, sketchPlane, xCoordinateInPlane, yCoordinateInPlane, textDepth, modelTextType);

            InternalSetModelText(mt);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Example #10
0
        /// <summary>
        /// Initialize a ReferencePoint element
        /// </summary>
        /// <param name="curveReference"></param>
        /// <param name="parameter"></param>
        /// <param name="measurementType"></param>
        /// <param name="measureFrom"></param>
        private void InitReferencePoint(Reference curveReference, double parameter, PointOnCurveMeasurementType measurementType,
                                        PointOnCurveMeasureFrom measureFrom)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldRefPt =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ReferencePoint>(Document);

            //There was a point, rebind to that, and adjust its position
            if (oldRefPt != null)
            {
                InternalSetReferencePoint(oldRefPt);
                InternalSetPointOnCurve(curveReference, parameter, measurementType, measureFrom);
                return;
            }

            //Phase 2- There was no existing point, create one
            TransactionManager.Instance.EnsureInTransaction(Document);

            var plc       = new PointLocationOnCurve(measurementType, parameter, measureFrom);
            var edgePoint = Document.Application.Create.NewPointOnEdge(curveReference, plc);

            InternalSetReferencePoint(Document.FamilyCreate.NewReferencePoint(edgePoint));

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);
        }
Example #11
0
        private void InitSpace(
            DB.Level level,
            DB.UV point)
        {
            DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            // This creates a new wall and deletes the old one
            TransactionManager.Instance.EnsureInTransaction(document);

            //Phase 1 - Check to see if the object exists and should be rebound
            var roomElem = ElementBinder.GetElementFromTrace <DB.Mechanical.Space>(document);

            if (roomElem == null)
            {
                roomElem = document.Create.NewSpace(level, point);
            }

            InternalSetSpace(roomElem);

            TransactionManager.Instance.TransactionTaskDone();

            if (roomElem != null)
            {
                ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement);
            }
            else
            {
                ElementBinder.SetElementForTrace(this.InternalElement);
            }
        }
Example #12
0
        /// <summary>
        /// Initialize a CurtainSystem element
        /// </summary>
        private void InitCurtainSystem(ReferenceArray faces, Autodesk.Revit.DB.CurtainSystemType curtainSystemType)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            Autodesk.Revit.DB.CurtainSystem curtainSystem = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.CurtainSystem>(Document);

            ICollection <ElementId> ids = Document.Create.NewCurtainSystem2(faces, curtainSystemType);

            if (ids.Count > 1)
            {
                foreach (ElementId id in ids)
                {
                    Autodesk.Revit.DB.CurtainSystem system = (Autodesk.Revit.DB.CurtainSystem)Document.GetElement(id);
                    InitCurtainSystem(system);
                }
                return;
            }
            else
            {
                curtainSystem = (Autodesk.Revit.DB.CurtainSystem)Document.GetElement(ids.First());
            }

            InternalSetCurtainSystem(curtainSystem);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.CleanupAndSetElementForTrace(Document, InternalCurtainSystem);
        }
Example #13
0
        /// <summary>
        /// Initialize a Sheet element with a name, number and specific titleblock.
        /// </summary>
        /// <param name="sheetName">name of the sheet.</param>
        /// <param name="sheetNumber">sheet number.</param>
        /// <param name="titleBlockFamilySymbol">sheet titleblock.</param>
        private void InitSheet(string sheetName, string sheetNumber, Autodesk.Revit.DB.FamilySymbol titleBlockFamilySymbol)
        {
            //Phase 1 - Check to see if the object exists
            var oldEle =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ViewSheet>(Document);

            // Rebind to Element
            if (oldEle != null)
            {
                InternalSetViewSheet(oldEle);
                InternalSetSheetName(sheetName);
                InternalSetSheetNumber(sheetNumber);
                InternalSetTitleBlock(titleBlockFamilySymbol.Id);

                return;
            }

            //Phase 2 - There was no existing Element, create new one
            TransactionManager.Instance.EnsureInTransaction(Document);

            // create sheet with title block ID
            var sheet = Autodesk.Revit.DB.ViewSheet.Create(Document, titleBlockFamilySymbol.Id);

            InternalSetViewSheet(sheet);
            InternalSetSheetName(sheetName);
            InternalSetSheetNumber(sheetNumber);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Example #14
0
        private void InitCurveByPoints(IEnumerable <Autodesk.Revit.DB.ReferencePoint> refPoints, bool isReferenceLine)
        {
            //Add all of the elements in the sequence to a ReferencePointArray.
            var refPtArr = new ReferencePointArray();

            foreach (var refPt in refPoints)
            {
                refPtArr.Append(refPt);
            }

            //Phase 1 - Check to see if the object exists and should be rebound
            var cbp =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.CurveByPoints>(Document);

            if (cbp != null)
            {
                InternalSetCurveElement(cbp);
                InternalSetReferencePoints(refPtArr);
                InternalSetIsReferenceLine(isReferenceLine);
                return;
            }

            TransactionManager.Instance.EnsureInTransaction(Document);

            cbp = DocumentManager.Instance.CurrentDBDocument.FamilyCreate.NewCurveByPoints(refPtArr);

            cbp.IsReferenceLine = isReferenceLine;

            InternalSetCurveElement(cbp);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Example #15
0
        private void InitTag(
            Autodesk.Revit.DB.Element host,
            Autodesk.Revit.DB.TagOrientation orientation,
            Autodesk.Revit.DB.TagMode mode,
            bool addLeader,
            Autodesk.Revit.DB.XYZ point)
        {
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(document);

            var tagElem = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.IndependentTag>(document);

            if (tagElem == null)
            {
                tagElem = document.Create.NewTag(document.ActiveView, host, addLeader, mode, orientation, point);
            }

            InternalSetTag(tagElem);

            TransactionManager.Instance.TransactionTaskDone();


            if (tagElem != null)
            {
                ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement);
            }
            else
            {
                ElementBinder.SetElementForTrace(this.InternalElement);
            }
        }
        private void InitRebarHookType(double angle, double multiplier)
        {
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(document);

            var hookTypeElem = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Structure.RebarHookType>(document);

            if (hookTypeElem == null)
            {
                hookTypeElem = Autodesk.Revit.DB.Structure.RebarHookType.Create(document, angle, multiplier);
            }

            TransactionManager.Instance.TransactionTaskDone();


            if (hookTypeElem != null)
            {
                ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement);
            }
            else
            {
                ElementBinder.SetElementForTrace(this.InternalElement);
            }
        }
Example #17
0
        /// <summary>
        /// Initialize a SketchPlane element
        /// </summary>
        /// <param name="p"></param>
        private void InitSketchPlane(Autodesk.Revit.DB.Plane p)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldEle =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.SketchPlane>(Document);

            //There was an element, bind & mutate
            if (oldEle != null)
            {
                InternalSetSketchPlane(oldEle);
                if (InternalSetPlane(p))
                {
                    return;
                }

                // if setting the plane fails, we delete the old Element
                // in order to create a new one
                DocumentManager.Instance.DeleteElement(new ElementUUID(oldEle.UniqueId));
            }

            //Phase 2- There was no existing element, create new
            TransactionManager.Instance.EnsureInTransaction(Document);

            Autodesk.Revit.DB.SketchPlane sp;

            sp = Autodesk.Revit.DB.SketchPlane.Create(Document, p);

            InternalSetSketchPlane(sp);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }
        /// <summary>
        /// Initialize an AxonometricView element
        /// </summary>
        private void InitAxonometricView(XYZ eye, XYZ target, string name = DEFAULT_VIEW_NAME, Autodesk.Revit.DB.Element element = null, bool isolate = false)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldEle =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.View3D>(Document);

            //Phase 2 - There was no existing Element, create new one
            TransactionManager.Instance.EnsureInTransaction(Document);

            // Rebind to Element
            if (oldEle != null)
            {
                InternalSetView3D(oldEle);
                InternalSetOrientation(BuildOrientation3D(eye, target));
                InternalSetIsolation(element, isolate);
                InternalSetName(name);
                return;
            }

            var vd = Create3DView(BuildOrientation3D(eye, target), name, false);

            InternalSetView3D(vd);
            InternalSetIsolation(element, isolate);
            InternalSetName(name);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Example #19
0
        private void InitFamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.Line line, Autodesk.Revit.DB.Level level)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldFam = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(DocumentManager.Instance.CurrentDBDocument);

            //There was a point, rebind to that, and adjust its position
            if (oldFam != null)
            {
                InternalSetFamilyInstance(oldFam);
                InternalSetLevel(level);
                InternalSetFamilySymbol(fs);
                InternalSetPosition(line);
                return;
            }

            //Phase 2- There was no existing point, create one
            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

            //If the symbol is not active, then activate it
            if (!fs.IsActive)
            {
                fs.Activate();
            }

            var fi = DocumentManager.Instance.CurrentDBDocument.Create.NewFamilyInstance(line, fs, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

            ((Autodesk.Revit.DB.LocationCurve)fi.Location).Curve = line;

            InternalSetFamilyInstance(fi);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);
        }
Example #20
0
        /// <summary>
        /// Initialize a CableTray element.
        /// </summary>
        private void InitObject(Autodesk.Revit.DB.Electrical.CableTrayType cableTrayType, XYZ start, XYZ end)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldFam =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.MEPCurve>(DocumentManager.Instance.CurrentDBDocument);

            //There was a point, rebind to that, and adjust its position
            if (oldFam != null)
            {
                InternalSetMEPCurve(oldFam);
                InternalSetMEPCurveType(cableTrayType);
                InternalSetPosition(start, end);
                return;
            }

            //Phase 2- There was no existing point, create one
            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

            Autodesk.Revit.DB.MEPCurve fi;

            if (DocumentManager.Instance.CurrentDBDocument.IsFamilyDocument)
            {
                fi = null;
            }
            else
            {
                fi = Autodesk.Revit.DB.Electrical.CableTray.Create(DocumentManager.Instance.CurrentDBDocument, cableTrayType.Id, start, end, ElementId.InvalidElementId) as Autodesk.Revit.DB.MEPCurve;
            }

            InternalSetMEPCurve(fi);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);
        }
Example #21
0
        /// <summary>
        /// Private constructor that constructs a FreeForm from a user-provided
        /// solid
        /// </summary>
        /// <param name="solid"></param>
        private FreeForm(Autodesk.Revit.DB.Solid mySolid)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var ele =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FreeFormElement>(Document);

            // mutate with new solid, if possible
            if (ele != null)
            {
                InternalSetFreeFormElement(ele);
                if (InternalSetSolid(mySolid))
                {
                    return;
                }
            }

            // recreate freeform
            TransactionManager.Instance.EnsureInTransaction(Document);

            var freeForm = FreeFormElement.Create(Document, mySolid);

            InternalSetFreeFormElement(freeForm);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Example #22
0
        // PB: This implementation borrows the somewhat risky notions from the original Dynamo
        // implementation.  In short, it has the ability to infer a sketch plane,
        // which might also mean deleting the original one.

        /// <summary>
        /// Initialize a ModelCurve element
        /// </summary>
        /// <param name="crv"></param>
        /// <param name="makeReferenceCurve"></param>
        private void InitModelCurve(Autodesk.Revit.DB.Curve crv, bool makeReferenceCurve)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var mc =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ModelCurve>(Document);

            //There was a modelcurve, try and set sketch plane
            // if you can't, rebuild
            if (mc != null)
            {
                InternalSetCurveElement(mc);
                InternalSetSketchPlaneFromCurve(crv);
                return;
            }

            ElementId oldId       = (mc != null) ? mc.Id : ElementId.InvalidElementId;
            string    oldUniqueId = (mc != null) ? mc.UniqueId : string.Empty;

            TransactionManager.Instance.EnsureInTransaction(Document);

            // (sic erat scriptum)
            var sp    = GetSketchPlaneFromCurve(crv);
            var plane = sp.GetPlane();

            if (CurveUtils.GetPlaneFromCurve(crv, true) == null)
            {
                var flattenCurve = Flatten3dCurveOnPlane(crv, plane);
                mc = Document.IsFamilyDocument
                    ? Document.FamilyCreate.NewModelCurve(flattenCurve, sp)
                    : Document.Create.NewModelCurve(flattenCurve, sp);

                setCurveMethod(mc, crv);
            }
            else
            {
                mc = Document.IsFamilyDocument
                    ? Document.FamilyCreate.NewModelCurve(crv, sp)
                    : Document.Create.NewModelCurve(crv, sp);
            }

            if (mc.SketchPlane.Id != sp.Id)
            {
                //THIS BIZARRE as Revit could use different existing SP, so if Revit had found better plane  this sketch plane has no use
                DocumentManager.Instance.DeleteElement(new ElementUUID(sp.UniqueId));
            }

            InternalSetCurveElement(mc);
            if (oldId != mc.Id && oldId != ElementId.InvalidElementId)
            {
                DocumentManager.Instance.DeleteElement(new ElementUUID(oldUniqueId));
            }
            if (makeReferenceCurve)
            {
                mc.ChangeToReferenceLine();
            }

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Example #23
0
        /// <summary>
        /// Initialize a ReferencePoint element
        /// </summary>
        /// <param name="faceReference"></param>
        /// <param name="uv"></param>
        private void InitReferencePoint(Reference faceReference, UV uv)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldRefPt =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ReferencePoint>(Document);

            //There was a point, rebind to that, and adjust its position
            if (oldRefPt != null)
            {
                InternalSetReferencePoint(oldRefPt);
                InternalSetPointOnFace(faceReference, uv);
                return;
            }

            //Phase 2- There was no existing point, create one
            TransactionManager.Instance.EnsureInTransaction(Document);

            var edgePoint = Document.Application.Create.NewPointOnFace(faceReference, uv);

            InternalSetReferencePoint(Document.FamilyCreate.NewReferencePoint(edgePoint));

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);

            // otherwise the point value is invalid for downstream requests
            DocumentManager.Regenerate();
        }
Example #24
0
        /// <summary>
        /// Initializes the takeoff object.
        /// </summary>
        /// <param name="c1">The conenctor.</param>
        /// <param name="curve">The curve.</param>
        private void InitTakeoffObject(Autodesk.Revit.DB.Connector c1, Autodesk.Revit.DB.MEPCurve curve)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldFam =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(DocumentManager.Instance.CurrentDBDocument);

            //There was a point, rebind to that, and adjust its position
            if (oldFam != null)
            {
                InternalSetFamilyInstance(oldFam);
                return;
            }

            //Phase 2- There was no existing point, create one
            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

            Autodesk.Revit.DB.FamilyInstance fi;

            if (DocumentManager.Instance.CurrentDBDocument.IsFamilyDocument)
            {
                fi = null;
            }
            else
            {
                fi = DocumentManager.Instance.CurrentDBDocument.Create.NewTakeoffFitting(c1, curve);
            }

            InternalSetFamilyInstance(fi);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);
        }
Example #25
0
        /// <summary>
        /// Init a new detail curve from curve
        /// </summary>
        /// <param name="view"></param>
        /// <param name="curve"></param>
        private void Init(Autodesk.Revit.DB.View view, Autodesk.Revit.DB.Curve curve)
        {
            // Open Transaction and get document
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
            TransactionManager.Instance.EnsureInTransaction(document);

            // Get exsiting element
            var element = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.DetailCurve>(document);

            if (element == null)
            {
                if (document.IsFamilyDocument)
                {
                    element = document.FamilyCreate.NewDetailCurve(view, curve);
                }
                else
                {
                    element = document.Create.NewDetailCurve(view, curve);
                }
            }
            else
            {
                element.SetGeometryCurve(curve, true);
            }

            InternalSetCurveElement(element);

            // Set transaction task done & element for trace
            TransactionManager.Instance.TransactionTaskDone();
            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Example #26
0
        /// <summary>
        /// Initialize a DividedSurface element
        /// </summary>
        /// <param name="elementFace"></param>
        /// <param name="uDivs"></param>
        /// <param name="vDivs"></param>
        /// <param name="rotation"></param>
        private void InitDividedSurface(ElementFaceReference elementFace, int uDivs, int vDivs, double rotation)
        {
            // if the family instance is present in trace...
            var oldEle =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.DividedSurface>(Document);

            // just mutate it...
            if (oldEle != null)
            {
                InternalSetDividedSurface(oldEle);
                InternalSetDivisions(uDivs, vDivs);
                InternalSetRotation(rotation);
                return;
            }

            // otherwise create a new family instance...
            TransactionManager.Instance.EnsureInTransaction(Document);

            //TODO: 2014->2015
            //var divSurf = Document.FamilyCreate.NewDividedSurface(elementFace.InternalReference);
            var divSurf = Autodesk.Revit.DB.DividedSurface.Create(Document, elementFace.InternalReference);

            InternalSetDividedSurface(divSurf);
            InternalSetDivisions(uDivs, vDivs);
            InternalSetRotation(rotation);

            TransactionManager.Instance.TransactionTaskDone();

            // remember this new value
            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Example #27
0
        private void InitSheet(string nameOfSheet, string numberOfSheet)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldEle = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ViewSheet>(DocumentManager.Instance.CurrentDBDocument);

            // Rebind to Element
            if (oldEle != null)
            {
                InternalSetViewSheet(oldEle);
                InternalSetSheetName(nameOfSheet);
                InternalSetSheetNumber(numberOfSheet);
                return;
            }

            //Phase 2 - There was no existing Element, create new one
            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

            // create sheet without title block
            var sheet = Autodesk.Revit.DB.ViewSheet.CreatePlaceholder(DocumentManager.Instance.CurrentDBDocument);

            InternalSetViewSheet(sheet);
            InternalSetSheetName(nameOfSheet);
            InternalSetSheetNumber(numberOfSheet);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);
        }
Example #28
0
        private void InitFamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, Autodesk.Revit.DB.Reference reference, Autodesk.Revit.DB.XYZ location,
                                        Autodesk.Revit.DB.XYZ referenceDirection)
        {
            //Phase 1 - Check to see if the object exists and should be rebound
            var oldFam =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(Document);

            //There was an existing family instance, rebind to that, and adjust its position
            if (oldFam != null && oldFam.HostFace.ElementId == reference.ElementId)
            {
                InternalSetFamilyInstance(oldFam);
                InternalSetFamilySymbol(fs);
                InternalSetPosition(location);
                return;
            }

            //Phase 2- There was no existing point, create one
            TransactionManager.Instance.EnsureInTransaction(Document);

            //If the symbol is not active, then activate it
            if (!fs.IsActive)
            {
                fs.Activate();
            }

            var fi = Document.IsFamilyDocument
                ? Document.FamilyCreate.NewFamilyInstance(reference, location, referenceDirection, fs)
                : Document.Create.NewFamilyInstance(reference, location, referenceDirection, fs);

            InternalSetFamilyInstance(fi);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);
        }
Example #29
0
        private void InitView3D(string name)
        {
            var doc     = DocumentManager.Instance.CurrentDBDocument;
            var oldView = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.View3D>(doc);

            if (oldView != null)
            {
                InternalSetView3D(oldView);
                InternalSetName(name);
                return;
            }

            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

            var vft = new Autodesk.Revit.DB.FilteredElementCollector(doc)
                      .OfClass(typeof(Autodesk.Revit.DB.ViewFamilyType))
                      .Cast <Autodesk.Revit.DB.ViewFamilyType>()
                      .FirstOrDefault(x => x.ViewFamily == Autodesk.Revit.DB.ViewFamily.ThreeDimensional);
            var view = Autodesk.Revit.DB.View3D.CreateIsometric(doc, vft?.Id);

            view.Name = name;

            InternalSetView3D(view);
            InternalSetName(name);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.SetElementForTrace(InternalElement);
        }
        private void InitRebarFreeForm(IList <IList <Curve> > curves,
                                       Autodesk.Revit.DB.Structure.RebarBarType barType,
                                       Autodesk.Revit.DB.Element host)
        {
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(document);

            var rebarElem = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Structure.Rebar>(document);



            bool changed = false;



            // Check for existing Geometry
            // TBI



            if (rebarElem == null || changed)
            {
                // Delete exsiting Rebar Element
                if (rebarElem != null && rebarElem.Id != ElementId.InvalidElementId)
                {
                    document.Delete(rebarElem.Id);
                }

                Autodesk.Revit.DB.Structure.RebarFreeFormValidationResult res = new Autodesk.Revit.DB.Structure.RebarFreeFormValidationResult();
                rebarElem = Autodesk.Revit.DB.Structure.Rebar.CreateFreeForm(document, barType, host, curves, out res);
                if (res != Autodesk.Revit.DB.Structure.RebarFreeFormValidationResult.Success)
                {
                    TransactionManager.Instance.ForceCloseTransaction();
                    throw new Exception(res.ToString());
                }
            }
            else
            {
                rebarElem.SetHostId(document, host.Id);
                rebarElem.ChangeTypeId(barType.Id);
            }


            InternalSetRebar(rebarElem);

            TransactionManager.Instance.TransactionTaskDone();


            if (rebarElem != null)
            {
                ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement);
            }
            else
            {
                ElementBinder.SetElementForTrace(this.InternalElement);
            }
        }