Esempio n. 1
0
        /// <summary>
        /// Changes the workset of an element.
        /// </summary>
        /// <param name="element">Dynamo Elements.</param>
        /// <param name="workset">A revit workset</param>
        /// <returns name="element">The element that was changed.  Returns null if the change was unsuccessfull.</returns>
        public static dynamoElement SetElementWorkset(dynamoElement element, Workset workset)
        {
            //Get Revit Document object
            revitDoc doc = DocumentManager.Instance.CurrentDBDocument;

            Autodesk.Revit.DB.Element unwrapped = element.InternalElement;

            WorksetId wId = unwrapped.WorksetId;

            Autodesk.Revit.DB.Parameter wsParam = unwrapped.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM);
            if (wsParam == null)
            {
                return(null);
            }
            if (doc.IsModifiable)
            {
                wsParam.Set(workset.internalId.IntegerValue);
            }
            else
            {
                using (Autodesk.Revit.DB.Transaction tx = new Autodesk.Revit.DB.Transaction(doc))
                {
                    tx.Start("Change Element's Workset");
                    wsParam.Set(workset.internalId.IntegerValue);
                    tx.Commit();
                }
            }
            return(unwrapped.ToDSType(true));;
        }
Esempio n. 2
0
        /// <summary>
        /// Converts a Autodesk.Revit.DB.Element into its equivalent Dynamo element if possible.
        /// </summary>
        /// <param name="element">A Autodesk.Revit.DB.Element</param>
        /// <returns name="Dynamo Element">If successful, returns a dynamo element, otherwise returns null.</returns>
        public static DynaElem WrapRevitElement(RevitElem element)
        {
            DynaElem dElem = null;

            try
            {
                dElem = element.ToDSType(true);
            }
            catch { }

            return(dElem);
        }
Esempio n. 3
0
        public static Revit.Elements.Element SetName(Revit.Elements.Element element, string name)
        {
            // Unwrap elements
            Autodesk.Revit.DB.Element elem = element.InternalElement;

            Document document = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(document);
            elem.Name = name;
            TransactionManager.Instance.TransactionTaskDone();

            return(elem.ToDSType(true));
        }
Esempio n. 4
0
        public static DynElem DynamoElementByNameClass(string Name, Type Class,
                                                       [DefaultArgument("Synthetic.Revit.Document.Current()")] RevitDoc document)
        {
            RevitFECollector collector
                = new RevitFECollector(document);

            RevitDB.Element elem = collector
                                   .OfClass(Class)
                                   .FirstOrDefault(e => e.Name.Equals(Name));

            DynElem dElem = elem.ToDSType(true);

            return(dElem);
        }
Esempio n. 5
0
        public static object Create(global::Revit.Elements.Views.Sheet sheet, global::Revit.Elements.Element view, Autodesk.DesignScript.Geometry.Point location)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //obtain the element id from the sheet
            ElementId sheetId = new ElementId(sheet.Id);

            Autodesk.Revit.DB.Element result = null;
            //change the dynamo point to a revit point
            var revitPoint = location.ToRevitType(true);
            //obtain the element id from the view
            ElementId viewId = new ElementId(view.Id);



            try
            {
                //start the transaction to place views
                TransactionManager.Instance.EnsureInTransaction(doc);
                if (view.InternalElement.ToString() == "Autodesk.Revit.DB.ViewSchedule")
                {
                    result = Autodesk.Revit.DB.ScheduleSheetInstance.Create(doc, sheetId, viewId, revitPoint);
                }
                else
                {
                    result = Autodesk.Revit.DB.Viewport.Create(doc, sheetId, viewId, revitPoint);
                }

                TransactionManager.Instance.TransactionTaskDone();

                return(result.ToDSType(true));
            }
            catch (Exception e)
            {
                if (!Autodesk.Revit.DB.Viewport.CanAddViewToSheet(doc, sheetId, viewId))
                {
                    return("Error: View " + view.Id + " cannot be added to the sheet because it is already on another sheet.");
                }
                if (result == null)
                {
                    return("Error: View " + view.Id + " cannot be added to the sheet because it is empty.");
                }

                return("Error: View " + view.Id + e.Message);
            }
        }