/// <summary> /// Получучение типа семейства аннотации /// </summary> public static AnnotationSymbolType GetFamAn(string name) { FilteredElementCollector collector = new FilteredElementCollector(_doc); collector.OfCategory(BuiltInCategory.OST_GenericAnnotation); collector.WhereElementIsElementType(); AnnotationSymbolType fam = null; foreach (Element el in collector) { AnnotationSymbolType elAnSType = el as AnnotationSymbolType; string famName = elAnSType.Family.Name; if (famName == name) { fam = elAnSType; break; } } return(fam); }
private void Stream(ArrayList data, AnnotationSymbolType annoType) { data.Add(new Snoop.Data.ClassSeparator(typeof(AnnotationSymbolType))); // no data at this level }
/// <summary> /// Получение или создание семейства аннотации аппарата в линии /// </summary> public static AnnotationSymbolType GreateFamElSh(AnnotationSymbolType famElsh, IList <string> _done, Element elMainTable) { string name_ap_z = elMainTable.LookupParameter("KAV.SP.Тип, марка, обозначение документа").AsString(); Debug.Assert(name_ap_z != null, "Необходимо заполнить параметр: KAV.SP.Тип, марка, обозначение документа"); Element apZ = FamType(famElsh.Family, name_ap_z); if (apZ == null) { AnnotationSymbolType newApZ = FamType(famElsh.Family, "—") as AnnotationSymbolType; apZ = newApZ.Duplicate(name_ap_z); } if (!_done.Contains(apZ.Name)) { _done.Add(apZ.Name); string nazn_ap_z = elMainTable.LookupParameter("KAV.Назначение аппарата защиты").AsString(); string tip_ap_zz = elMainTable.LookupParameter("KAV.Mar.Тип аппарата защиты").AsString(); string tok_rasc_ap_z = elMainTable.LookupParameter("KAV.Mar.Ток уставки расцепителя").AsString(); int kol_pol_ap_z = elMainTable.LookupParameter("KAV.Mar.Количество полюсов аппарата защиты").AsInteger(); string pred_kom_st_ap_z = elMainTable.LookupParameter("KAV.Mar.Предельная коммутационная стойкость").AsString(); string tok_har = elMainTable.LookupParameter("KAV.Mar.Токовая характеристика").AsString(); string tok_har_ap_z = tok_har != "-" ? tok_har : ""; apZ.LookupParameter("УГО.Mar.Тип аппарата защиты").Set(tip_ap_zz); apZ.LookupParameter("УГО.Mar.Ток уставки расцепителя").Set(tok_rasc_ap_z); apZ.LookupParameter("УГО.Mar.Количество полюсов аппарата защиты").Set(kol_pol_ap_z.ToString()); apZ.LookupParameter("УГО.Mar.Предельная коммутационная стойкость").Set(pred_kom_st_ap_z); apZ.LookupParameter("УГО.Mar.Токовая характеристика").Set(tok_har_ap_z); int naznAp = 0; try { naznAp = apZ.LookupParameter(nazn_ap_z).AsInteger(); } // проверка у семейства аннотации видимость catch (NullReferenceException) { string message = string.Format("В семействе аннотации: {0}, отсутствует параметр видимости назначения аппарата: {1}, для типа {2}", famElsh.Family.Name, nazn_ap_z, name_ap_z); throw new NullReferenceException(message.ToString()); } if (naznAp != 1) { apZ.LookupParameter("диф").Set(0); apZ.LookupParameter("Амперметр").Set(0); apZ.LookupParameter("Вольтметр").Set(0); apZ.LookupParameter("конденсатор").Set(0); apZ.LookupParameter("мфип_ки").Set(0); apZ.LookupParameter("счетчик_ки").Set(0); apZ.LookupParameter("фильтр").Set(0); apZ.LookupParameter("узо").Set(0); apZ.LookupParameter("узип").Set(0); apZ.LookupParameter("трансформаторы тока").Set(0); apZ.LookupParameter("счетчик").Set(0); apZ.LookupParameter("рубильник").Set(0); apZ.LookupParameter("предохранитель").Set(0); apZ.LookupParameter("переключатель").Set(0); apZ.LookupParameter("силовой контакт пускателя").Set(0); apZ.LookupParameter("независимый расцепитель").Set(0); apZ.LookupParameter("мфип").Set(0); apZ.LookupParameter("магнитный пускатель").Set(0); apZ.LookupParameter("испытательная коробка").Set(0); apZ.LookupParameter("выключатель").Set(0); apZ.LookupParameter("привод").Set(0); apZ.LookupParameter(nazn_ap_z).Set(1); } } AnnotationSymbolType famAn = apZ as AnnotationSymbolType; return(famAn); }
Stream(ArrayList data, ElementType sym) { data.Add(new Snoop.Data.ClassSeparator(typeof(ElementType))); // no data at this level yet AnnotationSymbolType annoType = sym as AnnotationSymbolType; if (annoType != null) { Stream(data, annoType); return; } AreaReinforcementType areaReinforcementType = sym as AreaReinforcementType; if (areaReinforcementType != null) { Stream(data, areaReinforcementType); return; } AreaTagType areaTagType = sym as AreaTagType; if (areaTagType != null) { Stream(data, areaTagType); return; } BeamSystemType beamSystemType = sym as BeamSystemType; if (beamSystemType != null) { Stream(data, beamSystemType); return; } DimensionType dimType = sym as DimensionType; if (dimType != null) { Stream(data, dimType); return; } //TF FabricSheetType fabricST = sym as FabricSheetType; if (fabricST != null) { Stream(data, fabricST); return; } FabricWireType fabricWT = sym as FabricWireType; if (fabricWT != null) { Stream(data, fabricWT); return; } //TFEND GroupType groupType = sym as GroupType; if (groupType != null) { Stream(data, groupType); return; } HostObjAttributes hostAtt = sym as HostObjAttributes; if (hostAtt != null) { Stream(data, hostAtt); return; } InsertableObject insObj = sym as InsertableObject; if (insObj != null) { Stream(data, insObj); return; } LevelType levelType = sym as LevelType; if (levelType != null) { Stream(data, levelType); return; } LineAndTextAttrSymbol lineAndTextAttr = sym as LineAndTextAttrSymbol; if (lineAndTextAttr != null) { Stream(data, lineAndTextAttr); return; } LoadTypeBase loadTypeBase = sym as LoadTypeBase; if (loadTypeBase != null) { Stream(data, loadTypeBase); return; } MEPBuildingConstruction mepBldConst = sym as MEPBuildingConstruction; if (mepBldConst != null) { Stream(data, mepBldConst); return; } PathReinforcementType pathReinforcementType = sym as PathReinforcementType; if (pathReinforcementType != null) { Stream(data, pathReinforcementType); return; } RebarBarType rebarBarType = sym as RebarBarType; if (rebarBarType != null) { Stream(data, rebarBarType); return; } RebarCoverType rebarCoverType = sym as RebarCoverType; if (rebarCoverType != null) { Stream(data, rebarCoverType); return; } RebarHookType rebarHookType = sym as RebarHookType; if (rebarHookType != null) { Stream(data, rebarHookType); return; } RebarShape rebarShape = sym as RebarShape; if (rebarShape != null) { Stream(data, rebarShape); return; } RoomTagType roomTagType = sym as RoomTagType; if (roomTagType != null) { Stream(data, roomTagType); return; } SpaceTagType spaceTagType = sym as SpaceTagType; if (spaceTagType != null) { Stream(data, spaceTagType); return; } TrussType trussType = sym as TrussType; if (trussType != null) { Stream(data, trussType); return; } DistributionSysType distSysType = sym as DistributionSysType; if (distSysType != null) { Stream(data, distSysType); return; } MEPCurveType mepCurType = sym as MEPCurveType; if (mepCurType != null) { Stream(data, mepCurType); return; } FluidType fluidType = sym as FluidType; if (fluidType != null) { Stream(data, fluidType); return; } PipeScheduleType pipeSchedType = sym as PipeScheduleType; if (pipeSchedType != null) { Stream(data, pipeSchedType); return; } VoltageType voltType = sym as VoltageType; if (voltType != null) { Stream(data, voltType); return; } WireType wireType = sym as WireType; if (wireType != null) { Stream(data, wireType); return; } ModelTextType modelTxtType = sym as ModelTextType; if (modelTxtType != null) { Stream(data, modelTxtType); return; } }
Stream(ArrayList data, AnnotationSymbolType annoType) { data.Add(new Snoop.Data.ClassSeparator(typeof(AnnotationSymbolType))); // no data at this level }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { #region Get access to the current document and aplication. UIApplication uiapp = commandData.Application; UIDocument uidoc = commandData.Application.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application; Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document; #endregion // Try to create a project parameter. try { Category walls = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Walls); Category floors = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Floors); Category ceilings = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Ceilings); Category roofs = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Roofs); CategorySet catSet = new CategorySet(); catSet.Insert(walls); catSet.Insert(floors); catSet.Insert(ceilings); catSet.Insert(roofs); using (Transaction t = new Transaction(doc, "Add project parameter")) { t.Start(); CreateProjectParam(app, "LinkedTag", ParameterType.Integer, false, catSet, BuiltInParameterGroup.INVALID, true); if (t.Commit() == TransactionStatus.Committed) { } else { t.RollBack(); } } } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } if (Schema.Lookup(new Guid("2B195204-1C04-4538-8881-AD22FA697B41")) == null) { BuildNewSchema(doc); } // Retrieving a specific family from the database. try { // Create a new FilteredElementCollector FilteredElementCollector collector = new FilteredElementCollector(doc); // Define and apply one or more filters to it. ElementCategoryFilter categoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_GenericAnnotation); ParameterValueProvider pvp_1 = new ParameterValueProvider(new ElementId(BuiltInParameter.ALL_MODEL_FAMILY_NAME)); ParameterValueProvider pvp_2 = new ParameterValueProvider(new ElementId(BuiltInParameter.ALL_MODEL_TYPE_NAME)); FilterStringEquals equals = new FilterStringEquals(); string familyName = "Z-M2-MultilayerMaterialTag-LOD1"; string typeName = "2.5mm"; FilterRule fRule_1 = new FilterStringRule(pvp_1, equals, familyName, false); FilterRule fRule_2 = new FilterStringRule(pvp_2, equals, typeName, false); IList <FilterRule> fRules = new List <FilterRule> { fRule_1, fRule_2 }; ElementParameterFilter filters = new ElementParameterFilter(fRules); // Collect the familySymbol's id ICollection <ElementId> id = collector.WherePasses(categoryFilter).WherePasses(filters).ToElementIds(); if (id.Count == 0) { message = "No FamilyType has been detected."; return(Result.Failed); } AnnotationSymbolType materialTag = doc.GetElement(id.First()) as AnnotationSymbolType; if (CreateWorkPlane(doc) != true) { return(Result.Failed); } // Prompt the user to select select the element to be tagged. Reference pickedRef = null; pickedRef = uidoc.Selection.PickObject(ObjectType.Element, new MultilayerStrFilter(), "Please select a multilayer element."); Element selectedElm = doc.GetElement(pickedRef.ElementId); XYZ point = uidoc.Selection.PickPoint("Please pick a point to place the family"); StringBuilder strBld = new StringBuilder(); int rows; int shelfLength; switch (selectedElm.Category.Name) { case "Walls": Wall wl = selectedElm as Wall; WallType wlType = wl.WallType; CompoundStructure cmpStr_wl = wlType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_wl, doc, out shelfLength); rows = wlType.GetCompoundStructure().LayerCount; break; case "Floors": Floor fl = selectedElm as Floor; FloorType flType = fl.FloorType; CompoundStructure cmpStr_fl = flType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_fl, doc, out shelfLength); rows = flType.GetCompoundStructure().LayerCount; break; case "Ceilings": Ceiling cl = selectedElm as Ceiling; CeilingType clType = doc.GetElement(cl.GetTypeId()) as CeilingType; CompoundStructure cmpStr_cl = clType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_cl, doc, out shelfLength); rows = clType.GetCompoundStructure().LayerCount; break; case "Roofs": RoofBase rf = selectedElm as RoofBase; RoofType rfType = rf.RoofType; CompoundStructure cmpStr_rf = rfType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_rf, doc, out shelfLength); rows = rfType.GetCompoundStructure().LayerCount; break; default: TaskDialog.Show("Warning!", "This category is not supported."); return(Result.Failed); } using (Transaction trn_1 = new Transaction(doc, "Materials Mark")) { FamilyInstance createdElm = null; if (trn_1.Start() == TransactionStatus.Started) { createdElm = doc.Create.NewFamilyInstance(point, materialTag, doc.ActiveView); selectedElm.LookupParameter("LinkedTag").Set(createdElm.Id.IntegerValue); if (trn_1.Commit() == TransactionStatus.Committed) { Transaction trn_2 = new Transaction(doc, "Set parameters"); try { trn_2.Start(); createdElm.LookupParameter("multilineText").Set(strBld.ToString()); createdElm.LookupParameter("# of Rows").Set(rows); createdElm.LookupParameter("Shelf Length").Set(ToFt(shelfLength)); XYZ vec; if (selectedElm.Category.Name != "Walls") { vec = new XYZ(0, 0, createdElm.LookupParameter("Arrow Length").AsDouble() * doc.ActiveView.Scale); createdElm.LookupParameter("Down Arrow Direction").Set(1); } else { vec = new XYZ(-createdElm.LookupParameter("Arrow Length").AsDouble() * doc.ActiveView.Scale, 0, 0); createdElm.LookupParameter("Down Arrow Direction").Set(0); } ElementTransformUtils.MoveElement(doc, createdElm.Id, vec); trn_2.Commit(); AddElementToSchema(Schema.Lookup(new Guid("2B195204-1C04-4538-8881-AD22FA697B41")), createdElm, selectedElm.Id); } finally { if (trn_2 != null) { trn_2.Dispose(); } } } else { trn_1.RollBack(); return(Result.Failed); } } else { trn_1.RollBack(); return(Result.Failed); } return(Result.Succeeded); } } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; _doc = doc; //Prompt for Input contents Document fdocX = app.NewFamilyDocument("C:\\ProgramData\\Autodesk\\RVT 2013\\Family Templates\\English_I\\Annotations\\Generic Annotation.rft"); //Document fdocX = app.NewFamilyDocument("C:\\ProgramData\\Autodesk\\RVT 2013\\Family Templates\\English_I\\Generic Model.rft"); //New Qrencoder using the family document QREncoder qrcode = new QREncoder(fdocX, uidoc, app); string contents = Microsoft.VisualBasic.Interaction.InputBox("Enter and text to QR encode.", "QR Encode Prompt", "", -1, -1); if (contents != "") { if (null == fdocX) { return(Result.Failed); } // Modify document within a transaction using (Transaction tx = new Transaction(fdocX)) { tx.Start("Generate QR Code"); //GenerateQR(fdoc, qrcode, contents); GenerateQR(fdocX, qrcode, contents); tx.Commit(); } //save background family doc string dir = Path.GetDirectoryName(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); //Clean invalid filename characters string fileNameClean = CleanChars(contents); _familyName += fileNameClean; string filename = Path.Combine(dir, _familyName + ".rfa"); SaveAsOptions opt = new SaveAsOptions(); opt.OverwriteExistingFile = true; fdocX.SaveAs(filename, opt); fdocX.Close(false); //Insert new family into document using (Transaction tx2 = new Transaction(doc)) { tx2.Start("Insert QRCode"); Family fam = null; FilteredElementCollector fec = new FilteredElementCollector(doc) .OfClass(typeof(Family)); foreach (Family f in fec) { if (f.Name.Equals(_familyName)) { fam = f; } else { doc.LoadFamily(filename, out fam); } } FamilySymbol fs = null; foreach (FamilySymbol symbol in fam.Symbols) { fs = symbol; break; } XYZ p = uidoc.Selection.PickPoint("Please pick point to place QR code"); AnnotationSymbolTypeSet annoset = _doc.AnnotationSymbolTypes; AnnotationSymbolType annoSymbolType = null; foreach (AnnotationSymbolType type in annoset) { if (type.Name.Equals(_familyName)) { annoSymbolType = type; } } //Deprecated in 2013, but too lazy to implement new doc.Create.NewAnnotationSymbol(p, annoSymbolType, uidoc.ActiveView); //doc.Create.NewFamilyInstance(p, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); tx2.Commit(); } return(Result.Succeeded); } else { return(Result.Cancelled); } }