public DocumentationSchema(Autodesk.Revit.DB.Document document) { Value = "Value"; ValueWithName = "ValueWithName"; ValueWithDescription = "ValueWithDescription"; Table = new List <string> { "Table 1", "Table 2" }; }
public static List <global::Revit.Elements.Element> RetrieveNestedComponents(global::Revit.Elements.FamilyInstance instance) { //the current document Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; //the internal family list to loop through List <Autodesk.Revit.DB.FamilyInstance> internalFamily = new List <Autodesk.Revit.DB.FamilyInstance> { (Autodesk.Revit.DB.FamilyInstance)instance.InternalElement }; //output List <global::Revit.Elements.Element> nestedList = new List <global::Revit.Elements.Element>(); //variable to step through int i = 0; //test case string s = "keepGoing"; //loop da loop while (s == "keepGoing") { if (i != internalFamily.Count) { foreach (ElementId subCom in internalFamily[i].GetSubComponentIds()) { Autodesk.Revit.DB.FamilyInstance internalFam = (Autodesk.Revit.DB.FamilyInstance)doc.GetElement(subCom); internalFamily.Add(internalFam); nestedList.Add(internalFam.ToDSType(true)); } i++; s = "keepGoing"; } else { s = "stop collaborate and listen"; } } return(nestedList); }
public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { Trace.Listeners .Add(new System.Diagnostics.EventLogTraceListener("Application")); Autodesk.Revit.UI.UIDocument uidoc = commandData.Application.ActiveUIDocument; Autodesk.Revit.DB.Document doc = uidoc.Document; try { // get hold of the print manager Autodesk.Revit.DB.PrintManager printManager = doc.PrintManager; // select the printer printManager.SelectNewPrintDriver("Adobe PDF"); printManager.PrintRange = Autodesk.Revit.DB.PrintRange.Select; if (printManager.IsVirtual != Autodesk.Revit.DB.VirtualPrinterType.AdobePDF) { return(Autodesk.Revit.UI.Result.Failed); } // access the in-session print settings Autodesk.Revit.DB.IPrintSetting printSetting = printManager.PrintSetup.InSession; printSetting.PrintParameters.PaperPlacement = Autodesk.Revit.DB.PaperPlacementType.Margins; printSetting.PrintParameters.MarginType = Autodesk.Revit.DB.MarginType.NoMargin; printSetting.PrintParameters.ZoomType = Autodesk.Revit.DB.ZoomType.Zoom; printSetting.PrintParameters.Zoom = 100; // IList <Autodesk.Revit.DB.ViewSheetSet> viewSheetSets = GetViewSheetSet(doc); System.Text.StringBuilder strBld = new System.Text.StringBuilder(); foreach (Autodesk.Revit.DB.ViewSheetSet vss in viewSheetSets) { strBld.AppendLine(string.Format("Name:{0}; Views.Count={1}", vss.Name, vss.Views.Size)); } Trace.Write(strBld.ToString()); return(Autodesk.Revit.UI.Result.Succeeded); // // apply the updated settings and print foreach (Autodesk.Revit.DB.View view in printManager.ViewSheetSetting.AvailableViews) { if (view.ViewType == Autodesk.Revit.DB.ViewType.DrawingSheet) { SetUpSizeAndPrint((ViewSheet)view, printManager, printSetting); } } return(Autodesk.Revit.UI.Result.Succeeded); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Autodesk.Revit.UI.Result.Cancelled); } catch (System.Exception ex) { Trace.Write(string.Format("Command Exception:\n{0}\n{1}", ex.Message, ex.StackTrace)); return(Autodesk.Revit.UI.Result.Failed); } }
public Schema(Entity entity, Autodesk.Revit.DB.Document document) : base(entity, document) { }
public Schema(Autodesk.Revit.DB.Document document) { }
public static Dictionary <string, object> ByRoom(string familyTemplatePath, global::Revit.Elements.Room room, string materialName, global::Revit.Elements.Category category, string subcategory = "") { //variables global::Revit.Elements.Element famInstance = null; Autodesk.Revit.DB.FamilyInstance internalFam = null; bool fileFound = false; //the current document Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; UIApplication uiapp = new UIApplication(doc.Application); //convert the room to an Autodesk.Revit.DB representation Autodesk.Revit.DB.Architecture.Room internalRoom = (Autodesk.Revit.DB.Architecture.Room)room.InternalElement; string name = internalRoom.Name; //we close all of the families because we need to swap documents foreach (Document d in uiapp.Application.Documents) { if (d.IsFamilyDocument) { d.Close(false); } } //create the new family document in the background and store it in memory Document familyDocument = uiapp.Application.NewFamilyDocument(familyTemplatePath); //instantiate a material element id and try to get the material that was specified ElementId material = null; FilteredElementCollector materialCollector = new FilteredElementCollector(familyDocument).OfClass(typeof(Autodesk.Revit.DB.Material)); foreach (var m in materialCollector) { if (m.Name.ToLower().Replace(" ", "") == materialName.ToLower().Replace(" ", "")) { material = m.Id; } } //close Dynamo's open transaction, we need to do this because we open a new Revit API transaction in the family document (This is document switching) TransactionManager.Instance.ForceCloseTransaction(); //start creating the families. Transaction trans = new Transaction(familyDocument, "Generate Families Ya'll"); trans.Start(); //set the family category Autodesk.Revit.DB.Category familyCategory = familyDocument.Settings.Categories.get_Item(category.Name); familyDocument.OwnerFamily.FamilyCategory = familyCategory; //get the subcategory for the solids Autodesk.Revit.DB.Category subCategory = null; foreach (Autodesk.Revit.DB.Category c in familyCategory.SubCategories) { if (c.Name.ToLower() == subcategory.ToLower()) { subCategory = c; } } //get the height of the thing double height = room.Height; //get the curves IList <IList <BoundarySegment> > boundary = internalRoom.GetBoundarySegments(new SpatialElementBoundaryOptions()); //generate a plane Autodesk.Revit.DB.Plane revitPlane = Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(Vector.ZAxis().ToXyz(), new XYZ(0, 0, 0)); Autodesk.Revit.DB.SketchPlane sketchPlane = SketchPlane.Create(familyDocument, revitPlane); //the curve arrays to generate solids and voids in family CurveArray curveArray = new CurveArray(); CurveArrArray curveArrArray = new CurveArrArray(); CurveArray curveArrayVoid = new CurveArray(); CurveArrArray curveArrArrayVoid = new CurveArrArray(); //to perform the cut action on the solid with the voids CombinableElementArray ceArray = new CombinableElementArray(); //transform bizness Point roomCentroid = room.BoundingBox.ToCuboid().Centroid(); Point locationPoint = Point.ByCoordinates(roomCentroid.X, roomCentroid.Y, 0); CoordinateSystem oldCS = CoordinateSystem.ByOrigin(locationPoint); CoordinateSystem newCS = CoordinateSystem.ByOrigin(0, 0, 0); //flag to step through the boundaries. int flag = 0; while (flag < boundary.Count) { //the first set of curves is the solid's boundary if (flag == 0) { //generate the solid form which is the first item in the boundary segments. foreach (BoundarySegment b in boundary[flag]) { Autodesk.DesignScript.Geometry.Curve c = b.GetCurve().ToProtoType(); Autodesk.DesignScript.Geometry.Curve movedCurve = c.Transform(oldCS, newCS) as Autodesk.DesignScript.Geometry.Curve; curveArray.Append(movedCurve.ToRevitType()); } curveArrArray.Append(curveArray); Extrusion solidExtrusion = familyDocument.FamilyCreate.NewExtrusion(true, curveArrArray, sketchPlane, height); if (material != null) { //Set the material Autodesk.Revit.DB.Parameter matParam = solidExtrusion.get_Parameter(BuiltInParameter.MATERIAL_ID_PARAM); matParam.Set(material); } //try to set the subcategory if (subCategory != null) { solidExtrusion.Subcategory = subCategory; } } //subsequent lists of curves are representative of the voids else { //clear the curves from the collection for all items after the second one. (index 2+) if (!curveArrayVoid.IsEmpty) { curveArrayVoid.Clear(); curveArrArrayVoid.Clear(); ceArray.Clear(); } //generate the void form foreach (BoundarySegment b in boundary[flag]) { Autodesk.DesignScript.Geometry.Curve c = b.GetCurve().ToProtoType(); Autodesk.DesignScript.Geometry.Curve movedCurve = c.Transform(oldCS, newCS) as Autodesk.DesignScript.Geometry.Curve; curveArrayVoid.Append(movedCurve.ToRevitType()); } curveArrArrayVoid.Append(curveArrayVoid); Extrusion voidExtrusion = familyDocument.FamilyCreate.NewExtrusion(false, curveArrArrayVoid, sketchPlane, height); //try to combine things foreach (Extrusion genericForm in new FilteredElementCollector(familyDocument).OfClass(typeof(Extrusion)) .Cast <Extrusion>()) { ceArray.Append(genericForm); } //to add the void to the solid familyDocument.CombineElements(ceArray); } flag++; } familyDocument.Regenerate(); trans.Commit(); Autodesk.Revit.DB.Family fam = null; //build the temporary path string familyFilePath = Path.GetTempPath() + name + ".rfa"; SaveAsOptions opt = new SaveAsOptions(); opt.OverwriteExistingFile = true; familyDocument.SaveAs(familyFilePath, opt); familyDocument.Close(false); TransactionManager.Instance.ForceCloseTransaction(); Transaction trans2 = new Transaction(doc, "Attempting to place or update Room family instances."); trans2.Start(); IFamilyLoadOptions loadOptions = new FamilyImportOptions(); bool variable = true; loadOptions.OnFamilyFound(true, out variable); doc.LoadFamily(familyFilePath, loadOptions, out fam); FamilySymbol familySymbol = (FamilySymbol)doc.GetElement(fam.GetFamilySymbolIds().First()); //try to find if it is placed already FilteredElementCollector col = new FilteredElementCollector(doc); //get built in category from user viewable category BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString()); foreach (Autodesk.Revit.DB.Element e in col.WhereElementIsNotElementType().OfCategory(myCatEnum).ToElements()) { Autodesk.Revit.DB.FamilySymbol type = (FamilySymbol)doc.GetElement(e.GetTypeId()); if (type.FamilyName.Equals(name)) { fileFound = true; internalFam = e as Autodesk.Revit.DB.FamilyInstance; } } //place families that are not placed if (fileFound == false) { if (!familySymbol.IsActive) { familySymbol.Activate(); } internalFam = doc.Create.NewFamilyInstance(new XYZ(roomCentroid.X, roomCentroid.Y, 0), familySymbol, internalRoom.Level, StructuralType.NonStructural); } trans2.Commit(); //delete the temp file File.Delete(familyFilePath); //cast to Dynamo type for output and location updating (if necessary) famInstance = internalFam.ToDSType(true); if (fileFound) { famInstance.SetLocation(locationPoint); } //returns the outputs var outInfo = new Dictionary <string, object> { { "familyInstance", famInstance } }; return(outInfo); }