public VisualStateProxy() { // Use propery to init value here: BeaconInstance = new ElementBinder( e => { }, e => { e.Element = null; }); }
/// <summary> /// Initialize an AdaptiveComponent element /// </summary> /// <param name="uvParams">Parameters to use as reference</param> /// <param name="f">Face to use as reference</param> /// <param name="ft">familyType to place</param> private void InitAdaptiveComponent(double[][] uvParams, ElementFaceReference f, FamilyType ft) { // 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 (ft.InternalFamilySymbol.Id != oldFam.Symbol.Id) { InternalSetFamilySymbol(ft); } InternalSetUvsAndFace(uvParams.ToUvs(), f.InternalReference); return; } // otherwise create a new family instance... TransactionManager.Instance.EnsureInTransaction(Document); using (Autodesk.Revit.DB.SubTransaction st = new SubTransaction(Document)) { try { st.Start(); var fam = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(Element.Document, ft.InternalFamilySymbol); InternalSetFamilyInstance(fam); InternalSetUvsAndFace(uvParams.ToUvs(), f.InternalReference); st.Commit(); } catch (Exception ex) { st.RollBack(); throw new ArgumentException(Revit.Properties.Resources.Adaptive_Component_Creation_Failed + ex.Message); } } TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(InternalElement); }
/// <summary> /// Sets the internalDirectShape's shape to point to some geometry, /// this method also generates tessellated geometry from the protogeometry object /// and sets the material of the generated Revit faces /// </summary> private void InternalSetShape(DesignScriptEntity shapeReference, ElementId materialId, string currentSyncId) { //if the elementID for the current directShape revitElement exists on the input Geometry AND //the value stored at that key is equal to the materialId we're trying to set AND //the previousState's syncId (in the tags dictionary) equals the current syncId (from trace) //then we do not need to regenerate //first lookup the state on the input geometry var previousState = shapeReference.Tags.LookupTag(this.InternalElementId.ToString()) as DirectShapeState; //then compare values if (previousState != null && previousState.materialId == materialId.IntegerValue && previousState.syncId == currentSyncId) { return; } TransactionManager.Instance.EnsureInTransaction(Document); var tessellatedShape = GenerateTessellatedGeo(shapeReference, materialId); this.InternalDirectShape.SetShape(tessellatedShape); //update the value in trace, since we had to modify the geometry we need a new syncId var updatedTraceData = new DirectShapeState(this, Guid.NewGuid().ToString(), materialId); ElementBinder.SetRawDataForTrace(updatedTraceData); //place new values in the tags dict if (shapeReference.Tags.LookupTag(this.InternalElementId.ToString()) == null) { shapeReference.Tags.AddTag(this.InternalElementId.ToString(), updatedTraceData); } else { var storedState = shapeReference.Tags.LookupTag(this.InternalElementId.ToString()) as DirectShapeState; storedState.syncId = updatedTraceData.syncId; storedState.materialId = updatedTraceData.materialId; storedState.IntID = updatedTraceData.IntID; storedState.StringID = updatedTraceData.StringID; } TransactionManager.Instance.TransactionTaskDone(); }
private void InitTag( Autodesk.Revit.DB.View view, 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 || view.Id != tagElem.OwnerViewId || (tagElem.TaggedElementId.HostElementId != host.Id && tagElem.TaggedElementId.LinkedElementId != host.Id)) { tagElem = document.Create.NewTag(view, host, addLeader, mode, orientation, point); } else { tagElem.TagOrientation = orientation; tagElem.HasLeader = addLeader; tagElem.TagHeadPosition = point; } InternalSetTag(tagElem); TransactionManager.Instance.TransactionTaskDone(); if (tagElem != null) { ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement); } else { ElementBinder.SetElementForTrace(this.InternalElement); } }
private void InitRebarContainer(List <Revit.Elements.Rebar> rebars) { if (rebars.Count > 0) { Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(document); var rebarElem = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Structure.RebarContainer>(document); if (rebarElem == null) { ElementId stdC = Autodesk.Revit.DB.Structure.RebarContainerType.CreateDefaultRebarContainerType(DocumentManager.Instance.CurrentDBDocument); Autodesk.Revit.DB.Element host = DocumentManager.Instance.CurrentDBDocument.GetElement(rebars[0].InternalRebar.GetHostId()); rebarElem = Autodesk.Revit.DB.Structure.RebarContainer.Create(DocumentManager.Instance.CurrentDBDocument, host, stdC); } else { rebarElem.ClearItems(); } foreach (Revit.Elements.Rebar rebar in rebars) { rebarElem.AppendItemFromRebar(rebar.InternalRebar); } InternalSetRebarContainer(rebarElem); TransactionManager.Instance.TransactionTaskDone(); if (rebarElem != null) { ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement); } else { ElementBinder.SetElementForTrace(this.InternalElement); } } }
private void InitFamilyInstance(FamilySymbol fs, Reference reference, XYZ location, 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(); } Autodesk.Revit.DB.FamilyInstance fi; if (Document.IsFamilyDocument) { fi = Document.FamilyCreate.NewFamilyInstance(reference, location, referenceDirection, fs); } else { fi = Document.Create.NewFamilyInstance(reference, location, referenceDirection, fs); } InternalSetFamilyInstance(fi); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(InternalElement); }
/// <summary> /// Initialize a roof element /// </summary> private void InitRoof(CurveArray curves, Autodesk.Revit.DB.ReferencePlane reference, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.RoofType roofType, double extrusionStart, double extrusionEnd) { TransactionManager.Instance.EnsureInTransaction(Document); Autodesk.Revit.DB.RoofBase roof = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.RoofBase>(Document); if (roof == null) { roof = Document.Create.NewExtrusionRoof(curves, reference, level, roofType, extrusionStart, extrusionEnd); } else { roof = Document.Create.NewExtrusionRoof(curves, reference, level, roofType, extrusionStart, extrusionEnd); } InternalSetRoof(roof); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.CleanupAndSetElementForTrace(Document, InternalRoof); }
/// <summary> /// Initialize a ViewSchedule Element. /// </summary> /// <param name="category"></param> /// <param name="name"></param> /// <param name="type"></param> private void InitScheduleView(Category category, string name, ScheduleType type) { var doc = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(doc); // Get existing view if possible var vs = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ViewSchedule>(doc); if (vs == null) { vs = CreateViewSchedule(category, name, type); } InternalSetScheduleView(vs); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.CleanupAndSetElementForTrace(doc, this.InternalElement); }
/// <summary> /// Initialize a floor element /// </summary> private void InitFloor(CurveArray curveArray, Autodesk.Revit.DB.FloorType floorType, Autodesk.Revit.DB.Level level) { TransactionManager.Instance.EnsureInTransaction(Document); Autodesk.Revit.DB.Floor floor = null; if (floorType.IsFoundationSlab) { floor = Document.Create.NewFoundationSlab(curveArray, floorType, level, false, XYZ.BasisZ); } else { // we assume the floor is not structural here, this may be a bad assumption floor = Document.Create.NewFloor(curveArray, floorType, level, false); } InternalSetFloor(floor); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.CleanupAndSetElementForTrace(Document, InternalFloor); }
/// <summary> /// Initialize a GlobalParameter element /// </summary> /// <param name="line"></param> private void InitGlobalParameter(string name, Autodesk.Revit.DB.ParameterType type) { var existingId = Autodesk.Revit.DB.GlobalParametersManager.FindByName(Document, name); if (existingId != null && existingId != Autodesk.Revit.DB.ElementId.InvalidElementId) { // GP already exists var existingParameter = Document.GetElement(existingId) as Autodesk.Revit.DB.GlobalParameter; InternalSetGlobalParameter(existingParameter); } else { // Create a new GP TransactionManager.Instance.EnsureInTransaction(Document); Autodesk.Revit.DB.GlobalParameter newParameter = Autodesk.Revit.DB.GlobalParameter.Create(Document, name, type); InternalSetGlobalParameter(newParameter); TransactionManager.Instance.TransactionTaskDone(); } ElementBinder.CleanupAndSetElementForTrace(Document, InternalGlobalParameter); }
/// <summary> /// Init Filled Region by Curves /// </summary> /// <param name="view"></param> /// <param name="typeId"></param> /// <param name="boundary"></param> private void Init(View view, ElementId typeId, IEnumerable <CurveLoop> boundary) { // Get document and start transaction Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(document); // Get existing element var region = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FilledRegion>(document); if (null != region) { DocumentManager.Instance.DeleteElement(new ElementUUID(region.UniqueId)); } region = Autodesk.Revit.DB.FilledRegion.Create(document, typeId, view.Id, boundary.ToList()); InternalSetElement(region); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(this.InternalElement); }
/// <summary> /// Make a SketchPlane from a plane /// </summary> /// <param name="p"></param> private SketchPlane(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(oldEle.Id); } //Phase 2- There was no existing element, create new TransactionManager.Instance.EnsureInTransaction(Document); Autodesk.Revit.DB.SketchPlane sp; if (Document.IsFamilyDocument) { sp = Document.FamilyCreate.NewSketchPlane(p); } else { sp = Document.Create.NewSketchPlane(p); } InternalSetSketchPlane(sp); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(this.InternalElement); }
/// <summary> /// Initialize a GroupType element from a set of objects ids and a name /// </summary> /// <param name="ids"></param> /// <param name="name"></param> private void InitGroupType(ICollection <DB.ElementId> ids, string name) { DB.Document document = DocumentManager.Instance.CurrentDBDocument; //Find all groupType name in the document DB.FilteredElementCollector collector = new DB.FilteredElementCollector(document); List <string> groupTypeNames = collector.OfClass(typeof(DB.GroupType)).ToElements().Select(element => element.Name).ToList(); // 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; if (!groupTypeNames.Contains(name)) { GroupTypeElem.Name = name; } else { GetNextFilename(name + " {0}", groupTypeNames); } } InternalSetGroupType(GroupTypeElem); TransactionManager.Instance.TransactionTaskDone(); if (GroupTypeElem != null) { ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement); } else { ElementBinder.SetElementForTrace(this.InternalElement); } }
/// <summary> /// Create new RevisionCloud from Curves /// </summary> /// <param name="view"></param> /// <param name="curves"></param> /// <param name="id"></param> private void Init(Autodesk.Revit.DB.View view, IEnumerable <Autodesk.Revit.DB.Curve> curves, Autodesk.Revit.DB.ElementId id) { // get document and open transaction Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(document); // get existing element if possible var element = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.RevisionCloud>(document); if (null != element) { DocumentManager.Instance.DeleteElement(new ElementUUID(element.UniqueId)); } element = Autodesk.Revit.DB.RevisionCloud.Create(document, view, id, curves.ToList()); InternalSetElement(element); // commit transaction and set element for trace TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(this.InternalElement); }
/// <summary> /// Initialize a DraftingView element /// </summary> private void InitDraftingView(string name) { TransactionManager.Instance.EnsureInTransaction(Document); FilteredElementCollector collector = new FilteredElementCollector(Document); var viewFamilyType = collector.OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>(). First(vft => vft.ViewFamily == ViewFamily.Drafting); var vd = ViewDrafting.Create(Document, viewFamilyType.Id); //rename the view if (!vd.Name.Equals(name)) { vd.Name = View3D.CreateUniqueViewName(name); } InternalSetDraftingView(vd); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.CleanupAndSetElementForTrace(Document, this.InternalElement); }
/// <summary> /// Internal constructor for a FamilyInstance /// </summary> internal FamilyInstance(Autodesk.Revit.DB.FamilySymbol fs, XYZ pos, 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>(Document); //There was a point, rebind to that, and adjust its position if (oldFam != null) { InternalSetFamilyInstance(oldFam); InternalSetLevel(level); InternalSetFamilySymbol(fs); InternalSetPosition(pos); return; } //Phase 2- There was no existing point, create one TransactionManager.Instance.EnsureInTransaction(Document); Autodesk.Revit.DB.FamilyInstance fi; if (Document.IsFamilyDocument) { fi = Document.FamilyCreate.NewFamilyInstance(pos, fs, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } else { fi = Document.Create.NewFamilyInstance( pos, fs, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } InternalSetFamilyInstance(fi); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(InternalElement); }
/// <summary> /// Initialize a roof element /// </summary> private void InitRoof(CurveArray curves, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.RoofType roofType) { TransactionManager.Instance.EnsureInTransaction(Document); Autodesk.Revit.DB.RoofBase roof = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.RoofBase>(Document); if (roof == null) { ModelCurveArray footprint = new ModelCurveArray(); roof = Document.Create.NewFootPrintRoof(curves, level, roofType, out footprint); } else { ModelCurveArray footprint = new ModelCurveArray(); roof = Document.Create.NewFootPrintRoof(curves, level, roofType, out footprint); } InternalSetRoof(roof); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.CleanupAndSetElementForTrace(Document, InternalRoof); }
// Used when the ValueProvider contains the collection to be bound as a single element, e.g. the raw value // is [ "1", "2" ] and needs to be converted to an int[]. // Internal for testing. internal async Task <CollectionResult> BindSimpleCollection( ModelBindingContext bindingContext, ValueProviderResult values) { var boundCollection = new List <TElement>(); var elementMetadata = bindingContext.ModelMetadata.ElementMetadata; foreach (var value in values) { bindingContext.ValueProvider = new CompositeValueProvider { // our temporary provider goes at the front of the list new ElementalValueProvider(bindingContext.ModelName, value, values.Culture), bindingContext.ValueProvider }; // Enter new scope to change ModelMetadata and isolate element binding operations. using (bindingContext.EnterNestedScope( elementMetadata, fieldName: bindingContext.FieldName, modelName: bindingContext.ModelName, model: null)) { await ElementBinder.BindModelAsync(bindingContext); if (bindingContext.Result.IsModelSet) { var boundValue = bindingContext.Result.Model; boundCollection.Add(CastOrDefault <TElement>(boundValue)); } } } return(new CollectionResult { Model = boundCollection }); }
public void RawTraceInteractionTestWithMultipleIDs() { var elementIDs = new MultipleSerializableId { IntIDs = { 42, 20 }, StringIDs = { "{BE507CAC-7F23-43D6-A2B4-13F6AF09046F}", "{A79294BF-6D27-4B86-BEE9-D6921C11D495}" } }; //Raw write ElementBinder.SetRawDataForTrace(elementIDs); elementIDs = null; //Readback var readback = (MultipleSerializableId)ElementBinder.GetRawDataFromTrace(); //Verify that the data is correct Assert.IsTrue(readback.IntIDs.Count == 2); Assert.IsTrue(readback.IntIDs[0] == 42); Assert.IsTrue(readback.IntIDs[1] == 20); Assert.IsTrue(readback.StringIDs.Count == 2); Assert.IsTrue(readback.StringIDs[0].Equals("{BE507CAC-7F23-43D6-A2B4-13F6AF09046F}")); Assert.IsTrue(readback.StringIDs[1].Equals("{A79294BF-6D27-4B86-BEE9-D6921C11D495}")); }
private void InitDimension(Autodesk.Revit.DB.View view, Autodesk.Revit.DB.Line line, Autodesk.Revit.DB.ReferenceArray arr, Autodesk.Revit.DB.DimensionType type) { //Phase 1 - Check to see if the object exists and should be rebound var oldEle = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Dimension>(DocumentManager.Instance.CurrentDBDocument); // Rebind to Element if (oldEle != null) { InternalSetDimension(oldEle); return; } //Phase 2 - There was no existing Element, create new one TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); var ii = DocumentManager.Instance.CurrentDBDocument.Create.NewDimension(view, line, arr, type); InternalSetDimension(ii); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(InternalElement); }
/// <summary> /// Initialize a ReferencePoint element /// </summary> /// <param name="xyz"></param> private void InitReferencePoint(XYZ xyz) { //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); InternalSetPosition(xyz); return; } //Phase 2- There was no existing point, create one TransactionManager.Instance.EnsureInTransaction(Document); InternalSetReferencePoint(Document.FamilyCreate.NewReferencePoint(xyz)); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(InternalElement); }
/// <summary> /// Init ParameterFilterElement by rules /// </summary> /// <param name="name"></param> /// <param name="ids"></param> /// <param name="rules"></param> private void Init(string name, IEnumerable <ElementId> ids, IEnumerable <Autodesk.Revit.DB.FilterRule> rules) { Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(document); var elem = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ParameterFilterElement>(document); if (elem == null) { elem = Autodesk.Revit.DB.ParameterFilterElement.Create(document, name, ids.ToList(), rules.ToList()); } else { elem.Name = name; elem.SetCategories(ids.ToList()); elem.SetRules(rules.ToList()); } InternalSetElement(elem); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(this.InternalElement); }
private void InitImageInstance(Autodesk.Revit.DB.View view, Autodesk.Revit.DB.ElementId typeId, Autodesk.Revit.DB.ImagePlacementOptions options) { //Phase 1 - Check to see if the object exists and should be rebound var oldEle = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ImageInstance>(DocumentManager.Instance.CurrentDBDocument); // Rebind to Element if (oldEle != null) { InternalSetImageInstance(oldEle); return; } //Phase 2 - There was no existing Element, create new one TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); var ii = Autodesk.Revit.DB.ImageInstance.Create(DocumentManager.Instance.CurrentDBDocument, view, typeId, options); InternalSetImageInstance(ii); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(InternalElement); }
/// <summary> /// Initialize an ImportInstance element /// </summary> /// <param name="satPath"></param> /// <param name="translation"></param> /// <param name="view"></param> private void InitImportInstance(string satPath, Revit.Elements.Views.View view, XYZ translation = null) { var instance = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ImportInstance>(Document); if (null != instance) { DocumentManager.Instance.DeleteElement(new ElementUUID(instance.UniqueId)); } translation = translation ?? XYZ.Zero; TransactionManager.Instance.EnsureInTransaction(Document); var options = new SATImportOptions() { Unit = ImportUnit.Foot }; var id = null != view?Document.Import(satPath, options, view.InternalView) : Document.Import(satPath, options, Document.ActiveView); var element = Document.GetElement(id); var importInstance = element as Autodesk.Revit.DB.ImportInstance; if (importInstance == null) { throw new Exception(Properties.Resources.InstanceImportFailure); } InternalSetImportInstance(importInstance); InternalUnpinAndTranslateImportInstance(translation); this.Path = satPath; TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(importInstance); }
/// <summary> /// Initialize a ModelText element /// </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 void InitModelText(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); }
private void InitViewPlan(Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.ViewFamilyType viewFamilyType) { // 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.ViewPlan>(doc); // Rebind to Element if (oldEle != null) { InternalSetViewPlan(oldEle); return; } // Phase 2 - There was no existing Element, create new one TransactionManager.Instance.EnsureInTransaction(doc); var view = Autodesk.Revit.DB.ViewPlan.Create(doc, viewFamilyType.Id, level.Id); InternalSetViewPlan(view); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(InternalElement); }
/// <summary> /// Private constructor for Level /// </summary> /// <param name="elevation"></param> /// <param name="name"></param> private Level(double elevation, string name) { //Phase 1 - Check to see if the object exists and should be rebound var oldEle = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Level>(Document); //There was an element, bind & mutate if (oldEle != null) { InternalSetLevel(oldEle); InternalSetElevation(elevation); InternalSetName(name); return; } //Phase 2- There was no existing element, create new TransactionManager.Instance.EnsureInTransaction(Document); Autodesk.Revit.DB.Level level; if (Document.IsFamilyDocument) { level = Document.FamilyCreate.NewLevel(elevation); } else { level = Document.Create.NewLevel(elevation); } InternalSetLevel(level); InternalSetName(name); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(this.InternalElement); }
/// <summary> /// Init ParameterFilterElement by rules /// </summary> /// <param name="name"></param> /// <param name="ids"></param> /// <param name="rules"></param> private void Init(string name, IEnumerable <ElementId> ids, IEnumerable <Autodesk.Revit.DB.FilterRule> rules) { Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(document); var elemFilters = new List <ElementFilter>(); foreach (var rule in rules) { var elemParamFilter = new ElementParameterFilter(rule); elemFilters.Add(elemParamFilter); } Autodesk.Revit.DB.ElementFilter eleFilter = new LogicalOrFilter(elemFilters); var elem = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.ParameterFilterElement>(document); if (elem == null) { // ParameterFilterElement..::..Create Method (Document, String, ICollection<ElementId>, IList<FilterRule>) is deprecated in Revit 2019 and will be removed in the next version of Revit. //We suggest you instead use a Create method that takes an ElementFilter as input. elem = Autodesk.Revit.DB.ParameterFilterElement.Create(document, name, ids.ToList(), eleFilter); } else { elem.Name = name; elem.SetCategories(ids.ToList()); //ParameterFilterElement..::..SetRules Method is deprecated in Revit 2019 and will be removed in the next version of Revit. //We suggest you instead use SetElementFilter instead. elem.SetElementFilter(eleFilter); } InternalSetElement(elem); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(this.InternalElement); }
/// <summary> /// Internal constructor for the AdaptiveComponent wrapper /// </summary> /// <param name="pts">Points to use as reference</param> /// <param name="fs">FamilySymbol to place</param> private AdaptiveComponent(Point[] pts, 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); } InternalSetPositions(pts.ToXyzs()); 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); InternalSetPositions(pts.ToXyzs()); TransactionManager.Instance.TransactionTaskDone(); // remember this value ElementBinder.SetElementForTrace(this.InternalElement); }
/// <summary> /// Initialize a Level element /// </summary> /// <param name="elevation"></param> /// <param name="name"></param> private void InitLevel(double elevation, string name) { //Phase 1 - Check to see if the object exists and should be rebound var oldEle = ElementBinder.GetElementAndTraceData <Autodesk.Revit.DB.Level, LevelTraceData>(Document); //There was an element, bind & mutate if (oldEle != null) { InternalSetLevel(oldEle.Item1); InternalSetElevation(elevation); InternalSetName(oldEle.Item2.InputName, name); return; } //There was no element, create a new one TransactionManager.Instance.EnsureInTransaction(Document); Autodesk.Revit.DB.Level level; if (Document.IsFamilyDocument) { level = Autodesk.Revit.DB.Level.Create(Document, elevation); } else { level = Autodesk.Revit.DB.Level.Create(Document, elevation); } InternalSetLevel(level); InternalSetName(string.Empty, name); var traceData = new LevelTraceData(this, name); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetRawDataForTrace(traceData); }
/// <summary> /// Initialize a Pipe element /// </summary> /// <param name="pipeType">Type of the pipe.</param> /// <param name="pipingSystemType">Type of the piping system.</param> /// <param name="start">The start.</param> /// <param name="end">The end.</param> /// <param name="level">The level.</param> private void InitObject(Autodesk.Revit.DB.Plumbing.PipeType pipeType, Autodesk.Revit.DB.Plumbing.PipingSystemType pipingSystemType, XYZ start, XYZ end, 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.MEPCurve>(DocumentManager.Instance.CurrentDBDocument); //There was a point, rebind to that, and adjust its position if (oldFam != null) { InternalSetMEPCurve(oldFam); InternalSetMEPCurveType(pipeType); 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.Plumbing.Pipe.Create(DocumentManager.Instance.CurrentDBDocument, pipingSystemType.Id, pipeType.Id, level.Id, start, end); } InternalSetMEPCurve(fi); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(InternalElement); }
public static void SetBeacon(DependencyObject obj, ElementBinder value) { obj.SetValue(BeaconProperty, value); }