public void Create3DModelLine(XYZ p, XYZ q, string line_style, WorksetId id) { try { if (p.IsAlmostEqualTo(q)) { debugger.show(err: "Expected two different points."); return; } Line line = Line.CreateBound(p, q); if (null == line) { debugger.show(err: "Geometry line creation failed."); return; } ModelCurve model_line_curve = null; model_line_curve = Info.DOC.Create.NewModelCurve(line, NewSketchPlanePassLine(line)); Parameter workset_param = model_line_curve.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM); workset_param.Set(Workset_Id.IntegerValue); // set linestyle ICollection <ElementId> styles = model_line_curve.GetLineStyleIds(); foreach (ElementId eid in styles) { Element e = Info.DOC.GetElement(eid); if (e.Name == line_style) { model_line_curve.LineStyle = e; break; } } } catch (Exception ex) { debugger.show(err: ex.ToString()); } }
/// <summary> /// Make a line from start point to end point with the direction and style /// </summary> /// <param name="startpt">start point</param> /// <param name="endpt">end point</param> /// <param name="direction">the direction which decide the plane</param> /// <param name="style">line style name</param> public void MakeLine(Autodesk.Revit.DB.XYZ startpt, Autodesk.Revit.DB.XYZ endpt, Autodesk.Revit.DB.XYZ direction, string style) { try { m_LineCount = m_LineCount + 1; Line line = Line.CreateBound(startpt, endpt); // Line must lie in the sketch plane. Use the direction of the line to construct a plane that hosts the target line. XYZ rotatedDirection = XYZ.BasisX; // If the direction is not vertical, cross the direction vector with Z to get a vector rotated ninety degrees. That vector, // plus the original vector, form the axes of the sketch plane. if (!direction.IsAlmostEqualTo(XYZ.BasisZ) && !direction.IsAlmostEqualTo(-XYZ.BasisZ)) { rotatedDirection = direction.Normalize().CrossProduct(XYZ.BasisZ); } Plane geometryPlane = m_app.Application.Create.NewPlane(direction, rotatedDirection, startpt); SketchPlane skplane = SketchPlane.Create(m_app.ActiveUIDocument.Document, geometryPlane); ModelCurve mcurve = m_app.ActiveUIDocument.Document.Create.NewModelCurve(line, skplane); m_app.ActiveUIDocument.Document.Regenerate(); //ElementArray lsArr = mcurve.LineStyles; ICollection <ElementId> lsArr = mcurve.GetLineStyleIds(); foreach (Autodesk.Revit.DB.ElementId eid in lsArr) { Element e = m_app.ActiveUIDocument.Document.GetElement(eid); if (e.Name == style) { mcurve.LineStyle = e; break; } } m_app.ActiveUIDocument.Document.Regenerate(); } catch (System.Exception ex) { m_outputInfo.Add("Failed to create lines: " + ex.ToString()); } }
private void Stream( ArrayList data, ModelCurve modelCurve ) { data.Add( new Snoop.Data.ClassSeparator( typeof( ModelCurve ) ) ); data.Add( new Snoop.Data.Object( "Geometry curve", modelCurve.GeometryCurve ) ); data.Add( new Snoop.Data.Object( "Sketch plane", modelCurve.SketchPlane ) ); data.Add( new Snoop.Data.ElementId( "Line style", modelCurve.LineStyle.Id, m_app.ActiveUIDocument.Document ) ); data.Add( new Snoop.Data.Enumerable( "Line styles", modelCurve.GetLineStyleIds(), m_app.ActiveUIDocument.Document ) ); ModelArc modelArc = modelCurve as ModelArc; if( modelArc != null ) { Stream( data, modelArc ); return; } ModelEllipse modelEllipse = modelCurve as ModelEllipse; if( modelEllipse != null ) { Stream( data, modelEllipse ); return; } ModelHermiteSpline modelHSpline = modelCurve as ModelHermiteSpline; if( modelHSpline != null ) { Stream( data, modelHSpline ); return; } ModelNurbSpline modelNSpline = modelCurve as ModelNurbSpline; if( modelNSpline != null ) { Stream( data, modelNSpline ); return; } ModelLine modelLine = modelCurve as ModelLine; if( modelLine != null ) { Stream( data, modelLine ); return; } }