public TextNote AddNewTextNote(UIDocument uiDoc, XYZ textLoc, double noteWidth, string text) { Document doc = uiDoc.Document; ElementId defaultTextTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); // make sure note width works for the text type double minWidth = TextNote.GetMinimumAllowedWidth(doc, defaultTextTypeId); double maxWidth = TextNote.GetMaximumAllowedWidth(doc, defaultTextTypeId); if (noteWidth < minWidth) { noteWidth = minWidth; } else if (noteWidth > maxWidth) { noteWidth = maxWidth; } TextNoteOptions opts = new TextNoteOptions(defaultTextTypeId); opts.HorizontalAlignment = HorizontalTextAlignment.Left; opts.Rotation = 0; TextNote textNote = TextNote.Create(doc, doc.ActiveView.Id, textLoc, noteWidth, text, opts); return(textNote); }
public void CreateTextNote(Document doc, List <Reference> references, Selection sel) { var listtextnote = GetText(doc, references); var converttext = (from x in listtextnote select x.Text).ToList(); var text = string.Join("", converttext.ToArray()); ElementId elementId = listtextnote.First().TextNoteType.Id; XYZ point = sel.PickPoint(); TextNoteOptions options = new TextNoteOptions(); options.TypeId = elementId; options.HorizontalAlignment = HorizontalTextAlignment.Left; double noteWidth = 0.2; double minWidth = TextNote.GetMinimumAllowedWidth(doc, elementId); double maxWidth = TextNote.GetMaximumAllowedWidth(doc, elementId); if (noteWidth < minWidth) { noteWidth = minWidth; } else if (noteWidth > maxWidth) { noteWidth = maxWidth; } using (Transaction tran = new Transaction(doc, "Create Text")) { tran.Start(); TextNote textNote = TextNote.Create(doc, doc.ActiveView.Id, point, noteWidth, text, options); tran.Commit(); } }
public void CreteaTextnode(Document doc, string value, TextNoteType textNoteType) { ElementId defaultTextTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); TextNoteOptions opts = new TextNoteOptions(defaultTextTypeId); opts.TypeId = textNoteType.Id; XYZ point = sel.PickPoint(); PLane3D pLane3D = new PLane3D(doc.ActiveView.Origin, doc.ActiveView.ViewDirection); var P = pLane3D.ProjectPointOnPlane(point); TextNote textNote = TextNote.Create(doc, doc.ActiveView.Id, P, value, opts); }
/// <summary> /// Create a TextNote on the specified XYZ. /// This function is useful during debugging to attach /// a label to points in space /// </summary> public static TextNote CreateTextNote(string text, XYZ origin, Document doc) { var options = new TextNoteOptions { HorizontalAlignment = HorizontalTextAlignment.Center, VerticalAlignment = VerticalTextAlignment.Middle, TypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType) }; return(TextNote.Create(doc, doc.ActiveView.Id, origin, text, options)); }
internal override void Execute() { #region 与revit文档交互入口 UIDocument uidoc = this.uiapp.ActiveUIDocument; Document doc = uidoc.Document; Selection sel = uidoc.Selection; View actiView = doc.ActiveView; #endregion IList <Element> textNoteTypes = (new FilteredElementCollector(doc)).OfClass(typeof(TextNoteType)).ToElements(); string tntfield = "仿宋_3.5mm";//目标文字注释类型 ElementId tntId = null; foreach (Element tnt in textNoteTypes) { if (tnt.Name == tntfield)//需要确认是否存在门窗标记类型的文字注释 { tntId = tnt.Id; } } TextNoteOptions opts = new TextNoteOptions(tntId); opts.Rotation = 0; IList <Element> selElements1 = sel.PickElementsByRectangle("请框选元素"); using (Transaction trans = new Transaction(doc, "SetSurfaceTransparencyr")) { trans.Start(); foreach (Element element in selElements1) { if (!element.IsValidObject) { continue; //判断物体是否为有效物体 } //if (element.Pinned) continue; BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(actiView); if (boundingBoxXYZ == null) { continue; } XYZ textLoc = boundingBoxXYZ.Min - new XYZ(20, 0, 0); TextNote textNote = TextNote.Create(doc, actiView.Id, textLoc, element.Id.ToString(), opts); } trans.Commit(); } //throw new NotImplementedException(); }
private void drawLines(Document doc, List <Line> lines) { var defaultNoteTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); bool isReset = false; var counter = 0; for (int i = 0; i < lines.Count; i++) { var line = lines[i]; var plane = new Plane(XYZ.BasisY.Negate(), line.GetEndPoint(0)); var sketchPlane = SketchPlane.Create(doc, plane); var noteOptions = new TextNoteOptions() { HorizontalAlignment = HorizontalTextAlignment.Center, TypeId = defaultNoteTypeId }; var no = TextNote.Create(doc, doc.ActiveView.Id, line.GetEndPoint(0) + line.Direction * line.Length / 2, counter.ToString(), noteOptions); no.Width = no.Width / 2; var direction = TextNote.Create(doc, doc.ActiveView.Id, line.GetEndPoint(1) - line.Direction * line.Length * 0.05, "X", noteOptions); doc.Create.NewModelCurve(line, sketchPlane); if (counter == 3 && !isReset) { counter = 0; isReset = true; } else { counter++; } } }
//创建门窗标记字体实例 public TextNote AddNewTextNote(Document doc, ElementId viewId, XYZ textLoc, String str, double angle) { IList <Element> textNoteTypes = (new FilteredElementCollector(doc)).OfClass(typeof(TextNoteType)).ToElements(); string tntfield = "Arial Narrow-2.0-1.00-HDDN";//目标文字注释类型 ElementId tntId = null; foreach (Element tnt in textNoteTypes) { if (tnt.Name == tntfield)//需要确认是否存在门窗标记类型的文字注释 { tntId = tnt.Id; } } TextNoteOptions opts = new TextNoteOptions(tntId); opts.Rotation = angle; TextNote textNote = TextNote.Create(doc, viewId, textLoc, str, opts); return(textNote); }
/// <summary> /// Calulate the area of all the available rooms and specify them using TextNotes /// </summary> public void RoomArea() { Revit.Creation.Document doc = m_revitApp.ActiveUIDocument.Document.Create; SketchPlane sketchPlane = Utils.Geometry.GetWorldPlane(m_revitApp); RevitLookup.Test.Forms.Levels lev = new RevitLookup.Test.Forms.Levels(m_revitApp); if (lev.ShowDialog() != DialogResult.OK) return; Level curLevel = lev.LevelSelected; if (curLevel == null) { MessageBox.Show("No Level was selected."); return; } // Get the plan topology of the active doc first PlanTopology planTopo = m_revitApp.ActiveUIDocument.Document.get_PlanTopology(curLevel); ICollection<ElementId> roomIds = planTopo.GetRoomIds(); if (roomIds.Count > 0) { IEnumerator<ElementId> setIter = roomIds.GetEnumerator(); while (setIter.MoveNext()) { Room room = m_revitApp.ActiveUIDocument.Document.GetElement(setIter.Current) as Room; if (null != room) { Autodesk.Revit.DB.View view = m_revitApp.ActiveUIDocument.Document.ActiveView; LocationPoint locationPoint = room.Location as LocationPoint; Double area = room.get_Parameter(BuiltInParameter.ROOM_AREA).AsDouble(); Double roundedArea = Math.Round(area, 2); // providing an offset so that the Room Tag and the Area Tag dont overlap. Overlapping leads to an // alignment related assert. XYZ offset = new XYZ(5.0, 0, 0); /// align text middle and center TextNoteOptions op = new TextNoteOptions(); TextNote txtNote = TextNote.Create(m_revitApp.ActiveUIDocument.Document, view.Id, offset + locationPoint.Point, .25, roundedArea.ToString(), op); } } } else { MessageBox.Show("No rooms found in the Active Document", "RevitLookup", MessageBoxButtons.OK, MessageBoxIcon.Information); } // TBD: Tried to play around with PlanCircuits and there seems to be a problem with the IsRoomLocated property. // arj 1/23/07 //Revit.PlanCircuitSet circSet = planTopo.Circuits; //Revit.PlanCircuitSetIterator setIters = circSet.ForwardIterator(); //while (setIters.MoveNext()) //{ // Revit.PlanCircuit planCircuit = setIters.Current as Revit.PlanCircuit; // if (null != planCircuit) // { // // if (planCircuit.IsRoomLocated) // throws an exception always "Attempted to read or write protected memory. // This is often an indication that other memory is corrupt." // { // } // } //} }
private void Report(Document doc) { View active = doc.ActiveView; ElementId levelId = null; Parameter level = active.LookupParameter("Associated Level"); FilteredElementCollector lvlCollector = new FilteredElementCollector(doc); ICollection <Element> lvlCollection = lvlCollector.OfClass(typeof(Level)).ToElements(); foreach (Element l in lvlCollection) { Level lvl = l as Level; if (lvl.Name == level.AsString()) { levelId = lvl.Id; //TaskDialog.Show("test", lvl.Name + "\n" + lvl.Id.ToString()); } } using (Transaction trans = new Transaction(doc)) { trans.Start("Labels"); // Find all Room instances in the document by using category filter ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Rooms); // Apply the filter to the elements in the active document // Use shortcut WhereElementIsNotElementType() to find wall instances only IEnumerable <Room> rooms = new FilteredElementCollector(doc) .WhereElementIsNotElementType() .OfClass(typeof(SpatialElement)) .Where(e => e.GetType() == typeof(Room)) .Where(e => e.LevelId.IntegerValue == levelId.IntegerValue) .Cast <Room>(); foreach (Element e in rooms) { Room room = e as Room; LocationPoint locPoint = doc.GetElement(e.Id).Location as LocationPoint; XYZ textloc = locPoint.Point; ElementId defaultTextTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); double noteWidth = .2; // make sure note width works for the text type double minWidth = TextNote.GetMinimumAllowedWidth(doc, defaultTextTypeId); double maxWidth = TextNote.GetMaximumAllowedWidth(doc, defaultTextTypeId); if (noteWidth < minWidth) { noteWidth = minWidth; } else if (noteWidth > maxWidth) { noteWidth = maxWidth; } TextNoteOptions opts = new TextNoteOptions(defaultTextTypeId); opts.HorizontalAlignment = HorizontalTextAlignment.Left; opts.Rotation = 0; TextNote textNote = TextNote.Create(doc, doc.ActiveView.Id, textloc, noteWidth, room.Name, opts); } trans.Commit(); } }
private void Setsymbol(Document doc, Dimension ele1, Dimension ele2, string family, string type, string family1, string type1, Plane plane) { Line curve1 = ele1.Curve as Line; curve1.MakeBound(0, 1); Line line1 = Support.ProjectLineOnPlane(plane, curve1); Line curve2 = ele2.Curve as Line; curve2.MakeBound(0, 1); Line line2 = Support.ProjectLineOnPlane(plane, curve2); FamilySymbol symbol = Support.GetSymbol(doc, family, type); FamilySymbol symbol1 = Support.GetSymbol(doc, family1, type1); //SUPPORT.PARAMETER.PARAMETER para = new SUPPORT.PARAMETER.PARAMETER(); if (ele1.Id != ele2.Id) { //giao diem: XYZ giaodiem = Support.ExtendLineIntersection(line1, line2); ////Getendpoint: List <XYZ> listendpoint1 = Support.GetStartEndDimensio(ele1); List <XYZ> listendpoint2 = Support.GetStartEndDimensio(ele2); List <XYZ> TwoPointEndDim = Support.GetDimensionPointsEnd(doc, ele1); XYZ test1 = TwoPointEndDim[0]; test1 = Support.ProjectOnto(plane, test1); XYZ test2 = TwoPointEndDim[1]; test2 = Support.ProjectOnto(plane, test2); XYZ tp = new XYZ(2, 0, 0); Plane plane1 = Plane.CreateByNormalAndOrigin(line1.Direction.Normalize(), test2 - tp); #region Create line: var min1 = double.MaxValue; XYZ Point1 = XYZ.Zero; XYZ Point2 = XYZ.Zero; foreach (var point in listendpoint1) { var distance = giaodiem.DistanceTo(point); if (distance < min1) { Point1 = point; min1 = distance; } } var min2 = double.MaxValue; foreach (var point in listendpoint2) { var distance = giaodiem.DistanceTo(point); if (distance < min2) { Point2 = point; min2 = distance; } } Point1 = Support.ProjectOnto(plane, Point1); Point2 = Support.ProjectOnto(plane, Point2); XYZ ep21 = Support.ProjectOnto(plane, listendpoint2[0]); XYZ ep222 = Support.ProjectOnto(plane, listendpoint2[1]); DetailCurve cur1 = Support.createdetailcurve(doc, Point1, giaodiem, plane); DetailCurve cur3 = Support.createdetailcurve(doc, Point2, giaodiem, plane); #endregion #region : Create text List <Element> list1 = new List <Element>(); List <Element> list2 = new List <Element>(); for (int aa = 1; aa < ele1.Segments.Size; aa++) { Reference ref1 = ele1.References.get_Item(aa); Element element1 = doc.GetElement(ref1); if (element1.Name != null && element1.Category.Name == "Specialty Equipment") { list1.Add(element1); } } for (int bb = 1; bb < ele2.Segments.Size; bb++) { Reference ref2 = ele2.References.get_Item(bb); Element element2 = doc.GetElement(ref2); if (element2.Name != null && element2.Category.Name == "Specialty Equipment") { list2.Add(element2); } } XYZ kc = new XYZ(0, 0, 0); XYZ pos = new XYZ(0, 0, 0); ElementId defaultTextTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); TextNoteOptions opts = new TextNoteOptions(defaultTextTypeId); opts.HorizontalAlignment = HorizontalTextAlignment.Left; string s1 = list1.First().Name; #region : Create location FilteredElementCollector filter = new FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_MultiCategoryTags); List <Element> listtag = filter.OfCategory(BuiltInCategory.OST_MultiCategoryTags).WhereElementIsNotElementType().ToElements().ToList(); List <Element> sametag = new List <Element>(); foreach (var item in listtag) { IndependentTag el = doc.GetElement(item.Id) as IndependentTag; Element tag1 = el.GetTaggedLocalElement(); string tag = tag1.Name; if (tag == list1.First().Name) { sametag.Add(item); } } string lastname = ""; if (sametag.Count > 0) { Element elem1 = doc.GetElement(sametag.First().Id) as Element; string samename = elem1.Name; int gachngang = samename.LastIndexOf("-"); lastname = samename.Substring(gachngang + 1); string s11 = s1 + "\n" + "(" + lastname + ")"; } if (sametag.Count == 0) { lastname = " "; } #endregion if (giaodiem.DistanceTo(test1) < giaodiem.DistanceTo(test2)) { FamilyInstance newinstance = null;; XYZ kt = new XYZ(0, 0, 0); if (line1.Direction.DotProduct(XYZ.BasisX) == -1) { kt = new XYZ(-3.3, 0, 0); } if (line1.Direction.DotProduct(XYZ.BasisX) == 1) { kt = new XYZ(3.3, 0, 0); } if (line1.Direction.DotProduct(XYZ.BasisZ) == -1) { kt = new XYZ(0, 0, -3.3); } if (line1.Direction.DotProduct(XYZ.BasisZ) == 1) { kt = new XYZ(0, 0, 3.3); } if (line1.Direction.DotProduct(XYZ.BasisY) == 1) { kt = new XYZ(0, 4, 0); } if (line1.Direction.DotProduct(XYZ.BasisY) == -1) { kt = new XYZ(0, -4, 0); } if (line1.Direction.DotProduct(XYZ.BasisX) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisY) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1) { kt = new XYZ(0, 0, 0); } newinstance = doc.Create.NewFamilyInstance(test1 - kt, symbol, doc.ActiveView); #region : Create symbol newinstance.LookupParameter("Part No.").Set(s1); newinstance.LookupParameter("TEXT 3").Set("CL" + " (" + list1.Count * list2.Count + ")"); newinstance.LookupParameter("TEXT 2").Set(lastname); #endregion } else { FamilyInstance newinstance = null; #region : Create symbol if (line1.Direction.DotProduct(XYZ.BasisX) == -1) { XYZ kt = new XYZ(0.7, 0, 0); newinstance = doc.Create.NewFamilyInstance(test2 - kt, symbol, doc.ActiveView); } if (line1.Direction.DotProduct(XYZ.BasisX) == 1) { XYZ kt = new XYZ(0, 0, 0); newinstance = doc.Create.NewFamilyInstance(test2 - kt, symbol, doc.ActiveView); } if (line1.Direction.DotProduct(XYZ.BasisZ) == 1) { XYZ kt = new XYZ(0, 0, 0); newinstance = doc.Create.NewFamilyInstance(test2 - kt, symbol, doc.ActiveView); } if (line1.Direction.DotProduct(XYZ.BasisY) == 1) { XYZ kt = new XYZ(0, 3.2, 0); newinstance = doc.Create.NewFamilyInstance(test2 - kt, symbol, doc.ActiveView); } if (line1.Direction.DotProduct(XYZ.BasisY) == -1) { XYZ kt = new XYZ(0, 0, 0); newinstance = doc.Create.NewFamilyInstance(test2 - kt, symbol, doc.ActiveView); } if (line1.Direction.DotProduct(XYZ.BasisX) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisY) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1) { XYZ kt = new XYZ(0, 0, 0); newinstance = doc.Create.NewFamilyInstance(test2 - kt, symbol, doc.ActiveView); } ICollection <ElementId> result = new List <ElementId>(); ICollection <ElementId> newresult = new List <ElementId>(); result.Add(newinstance.Id); ElementTransformUtils.RotateElement(doc, newinstance.Id, line2, Math.PI * 0.5); newresult = ElementTransformUtils.MirrorElements(doc, result, plane1, true); doc.Delete(newinstance.Id); FamilyInstance famiin = doc.GetElement(newresult.First()) as FamilyInstance; famiin.LookupParameter("Part No.").Set(s1); famiin.LookupParameter("TEXT 3").Set("CL" + " (" + list1.Count * list2.Count + ")"); famiin.LookupParameter("TEXT 2").Set(lastname); #endregion } #endregion } else { List <XYZ> listendpoint1 = Support.GetStartEndDimensio(ele1); List <XYZ> TwoPointEndDim = Support.GetDimensionPointsEnd(doc, ele1); XYZ test1 = TwoPointEndDim[0]; test1 = Support.ProjectOnto(plane, test1); XYZ test2 = TwoPointEndDim[1]; test2 = Support.ProjectOnto(plane, test2); XYZ Point2 = XYZ.Zero; #region //if (line1.Direction.DotProduct(XYZ.BasisY) == -1) //{ // Point2 = test1 + kc1; // Point2 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, Point2); // DetailCurve cur1 = SUPPORT.LINE.LINE.createdetailcurve(doc, test1, Point2, plane); //} //if (Math.Round(line1.Direction.DotProduct(XYZ.BasisY), 2) == 1) //{ // Point2 = test1 + kc11; // Point2 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, Point2); // DetailCurve cur1 = SUPPORT.LINE.LINE.createdetailcurve(doc, test1, Point2, plane); //} //if (line1.Direction.DotProduct(XYZ.BasisZ) == 1) //{ // Point2 = test2 + kc2; // Point2 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, Point2); // test1 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, test1); // DetailCurve cur1 = SUPPORT.LINE.LINE.createdetailcurve(doc, test2, Point2, plane); //} //if (line1.Direction.DotProduct(XYZ.BasisZ) == -1) //{ // Point2 = test1 + kc22; // Point2 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, Point2); // test1 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, test1); // DetailCurve cur1 = SUPPORT.LINE.LINE.createdetailcurve(doc, test1, Point2, plane); //} //if (line1.Direction.DotProduct(XYZ.BasisX) == 1) //{ // Point1 = test2 - kc23; // Point1 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, Point1); // test1 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, test1); // DetailCurve cur1 = SUPPORT.LINE.LINE.createdetailcurve(doc, test2, Point1, plane); //} //if (line1.Direction.DotProduct(XYZ.BasisX) == -1) //{ // Point1 = test1 + kc23; // Point1 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, Point1); // test1 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, test1); // DetailCurve cur1 = SUPPORT.LINE.LINE.createdetailcurve(doc, test1, Point1, plane); //} ////if (line1.Direction.DotProduct(XYZ.BasisX) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisY) != -1 && line1.Direction.DotProduct(XYZ.BasisY) != 1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1 && line1.Direction.DotProduct(XYZ.BasisZ) != 1) ////{ //// CreateExtenline(doc, plane, ele1, 3.5); ////} //foreach (var point in listendpoint1) //{ // var distance = kc1.DistanceTo(point); // if (distance < min1) // { // Point1 = point; // min1 = distance; // } //} #endregion #region : Create text List <Element> list1 = new List <Element>(); for (int aa = 1; aa < ele1.Segments.Size; aa++) { Reference ref1 = ele1.References.get_Item(aa); Element element1 = doc.GetElement(ref1); if (element1.Name != null && element1.Category.Name == "Specialty Equipment") { list1.Add(element1); } } //XYZ pos = null; ElementId defaultTextTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); TextNoteOptions opts = new TextNoteOptions(defaultTextTypeId); string s1 = list1.First().Name; XYZ vector = test1 - test2; Double x = vector.DotProduct(XYZ.BasisX); Double y = vector.DotProduct(XYZ.BasisY); Double z = vector.DotProduct(XYZ.BasisZ); FamilyInstance newinstance = null; if (Support.IsHorizontal(vector, doc.ActiveView) == true) { XYZ kt = new XYZ(0, 0, 0); if (line1.Direction.DotProduct(XYZ.BasisX) == -1) { kt = new XYZ(-3.2, 0, 0); } if (line1.Direction.DotProduct(XYZ.BasisX) == 1) { kt = new XYZ(3.2, 0, 0); } if (line1.Direction.DotProduct(XYZ.BasisZ) == -1) { kt = new XYZ(0, 0, -3.2); } if (line1.Direction.DotProduct(XYZ.BasisZ) == 1) { kt = new XYZ(0, 0, 0); } if (line1.Direction.DotProduct(XYZ.BasisY) == 1) { kt = new XYZ(0, 3.2, 0); } if (line1.Direction.DotProduct(XYZ.BasisY) == -1) { kt = new XYZ(0, (3.2 + Support.Totaldim(ele1)), 0); } if (line1.Direction.DotProduct(XYZ.BasisX) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisY) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1) { kt = new XYZ(0, (3.2 + Support.Totaldim(ele1)), 0); } newinstance = doc.Create.NewFamilyInstance(test1, symbol, doc.ActiveView); } if (Support.IsVertical(vector, doc.ActiveView) == true) { XYZ kt = new XYZ(0, 0, 0); if (line1.Direction.DotProduct(XYZ.BasisX) == 1) { kt = new XYZ(-(Support.Totaldim(ele1) + 3.2), 0, 0); } if (line1.Direction.DotProduct(XYZ.BasisX) == -1) { kt = new XYZ(-3.2, 0, 0); } if (line1.Direction.DotProduct(XYZ.BasisZ) == 1) { kt = new XYZ(0, 0, -(Support.Totaldim(ele1) + 3.2)); } if (line1.Direction.DotProduct(XYZ.BasisZ) == -1) { kt = new XYZ(0, 0, -3.2); } if (line1.Direction.DotProduct(XYZ.BasisY) == -1) { kt = new XYZ(0, 3.2, 0); } if (line1.Direction.DotProduct(XYZ.BasisY) == 1) { kt = new XYZ(0, 3.2, 0); } if (line1.Direction.DotProduct(XYZ.BasisX) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisY) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1) { kt = new XYZ(0, 0, 0); } newinstance = doc.Create.NewFamilyInstance(test1, symbol1, doc.ActiveView); } if (Support.IsHorizontal(vector, doc.ActiveView) == false && Support.IsVertical(vector, doc.ActiveView) == false) { newinstance = doc.Create.NewFamilyInstance(test1, symbol, doc.ActiveView); } #endregion #region : Create location FilteredElementCollector filter = new FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_MultiCategoryTags); List <Element> listtag = filter.OfCategory(BuiltInCategory.OST_MultiCategoryTags).WhereElementIsNotElementType().ToElements().ToList(); List <Element> sametag = new List <Element>(); foreach (var item in listtag) { IndependentTag el = doc.GetElement(item.Id) as IndependentTag; Element tag1 = el.GetTaggedLocalElement(); string tag = tag1.Name; if (tag == list1.First().Name) { sametag.Add(item); } } try { if (sametag.Count > 0) { Element elem1 = doc.GetElement(sametag.First().Id) as Element; string samename = elem1.Name; int gachngang = samename.LastIndexOf("-"); string lastname = samename.Substring(gachngang + 1); string s11 = s1 + "\n" + "(" + lastname + ")"; #region : Create symbol newinstance.LookupParameter("Part No.").Set(s1); newinstance.LookupParameter("TEXT 3").Set("CL" + " (" + list1.Count + ")"); newinstance.LookupParameter("TEXT 2").Set(lastname); #endregion } else { newinstance.LookupParameter("Part No.").Set(s1); newinstance.LookupParameter("TEXT 3").Set("CL" + " (" + list1.Count + ")"); newinstance.LookupParameter("TEXT 2").Set(" "); } } catch { }; #endregion } }
public static void Place(UIApplication uiapp, TextLeaderPosition _textLeader, double _textWidth, double _leaderLength) { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; IList <UIView> uiviews = uidoc.GetOpenUIViews(); UIView uiview = null; foreach (UIView uv in uiviews) { if (uv.ViewId.Equals(doc.ActiveView.Id)) { uiview = uv; break; } } IList <XYZ> corners = uiview.GetZoomCorners(); XYZ p = corners[0]; XYZ q = corners[1]; XYZ v = q - p; XYZ center = p + 0.5 * v; try { using (Transaction tran = new Transaction(doc, "Text note created")) { if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text)) { //uses PresentationCore string textNoteContent = Clipboard.GetDataObject().GetData(DataFormats.Text).ToString(); //double width = 3.0 / 12.0; // feet on paper TextNoteOptions options = new TextNoteOptions(); options.HorizontalAlignment = HorizontalTextAlignment.Left; options.TypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); double noteWidth = _textWidth / 12; tran.Start(); TextNote note = TextNote.Create(doc, doc.ActiveView.Id, center, textNoteContent, options); note.Width = noteWidth; if (_textLeader == TextLeaderPosition.Both) { note.AddLeader(TextNoteLeaderTypes.TNLT_STRAIGHT_L); Leader lead = note.AddLeader(TextNoteLeaderTypes.TNLT_STRAIGHT_R); note.LeaderLeftAttachment = LeaderAtachement.TopLine; note.LeaderRightAttachment = LeaderAtachement.TopLine; note.Width = noteWidth; lead.End = new XYZ(center.X + _leaderLength, center.Y - 0.8, center.Z); } else if (_textLeader == TextLeaderPosition.Left) { note.AddLeader(TextNoteLeaderTypes.TNLT_STRAIGHT_L); note.LeaderLeftAttachment = LeaderAtachement.TopLine; note.Width = noteWidth; } else if (_textLeader == TextLeaderPosition.Right) { Leader lead = note.AddLeader(TextNoteLeaderTypes.TNLT_STRAIGHT_R); note.LeaderRightAttachment = LeaderAtachement.TopLine; note.Width = noteWidth; //lead.Elbow = new XYZ(center.X, center.Y, center.Z); lead.End = new XYZ(center.X + _leaderLength, center.Y - 0.8, center.Z); } tran.Commit(); } else { TaskDialog.Show("Warning", "Clipboard is empty. Try to copy something."); } } } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; try { XYZ origin = uidoc.Selection.PickPoint("Select insertion point"); double Yoffset = origin.Y; double width = 0.5; //feet TextNoteOptions options = new TextNoteOptions(); options.HorizontalAlignment = HorizontalTextAlignment.Left; options.TypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); ICollection <Element> textNoteTypes = new FilteredElementCollector(doc).OfClass(typeof(TextNoteType)).OrderBy(x => x.Name).ToList(); ElementClassFilter filter = new ElementClassFilter(typeof(TextNote)); using (Transaction t = new Transaction(doc, "Place text")) { t.Start(); foreach (Element e in textNoteTypes) { TextNoteType textNoteElement = doc.GetElement(e.Id) as TextNoteType; FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType(); var query = from element in collector where element.GetTypeId() == e.Id select element; double fontSize = Convert.ToDouble(textNoteElement.LookupParameter("Text Size").AsValueString().Replace("mm", "")) / 304.8; double borderOffset = textNoteElement.LookupParameter("Leader/Border Offset").AsDouble(); XYZ offsetPoint = new XYZ(origin.X, Yoffset, 0); TextNote note = TextNote.Create(doc, doc.ActiveView.Id, offsetPoint, width, textNoteElement.Name + " count: " + query.Count().ToString(), options); note.ChangeTypeId(e.Id); Yoffset -= (fontSize + borderOffset * 2 + 0.03); } t.Commit(); } return(Result.Succeeded); } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); return(Result.Failed); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var doc = commandData.Application.ActiveUIDocument.Document; try { var transaction = new Transaction(doc, "创建图纸"); transaction.Start(); #region 创建楼层平面 var level = Level.Create(doc, 1); var viewTypeList = from element in new FilteredElementCollector(doc). OfClass(typeof(ViewFamilyType)) let type = element as ViewFamilyType where type.ViewFamily == ViewFamily.FloorPlan select type; var viewTypeId = viewTypeList?.FirstOrDefault()?.Id; if (viewTypeId == null) { throw new Exception("没有找到楼层平面"); } var viewPlan = ViewPlan.Create(doc, viewTypeId, level.Id); #endregion #region 添加文字 #region 创建文字类型 TextNoteType newTextNoteType; var textFamilyName = "3.5mm 宋体"; var textNoteTypeList = from element in new FilteredElementCollector(doc). OfClass(typeof(TextNoteType)) let type = element as TextNoteType where type.FamilyName == "文字" && type.Name == textFamilyName select type; if (textNoteTypeList.Count() > 0) { newTextNoteType = textNoteTypeList.FirstOrDefault(); } else { textNoteTypeList = from element in new FilteredElementCollector(doc). OfClass(typeof(TextNoteType)) let type = element as TextNoteType where type.FamilyName == "文字" select type; var textNoteType = textNoteTypeList.FirstOrDefault(); newTextNoteType = textNoteType.Duplicate(textFamilyName) as TextNoteType; newTextNoteType.get_Parameter(BuiltInParameter.TEXT_SIZE).Set(3.5 / 304.8);//文字大小 newTextNoteType.get_Parameter(BuiltInParameter.TEXT_FONT).Set("宋体"); newTextNoteType.get_Parameter(BuiltInParameter.TEXT_BACKGROUND).Set(1); } #endregion #region 创建文字 var option = new TextNoteOptions(); option.HorizontalAlignment = HorizontalTextAlignment.Center; option.TypeId = newTextNoteType.Id; var textNote = TextNote.Create(doc, viewPlan.Id, new XYZ(0, 0, 0), viewPlan.Name, option); #endregion #endregion #region 应用视图样板 var viewTemplateList = from element in new FilteredElementCollector(doc). OfClass(typeof(ViewPlan)) let view = element as ViewPlan where view.IsTemplate && view.Name == "Architectural Plan" select view; var viewTemplate = viewTemplateList?.FirstOrDefault(); if (viewTemplate == null) { throw new Exception("没有找到视图样板"); } viewPlan.ViewTemplateId = viewTemplate.Id; #endregion #region 添加标注 var dimTypeList = from element in new FilteredElementCollector(doc). OfClass(typeof(DimensionType)) let type = element as DimensionType where type.Name == "Feet & Inches" select type; var targetDimensionType = dimTypeList?.FirstOrDefault(); var wall = doc.GetElement(new ElementId(1101836)) as Wall; var wallLocationCurve = (wall.Location as LocationCurve).Curve; var wallDirection = (wallLocationCurve as Line).Direction; var options = new Options(); options.ComputeReferences = true; var wallSolid = wall.GetGeometryObjects(options).FirstOrDefault() as Solid; var references = new ReferenceArray(); foreach (Face face in wallSolid.Faces) { if (face is PlanarFace pFace && pFace.FaceNormal.CrossProduct(wallDirection).IsAlmostEqualTo(XYZ.Zero) ) { references.Append(face.Reference); } } var offset = 1000 / 304.8; var line = Line.CreateBound(wallLocationCurve.GetEndPoint(0) + XYZ.BasisY * offset, wallLocationCurve.GetEndPoint(1) + XYZ.BasisY * offset); var dimension = doc.Create.NewDimension(viewPlan, line, references); dimension.DimensionType = targetDimensionType; #endregion #region 创建图纸 var sheet = ViewSheet.Create(doc, new ElementId(382615)); #endregion #region 添加视图到图纸 if (Viewport.CanAddViewToSheet(doc, sheet.Id, viewPlan.Id)) { var uv = new XYZ(698 / 304.8 / 2, 522 / 304.8 / 2, 0); var viewPort = Viewport.Create(doc, sheet.Id, viewPlan.Id, uv); } #endregion transaction.Commit(); } catch (Exception e) { return(Result.Failed); } return(Result.Succeeded); }
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; Selection SelectedObjs = uidoc.Selection; ICollection <ElementId> ids = uidoc.Selection.GetElementIds(); ElementId defTextType = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); List <double> cDiams = new List <double>(); Line LineDir = null; bool updateRack = false; List <string> Conduits = new List <string>(); TextNote toUpdate = null; RackDim.GetMenuValues(uiapp); Store.mod_split = 30; foreach (ElementId eid in ids) { Element elem = doc.GetElement(eid); if (elem.GetType() == typeof(TextNote)) { updateRack = true; toUpdate = elem as TextNote; } else { GeometryElement geom = elem.get_Geometry(Store.Dimop(doc.ActiveView)); cDiams.Add(elem.get_Parameter(BuiltInParameter.RBS_CONDUIT_DIAMETER_PARAM).AsDouble()); LineDir = RackDim.GetLineOfGeom(geom); } } if (toUpdate != null) { ids.Remove(toUpdate.Id); } double dMax = cDiams.Max(); foreach (string s in Conduits) { TaskDialog.Show("asd", s); } using (Transaction tx = new Transaction(doc)) { tx.Start("Create Text"); List <ElementId> Rows = new List <ElementId>(); List <List <ElementId> > allRows = SeparateRows(ids, doc, dMax); string diameters = ""; Double Distance = 0; List <double> leftXs = new List <double>(); List <ElementId> lefts = new List <ElementId>(); List <double> rightXs = new List <double>(); List <ElementId> rights = new List <ElementId>(); foreach (int i in SortRows(allRows, doc)) { string prev = ""; int typcount = 1; string diam; if (i == 0 && allRows.Count > 1) { diameters += "ABOVE: "; } else if (i == allRows.Count - 1 && allRows.Count != 1) { diameters += '\n' + "BELOW: "; } else if (allRows.Count > 1) { diameters += '\n' + "MIDDLE: "; } List <ElementId> SortedRows = SortX(allRows[i], doc); leftXs.Add(RackDim.GetRotatedToVert(SortedRows[0], doc).GetEndPoint(0).X); lefts.Add(SortedRows[0]); rightXs.Add(RackDim.GetRotatedToVert(SortedRows[SortedRows.Count - 1], doc).GetEndPoint(0).X); rights.Add(SortedRows[SortedRows.Count - 1]); foreach (ElementId eid in SortedRows) { diam = doc.GetElement(eid).get_Parameter(BuiltInParameter.RBS_CONDUIT_DIAMETER_PARAM).AsValueString(); if (diam == prev) { typcount += 1; } else { if (typcount != 1) { diameters = diameters + typcount + "-" + prev + "C, "; diameters = BreakLine(diameters, Store.mod_split); typcount = 1; } else if (prev != "") { diameters = diameters + prev + "C, "; diameters = BreakLine(diameters, Store.mod_split); } prev = diam; } } if (typcount != 1) { diameters = diameters + typcount + "-" + prev + "C"; } else { diameters = diameters + prev + "C"; } } ElementId firstEid = lefts[leftXs.IndexOf(leftXs.Max())]; ElementId lastEid = rights[rightXs.IndexOf(rightXs.Min())]; LocationCurve firstP = doc.GetElement(firstEid).Location as LocationCurve; LocationCurve lastP = doc.GetElement(lastEid).Location as LocationCurve; XYZ rotP = firstP.Curve.GetEndPoint(0); Distance = Math.Abs(RackDim.GetRotatedToVert(firstEid, doc, rotP).GetEndPoint(0).X - RackDim.GetRotatedToVert(lastEid, doc, rotP).GetEndPoint(0).X); Line firstL = firstP.Curve as Line; if (updateRack) { toUpdate.Text = diameters; } else { Line texRot = Line.CreateBound(firstP.Curve.GetEndPoint(0), firstP.Curve.GetEndPoint(1)); Double textAngle = texRot.Direction.AngleTo(new XYZ(0, -1, 0)); bool fix = false; if (textAngle >= Math.PI / 2) { textAngle = Math.PI - textAngle; fix = true; } TextNoteOptions textRotate = new TextNoteOptions { TypeId = defTextType, Rotation = textAngle }; TextNote text = TextNote.Create(doc, doc.ActiveView.Id, LineDir.Evaluate(Store.mod_place, true), diameters, textRotate); text.get_Parameter(BuiltInParameter.TEXT_ALIGN_HORZ).Set((Int32)TextAlignFlags.TEF_ALIGN_BOTTOM); if (fix) { text.Coord = firstP.Curve.Evaluate(Store.mod_place, true) .Add(RackDim.GetPerpendicular(firstL, Store.mod_place) .Direction.Multiply(Distance + (4 * Store.mod_firsty))); } else { text.Coord = firstP.Curve.Evaluate(Store.mod_place, true) .Subtract(RackDim.GetPerpendicular(firstL, Store.mod_place) .Direction.Multiply(Distance + (4 * Store.mod_firsty))); } text.Coord = new XYZ(text.Coord.X, text.Coord.Y + (1.4 * Store.mod_stepy), text.Coord.Z); text.AddLeader(TextNoteLeaderTypes.TNLT_STRAIGHT_R); text.AddLeader(TextNoteLeaderTypes.TNLT_STRAIGHT_R); IList <Leader> leaders = text.GetLeaders(); leaders[0].End = firstP.Curve.Evaluate(Store.mod_place, true); if (firstL.Direction.AngleTo(new XYZ(0, 1, 0)) >= Math.PI / 2) { leaders[1].End = leaders[0].End.Subtract(RackDim.GetPerpendicular(firstL, Store.mod_place) .Direction.Multiply(Distance)); } else { leaders[1].End = leaders[0].End.Add(RackDim.GetPerpendicular(firstL, Store.mod_place) .Direction.Multiply(Distance)); } if (fix) { leaders[0].Elbow = leaders[0].End.Subtract(RackDim.GetPerpendicular(firstL, Store.mod_place) .Direction.Multiply(1.4 * Store.mod_left)); leaders[1].Elbow = leaders[1].End.Add(RackDim.GetPerpendicular(firstL, Store.mod_place) .Direction.Multiply(1.4 * Store.mod_left)); } else { leaders[0].Elbow = leaders[0].End.Add(RackDim.GetPerpendicular(firstL, Store.mod_place) .Direction.Multiply(1.4 * Store.mod_left)); leaders[1].Elbow = leaders[1].End.Subtract(RackDim.GetPerpendicular(firstL, Store.mod_place) .Direction.Multiply(1.4 * Store.mod_left)); } } tx.Commit(); } return(Result.Succeeded); }
/// <summary> /// Tag wall layers by creating text note element on user /// specified point and populate it with layer information /// </summary> /// <param name="commandData"></param> /// <param name="message"></param> /// <param name="elements"></param> /// <returns></returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // Application context UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; // Get access the current view var activeView = uidoc.ActiveView; // Check if Text note can be created in currently active view bool canCreateTextNoteInView = false; switch (activeView.ViewType) { case ViewType.FloorPlan: canCreateTextNoteInView = true; break; case ViewType.CeilingPlan: canCreateTextNoteInView = true; break; case ViewType.Detail: canCreateTextNoteInView = true; break; } if (!canCreateTextNoteInView) { TaskDialog.Show("ERROR", "Text note can't be created in the current active view"); return(Result.Cancelled); } // Ask user to pick location point for Text Note var pt = uidoc.Selection.PickPoint("Pick text note location point"); // Ask user the select one basic wall Reference selectionReference = uidoc.Selection.PickObject(ObjectType.Element, "Select one wall"); Element selectionElement = doc.GetElement(selectionReference); // Cast generic element type to more specific wall type Wall wall = selectionElement as Wall; // Check if wall is type of basic wall if (wall.IsStackedWall) { TaskDialog.Show("Warning", "Wall you selected is category of the Stacked Wall.\nIt's not supported by this command"); return(Result.Cancelled); } // Access list of wall layers IList <CompoundStructureLayer> layers = wall.WallType.GetCompoundStructure().GetLayers(); // Get layer information in structured string format for Text note string a = ""; a += "Layer Function || " + "Material Name || " + "Layer Width" + "\n"; foreach (var l in layers) { var material = doc.GetElement(l.MaterialId) as Material; if (material != null) { a += l.Function.ToString() + " " + material.Name + " " + FeetTomm(l.Width).ToString() + "mm" + "\n"; } } // Create text note options var textNoteOptions = new TextNoteOptions { VerticalAlignment = VerticalTextAlignment.Top, HorizontalAlignment = HorizontalTextAlignment.Left, TypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType) }; // Open transaction for access to revit UI level document changing using (Transaction t = new Transaction(doc)) { t.Start("Tag Wall Layers"); // Create text note with wall layers information on user specified point in the current active view var textNote = TextNote.Create(doc, activeView.Id, pt, a, textNoteOptions); t.Commit(); } return(Result.Succeeded); }
/// <summary> /// Tag wall layers by creating text note element on user specified point and populate it with layer information. /// </summary> /// <param name="commandData">The command data.</param> /// <param name="message">The message.</param> /// <param name="elements">The elements.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // Application context. var uidoc = commandData.Application.ActiveUIDocument; var doc = uidoc.Document; // Check if we are in the Revit project , not in family one. if (doc.IsFamilyDocument) { Message.Display("Can't use command in family document", WindowType.Warning); return(Result.Cancelled); } // Get access to current view. var activeView = uidoc.ActiveView; // Check if Text Note can be created in currently active project view. bool canCreateTextNoteInView = false; switch (activeView.ViewType) { case ViewType.FloorPlan: case ViewType.CeilingPlan: case ViewType.Detail: case ViewType.Elevation: case ViewType.Section: case ViewType.EngineeringPlan: canCreateTextNoteInView = true; break; } // Collector for data provided in window. var userInfo = new TagWallLayersCommandData(); if (!canCreateTextNoteInView) { Message.Display("Text Note element can't be created in the current view.", WindowType.Error); return(Result.Cancelled); } try { // Get user provided information from window and show dialog. using (var window = new TagWallLayersForm(uidoc)) { window.ShowDialog(); if (window.DialogResult == DialogResult.Cancel) { return(Result.Cancelled); } userInfo = window.GetInformation(); } // Ask user to select one basic wall. var selectionReference = uidoc.Selection.PickObject(ObjectType.Element, //new SelectionFilterByCategory("Walls"), new SelectionFilterByCategory(BuiltInCategory.OST_Walls), "Select one basic wall."); var selectionElement = doc.GetElement(selectionReference); // Cast generic element type to more specific Wall type. var wall = selectionElement as Wall; // Check if wall is type of basic wall. if (wall == null || wall.IsStackedWall) { Message.Display("Wall you selected is category of the Stacked Wall.\nIt's not supported by this command.", WindowType.Warning); return(Result.Cancelled); } // Access list of wall layers. var layers = wall.WallType.GetCompoundStructure().GetLayers(); // Get layer information in structured string format for Text Note. var msg = new StringBuilder(); foreach (var layer in layers) { var material = doc.GetElement(layer.MaterialId) as Material; msg.AppendLine(); if (userInfo.Function) { msg.Append(layer.Function.ToString()); } // Check if material is attached to the layer in wall compound structure. if (userInfo.Name) { if (material != null) { msg.Append(" " + material.Name); } else { msg.Append(" <by category>"); } } // Convert units to metric. // Revit by default uses imperial units. if (userInfo.Thickness) { msg.Append(" " + LengthUnitConverter .ConvertToMetric(layer.Width, userInfo.UnitType, userInfo.Decimals) .ToString(CultureInfo.InvariantCulture)); } } // Create Text Note options. var textNoteOptions = new TextNoteOptions { VerticalAlignment = VerticalTextAlignment.Top, HorizontalAlignment = HorizontalTextAlignment.Left, TypeId = userInfo.TextTypeId }; // Open Revit document transaction to create new Text Note element. using (var transaction = new Transaction(doc)) { transaction.Start("Tag Wall Layers Command"); var pt = new XYZ(); // Construct sketch plane for user to pick point if we are in elevation or section view. if (activeView.ViewType == ViewType.Elevation || activeView.ViewType == ViewType.Section) { var plane = Plane.CreateByNormalAndOrigin(activeView.ViewDirection, activeView.Origin); var sketchPlane = SketchPlane.Create(doc, plane); activeView.SketchPlane = sketchPlane; } // Ask user to pick location point for the Text Note Element pt = uidoc.Selection.PickPoint("Pick text note location point"); // Create Text Note with wall layers information on user specified point in the current active view. var textNote = TextNote.Create(doc, activeView.Id, pt, msg.ToString(), textNoteOptions); transaction.Commit(); } } catch (Autodesk.Revit.Exceptions.OperationCanceledException ex) { return(Result.Cancelled); } catch { return(Result.Failed); } return(Result.Succeeded); }
/// <summary> /// Init element by location /// </summary> /// <param name="view"></param> /// <param name="origin"></param> /// <param name="alignment"></param> /// <param name="text"></param> /// <param name="keepRotatedTextreadable"></param> /// <param name="rotation">in degrees</param> /// <param name="typeId"></param> private void Init(RVT.View view, RVT.XYZ origin, RVT.HorizontalTextAlignment alignment, string text, bool keepRotatedTextreadable, double rotation, ElementId typeId) { Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(document); var element = ElementBinder.GetElementFromTrace <RVT.TextNote>(document); RVT.TextNoteOptions options = new TextNoteOptions() { HorizontalAlignment = alignment, KeepRotatedTextReadable = keepRotatedTextreadable, Rotation = rotation.ToRadians(), TypeId = typeId }; if (element == null) { element = RVT.TextNote.Create(document, view.Id, origin, text, options); } else { if (element.HorizontalAlignment != alignment) { element.HorizontalAlignment = alignment; } if (element.KeepRotatedTextReadable != keepRotatedTextreadable) { element.KeepRotatedTextReadable = keepRotatedTextreadable; } if (element.Text != text) { element.Text = text; } // if the element location is null, try to use the Coord property // Coord holds a point only without rotation. if (element.Location == null) { if (!element.Coord.IsAlmostEqualTo(origin)) { element.Coord = origin; } } else { // If a location point is set we can use this and extract // its location and rotation if (element.Location is LocationPoint) { LocationPoint point = (LocationPoint)element.Location; if (!point.Point.IsAlmostEqualTo(origin)) { point.Point = origin; } if (Math.Abs(point.Rotation - rotation.ToRadians()) <= System.Double.Epsilon) { point.Rotate(Line.CreateUnbound(XYZ.Zero, XYZ.BasisZ), rotation.ToRadians()); } } } } RVT.TextNoteType type = (RVT.TextNoteType)document.GetElement(typeId); InternalSetType(text, type, origin, alignment, rotation); InternalSetElement(element); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(this.InternalElement); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; try { XYZ origin = uidoc.Selection.PickPoint("Select insertion point"); double width = 0.2; //feet Category c = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines); CategoryNameMap subcats = c.SubCategories; double offset = 0; TextNoteOptions options = new TextNoteOptions(); options.HorizontalAlignment = HorizontalTextAlignment.Left; options.TypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); var dict = new SortedDictionary <string, GraphicsStyle>(); foreach (Category lineStyle in subcats) { GraphicsStyle gs = lineStyle.GetGraphicsStyle(GraphicsStyleType.Projection); dict.Add(gs.Name, gs); } var output = dict.OrderBy(e => e.Key).Select(e => new { graphicStyle = e.Value, linestyleName = e.Key }).ToList(); using (Transaction t = new Transaction(doc, "Place Lines")) { t.Start(); //foreach( Line item in ordered) { foreach (var item in output) { // GraphicsStyle gs = lineStyle.GetGraphicsStyle(GraphicsStyleType.Projection); XYZ newOrigin = new XYZ(origin.X, origin.Y + offset, 0); XYZ offsetPoint = new XYZ(origin.X + width, origin.Y + offset, 0); Line L1 = Line.CreateBound(newOrigin, offsetPoint); try { TextNote note = TextNote.Create(doc, doc.ActiveView.Id, new XYZ(origin.X - 0.2, origin.Y + offset + 0.01, 0), 0.2, item.linestyleName, options); DetailCurve e = doc.Create.NewDetailCurve(doc.ActiveView, L1); Parameter p = e.LookupParameter("Line Style"); p.Set(item.graphicStyle.Id); } catch { } offset -= 0.03; } t.Commit(); } return(Result.Succeeded); } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); return(Result.Failed); } }
RoomArea() { Revit.Creation.Document doc = m_revitApp.ActiveUIDocument.Document.Create; SketchPlane sketchPlane = Utils.Geometry.GetWorldPlane(m_revitApp); RevitLookup.Test.Forms.Levels lev = new RevitLookup.Test.Forms.Levels(m_revitApp); if (lev.ShowDialog() != DialogResult.OK) { return; } Level curLevel = lev.LevelSelected; if (curLevel == null) { MessageBox.Show("No Level was selected."); return; } // Get the plan topology of the active doc first PlanTopology planTopo = m_revitApp.ActiveUIDocument.Document.get_PlanTopology(curLevel); ICollection <ElementId> roomIds = planTopo.GetRoomIds(); if (roomIds.Count > 0) { IEnumerator <ElementId> setIter = roomIds.GetEnumerator(); while (setIter.MoveNext()) { Room room = m_revitApp.ActiveUIDocument.Document.GetElement(setIter.Current) as Room; if (null != room) { Autodesk.Revit.DB.View view = m_revitApp.ActiveUIDocument.Document.ActiveView; LocationPoint locationPoint = room.Location as LocationPoint; Double area = room.get_Parameter(BuiltInParameter.ROOM_AREA).AsDouble(); Double roundedArea = Math.Round(area, 2); // providing an offset so that the Room Tag and the Area Tag dont overlap. Overlapping leads to an // alignment related assert. XYZ offset = new XYZ(5.0, 0, 0); /// align text middle and center TextNoteOptions op = new TextNoteOptions(); TextNote txtNote = TextNote.Create(m_revitApp.ActiveUIDocument.Document, view.Id, offset + locationPoint.Point, .25, roundedArea.ToString(), op); } } } else { MessageBox.Show("No rooms found in the Active Document", "RevitLookup", MessageBoxButtons.OK, MessageBoxIcon.Information); } // TBD: Tried to play around with PlanCircuits and there seems to be a problem with the IsRoomLocated property. // arj 1/23/07 //Revit.PlanCircuitSet circSet = planTopo.Circuits; //Revit.PlanCircuitSetIterator setIters = circSet.ForwardIterator(); //while (setIters.MoveNext()) //{ // Revit.PlanCircuit planCircuit = setIters.Current as Revit.PlanCircuit; // if (null != planCircuit) // { // // if (planCircuit.IsRoomLocated) // throws an exception always "Attempted to read or write protected memory. // This is often an indication that other memory is corrupt." // { // } // } //} }
/// <summary> /// Handler method for ViewPrinting event. /// This method will dump EventArgument information of event firstly and then create TextNote element for this view. /// View print will be canceled if TextNote creation failed. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event arguments of ViewPrinting event.</param> public void AppViewPrinting(object sender, Autodesk.Revit.DB.Events.ViewPrintingEventArgs e) { // Setup log file if it still is empty if (null == m_eventsLog) { SetupLogFiles(); } // // header information Trace.WriteLine(System.Environment.NewLine + "View Print Start: ------------------------"); // // Dump the events arguments DumpEventArguments(e); // // Create TextNote for current view, cancel the event if TextNote creation failed bool failureOccured = false; // Reserves whether failure occurred when create TextNote try { String strText = String.Format("Printer Name: {0}{1}User Name: {2}", e.Document.PrintManager.PrinterName, System.Environment.NewLine, System.Environment.UserName); // // Use non-debug compile symbol to write constant text note #if !(Debug || DEBUG) strText = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; #endif using (Transaction eventTransaction = new Transaction(e.Document, "External Tool")) { eventTransaction.Start(); TextNoteOptions options = new TextNoteOptions(); options.HorizontalAlignment = HorizontalTextAlignment.Center; options.TypeId = e.Document.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); TextNote newTextNote = TextNote.Create(e.Document, e.View.Id, XYZ.Zero, strText, options); eventTransaction.Commit(); // Check to see whether TextNote creation succeeded if (null != newTextNote) { Trace.WriteLine("Create TextNote element successfully..."); m_newTextNoteId = newTextNote.Id; } else { failureOccured = true; } } } catch (System.Exception ex) { failureOccured = true; Trace.WriteLine("Exception occurred when creating TextNote, print will be canceled, ex: " + ex.Message); } finally { // Cancel the TextNote creation when failure occurred, meantime the event is cancellable if (failureOccured && e.Cancellable) { e.Cancel(); } } }
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; Selection choice = uidoc.Selection; Plane plane = Plane.CreateByNormalAndOrigin(doc.ActiveView.ViewDirection, doc.ActiveView.Origin); Dimension ele1 = null; Dimension ele2 = null; Reference r1 = choice.PickObject(ObjectType.Element, "Select First Dimension"); Reference r2 = choice.PickObject(ObjectType.Element, "Select Second Dimension"); using (Transaction tx = new Transaction(doc)) { tx.Start("Transaction Name"); Dimension dim1 = doc.GetElement(r1) as Dimension; Line curve1 = dim1.Curve as Line; curve1.MakeBound(0, 1); Line line1 = Support.ProjectLineOnPlane(plane, curve1); Dimension dim2 = doc.GetElement(r2) as Dimension; Line curve2 = dim2.Curve as Line; curve2.MakeBound(0, 1); Line line2 = Support.ProjectLineOnPlane(plane, curve2); XYZ vector1 = line1.GetEndPoint(0) - line1.GetEndPoint(1); XYZ vector2 = line2.GetEndPoint(0) - line2.GetEndPoint(1); if (Support.IsHorizontal(vector1, doc.ActiveView) == true) { ele1 = dim1; ele2 = dim2; } else { ele1 = dim2; ele2 = dim1; } List <Element> list1 = new List <Element>(); List <Element> list2 = new List <Element>(); for (int aa = 1; aa < ele1.Segments.Size; aa++) { Reference ref1 = ele1.References.get_Item(aa); Element element1 = doc.GetElement(ref1); if (element1.Name != null && element1.Category.Name == "Specialty Equipment") { list1.Add(element1); } } for (int bb = 1; bb < ele2.Segments.Size; bb++) { Reference ref2 = ele2.References.get_Item(bb); Element element2 = doc.GetElement(ref2); if (element2.Name != null && element2.Category.Name == "Specialty Equipment") { list2.Add(element2); } } if (list1.First().Name != list2.First().Name) { TaskDialog.Show("ERROR", "PLEASE SELECT TWO DIM FOR THE SAME OBJECT"); } else { if (clinename(doc) != "CSAZ" && clinename(doc) != "CSFL" && clinename(doc) != "STRESSCON") { if (ele1.Id != ele2.Id) { //giao diem: XYZ giaodiem = Support.ExtendLineIntersection(line1, line2); ////Getendpoint: List <XYZ> listendpoint1 = Support.GetStartEndDimensio(ele1); List <XYZ> listendpoint2 = Support.GetStartEndDimensio(ele2); List <XYZ> TwoPointEndDim = Support.GetDimensionPointsEnd(doc, ele1); XYZ test1 = TwoPointEndDim[0]; test1 = Support.ProjectOnto(plane, test1); XYZ test2 = TwoPointEndDim[1]; test2 = Support.ProjectOnto(plane, test2); //Create line: var min1 = double.MaxValue; XYZ Point1 = XYZ.Zero; XYZ Point2 = XYZ.Zero; foreach (var point in listendpoint1) { var distance = giaodiem.DistanceTo(point); if (distance < min1) { Point1 = point; min1 = distance; } } var min2 = double.MaxValue; foreach (var point in listendpoint2) { var distance = giaodiem.DistanceTo(point); if (distance < min2) { Point2 = point; min2 = distance; } } Point1 = Support.ProjectOnto(plane, Point1); Point2 = Support.ProjectOnto(plane, Point2); XYZ ep21 = Support.ProjectOnto(plane, listendpoint2[0]); XYZ ep222 = Support.ProjectOnto(plane, listendpoint2[1]); DetailCurve cur1 = Support.createdetailcurve(doc, Point1, giaodiem, plane); DetailCurve cur3 = Support.createdetailcurve(doc, Point2, giaodiem, plane); #region : Create text XYZ kc = new XYZ(0, 0, 0); XYZ pos = new XYZ(0, 0, 0); //if (line1.Direction.DotProduct(XYZ.BasisX) == 1) //{ // pos = new XYZ(10, 10, 10); //} if (giaodiem.DistanceTo(test1) < giaodiem.DistanceTo(test2)) { if (line1.Direction.DotProduct(XYZ.BasisY) > 0) { kc = new XYZ(0, 0, -0.45); } else { kc = new XYZ(0, 0, -0.45); } pos = Point1 - kc; } else { if (line1.Direction.DotProduct(XYZ.BasisY) > 0) { kc = new XYZ(0, 0, -0.45); } else { kc = new XYZ(0, 0, -0.45); } pos = Point1 - kc; } ElementId defaultTextTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); TextNoteOptions opts = new TextNoteOptions(defaultTextTypeId); opts.HorizontalAlignment = HorizontalTextAlignment.Left; //XYZ pos = Point1 - kc; string s1 = "CL (" + list1.Count * list2.Count + ") " + list1.First().Name; #endregion #region : Create location FilteredElementCollector filter = new FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_MultiCategoryTags); List <Element> listtag = filter.OfCategory(BuiltInCategory.OST_MultiCategoryTags).WhereElementIsNotElementType().ToElements().ToList(); List <Element> sametag = new List <Element>(); foreach (var item in listtag) { IndependentTag el = doc.GetElement(item.Id) as IndependentTag; Element tag1 = el.GetTaggedLocalElement(); string tag = tag1.Name; if (tag == list1.First().Name) { sametag.Add(item); } } if (sametag.Count > 0) { Element elem1 = doc.GetElement(sametag.First().Id) as Element; string samename = elem1.Name; int gachngang = samename.LastIndexOf("-"); string lastname = samename.Substring(gachngang + 2); string s11 = s1 + "\n" + "(" + lastname + ")"; TextNote s2 = TextNote.Create(doc, doc.ActiveView.Id, pos, s11, opts); } else { TextNote s2 = TextNote.Create(doc, doc.ActiveView.Id, pos, s1, opts); } #endregion } else { List <XYZ> listendpoint1 = Support.GetStartEndDimensio(ele1); #region : Create line var min1 = double.MaxValue; XYZ Point1 = XYZ.Zero; Double scale = doc.ActiveView.Scale; XYZ kc1 = new XYZ(0, 0.09 * scale, 0); XYZ kc11 = new XYZ(0, -0.09 * scale, 0); XYZ kc2 = new XYZ(0, 0, 0.09 * scale); XYZ kc22 = new XYZ(0, 0, 0.09 * scale); XYZ kc23 = new XYZ(-0.09 * scale, 0, 0); XYZ kc24 = new XYZ(0.09 * scale, 0, 0); XYZ kc25 = new XYZ(0.09 * scale, 0, 0.09 * scale); kc2 = Support.ProjectOnto(plane, kc2); kc23 = Support.ProjectOnto(plane, kc23); kc24 = Support.ProjectOnto(plane, kc24); kc25 = Support.ProjectOnto(plane, kc25); List <XYZ> TwoPointEndDim = Support.GetDimensionPointsEnd(doc, ele1); XYZ test1 = TwoPointEndDim[0]; test1 = Support.ProjectOnto(plane, test1); XYZ test2 = TwoPointEndDim[1]; test2 = Support.ProjectOnto(plane, test2); XYZ Point2 = XYZ.Zero; if (line1.Direction.DotProduct(XYZ.BasisY) == -1) { Point2 = test1 + kc1; Point2 = Support.ProjectOnto(plane, Point2); DetailCurve cur1 = Support.createdetailcurve(doc, test1, Point2, plane); } if (line1.Direction.DotProduct(XYZ.BasisY) == 1) { Point2 = test1 + kc11; Point2 = Support.ProjectOnto(plane, Point2); DetailCurve cur1 = Support.createdetailcurve(doc, test1, Point2, plane); } if (line1.Direction.DotProduct(XYZ.BasisZ) == 1) { Point2 = test2 + kc2; Point2 = Support.ProjectOnto(plane, Point2); test1 = Support.ProjectOnto(plane, test1); DetailCurve cur1 = Support.createdetailcurve(doc, test2, Point2, plane); } if (line1.Direction.DotProduct(XYZ.BasisZ) == -1) { Point2 = test1 + kc22; Point2 = Support.ProjectOnto(plane, Point2); test1 = Support.ProjectOnto(plane, test1); DetailCurve cur1 = Support.createdetailcurve(doc, test1, Point2, plane); } if (line1.Direction.DotProduct(XYZ.BasisX) == 1) { Point1 = test1 + kc23; Point1 = Support.ProjectOnto(plane, Point1); test1 = Support.ProjectOnto(plane, test1); DetailCurve cur1 = Support.createdetailcurve(doc, test1, Point1, plane); } if (line1.Direction.DotProduct(XYZ.BasisX) == -1) { Point1 = test1 + kc24; Point1 = Support.ProjectOnto(plane, Point1); test1 = Support.ProjectOnto(plane, test1); DetailCurve cur1 = Support.createdetailcurve(doc, test1, Point1, plane); } if (line1.Direction.DotProduct(XYZ.BasisX) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisY) != -1 && line1.Direction.DotProduct(XYZ.BasisY) != 1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1 && line1.Direction.DotProduct(XYZ.BasisZ) != 1) { CreateExtenline(doc, plane, ele1, 3.5); } foreach (var point in listendpoint1) { var distance = kc1.DistanceTo(point); if (distance < min1) { Point1 = point; min1 = distance; } } #endregion #region : Create text for (int aa = 1; aa < ele1.Segments.Size; aa++) { Reference ref1 = ele1.References.get_Item(aa); Element element1 = doc.GetElement(ref1); if (element1.Name != null && element1.Category.Name == "Specialty Equipment") { list1.Add(element1); } } XYZ pos = null; ElementId defaultTextTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); TextNoteOptions opts = new TextNoteOptions(defaultTextTypeId); string s1 = null; XYZ vector = test1 - test2; Double x = vector.DotProduct(XYZ.BasisX); Double y = vector.DotProduct(XYZ.BasisY); Double z = vector.DotProduct(XYZ.BasisZ); if (Support.IsHorizontal(vector, doc.ActiveView) == true) { XYZ kc = null; TextNoteOptions opts1 = new TextNoteOptions(); opts.HorizontalAlignment = HorizontalTextAlignment.Left; if (line1.Direction.DotProduct(XYZ.BasisY) == -1) { kc = new XYZ(0, 0, -0.44); pos = test1 - kc; } if (line1.Direction.DotProduct(XYZ.BasisY) == 1) { kc = new XYZ(0, 2.6, -0.44); pos = test1 - kc; } if (line1.Direction.DotProduct(XYZ.BasisX) == -1) { kc = new XYZ(-2.6, 0, -0.44); pos = test1 - kc; } if (line1.Direction.DotProduct(XYZ.BasisX) == 1) { kc = new XYZ(0.35, 0, -0.44); pos = test1 - kc; } if (line1.Direction.DotProduct(XYZ.BasisZ) == -1) { pos = test1; } if (line1.Direction.DotProduct(XYZ.BasisZ) == 1) { pos = test2; } if (line1.Direction.DotProduct(XYZ.BasisZ) != 1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1 && line1.Direction.DotProduct(XYZ.BasisY) != 1 && line1.Direction.DotProduct(XYZ.BasisY) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisX) != -1) { pos = test1; } s1 = "CL (" + (list1.Count) / 2 + ") " + list1.First().Name; } if (Support.IsVertical(vector, doc.ActiveView) == true) { XYZ kc = null; TextNoteOptions opts1 = new TextNoteOptions(); opts.HorizontalAlignment = HorizontalTextAlignment.Left; opts.Rotation = 0.5 * Math.PI; if (line1.Direction.DotProduct(XYZ.BasisZ) == -1) { kc = new XYZ(-0.42, 0, -0.35); pos = test1 - kc; } if (line1.Direction.DotProduct(XYZ.BasisZ) == 1) { kc = new XYZ(-0.42, 0.4, -0.35); pos = test1 - kc; } pos = test1; s1 = "CL (" + (list1.Count) / 2 + ") " + list1.First().Name; } if (Support.IsVertical(vector, doc.ActiveView) == false && Support.IsHorizontal(vector, doc.ActiveView) == false) { if (line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisX) != -1 && line1.Direction.DotProduct(XYZ.BasisY) != 1 && line1.Direction.DotProduct(XYZ.BasisY) != -1) { pos = test1; s1 = "CL (" + (list1.Count) / 2 + ") " + list1.First().Name; } } #endregion #region : Create location FilteredElementCollector filter = new FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_MultiCategoryTags); List <Element> listtag = filter.OfCategory(BuiltInCategory.OST_MultiCategoryTags).WhereElementIsNotElementType().ToElements().ToList(); List <Element> sametag = new List <Element>(); foreach (var item in listtag) { IndependentTag el = doc.GetElement(item.Id) as IndependentTag; Element tag1 = el.GetTaggedLocalElement(); string tag = tag1.Name; if (tag == list1.First().Name) { sametag.Add(item); } } if (sametag.Count > 0) { Element elem1 = doc.GetElement(sametag.First().Id) as Element; //string samename =elem1.GetParameters("CONTROL_MARK").ToString(); string samename = elem1.Name; int gachngang = samename.LastIndexOf("-"); string lastname = samename.Substring(gachngang + 2); string s11 = s1 + "\n" + "(" + lastname + ")"; TextNote s2 = TextNote.Create(doc, doc.ActiveView.Id, pos, s11, opts); } else { TextNote s2 = TextNote.Create(doc, doc.ActiveView.Id, pos, s1, opts); } #endregion } } //if (clinename(doc) == "") //{ // TaskDialog.Show("Error", "PLEASE CHECK PROJECT_CLIENT_PRECAST_MANUFACTURER"); //} if (clinename(doc) == "CSFL") { Setsymbol(doc, ele1, ele2, "AKSDADA1", "CS Miami Dummy Part Callout 3_16", "AKSDADA2", "CSS Miami Dummy Part Callout 3_16", plane); } if (clinename(doc) == "CSAZ") { Setsymbol(doc, ele1, ele2, "ARI1", "CS Arizon Dummy Part Callout 3_16", "ARI2", "CSS Arizon Dummy Part Callout 3_16", plane); } if (clinename(doc) == "STRESSCON") { Setsymbol(doc, ele1, ele2, "TAG TEXT NOTE", "NONE", "TAG TEXT NOTE1", "NONE", plane); } } tx.Commit(); } return(Result.Succeeded); }