public ModelCurve ModelLineCreation(UIApplication app, XYZ startPoint, XYZ endPoint, int counter, string style = "") {
ModelCurve mc = null;
Autodesk.Revit.DB.Document doc = app.ActiveUIDocument.Document;
View view = doc.ActiveView;
using (Transaction tr = new Transaction(doc, "ModelLine creation")) {
tr.Start();
CurveArray ca = new CurveArray();
XYZ origin = new XYZ(-1000, -1000, 0);
Line mLine = Line.CreateBound(startPoint, endPoint);
ca.Append(mLine);
ca.Append(Line.CreateBound(mLine.GetEndPoint(1), origin));
ca.Append(Line.CreateBound(origin, mLine.GetEndPoint(0)));
Plane verticalGeometryPlane = app.Application.Create.NewPlane(ca);
SketchPlane verticalSkplane = SketchPlane.Create(doc, verticalGeometryPlane);
mc = doc.Create.NewModelCurve(mLine, verticalSkplane);
XYZ lineDirection = (Line.CreateBound(startPoint, endPoint)).Direction; ////// код из первого ответа
XYZ normal = XYZ.BasisZ.CrossProduct(lineDirection).Normalize();
XYZ transform = normal.Multiply(0.5);
LocationCurve mcLine = mc.Location as LocationCurve;
mcLine.Move(transform);
XYZ baseVec1 = XYZ.BasisX;
XYZ upVec1 = XYZ.BasisZ;
double lineWidth = 1.0/12.0;
TextNoteOptions to = new TextNoteOptions();
to.HorizontalAlignment = HorizontalTextAlignment.Center;
to.TypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);
if (style != "") {
GraphicsStyle debugStyle = GetLineStyleByName(doc, mc, style);
mc.LineStyle = debugStyle;
}
tr.Commit();
}
return mc;
}
public GraphicsStyle GetLineStyleByName(Autodesk.Revit.DB.Document doc, CurveElement element, string styleName) {
foreach (Element style in GetLineStyles(doc, element)) {
GraphicsStyle anyStyle = style as GraphicsStyle;
if (anyStyle.Name == styleName) {
if (anyStyle.GraphicsStyleType == GraphicsStyleType.Projection) {
return anyStyle;
}
}
}
return null;
}
public List<GraphicsStyle> GetLineStyles(Autodesk.Revit.DB.Document doc, CurveElement element) {
List<GraphicsStyle> styles = new List<GraphicsStyle>();
ICollection<ElementId> lineIDs = element.GetLineStyleIds();
foreach (ElementId lineID in lineIDs) {
Element elem = doc.GetElement(lineID);
if (elem != null) {
GraphicsStyle style = elem as GraphicsStyle;
if (style != null)
styles.Add(style);
}
}
return styles;
}