BuildingCoder.Creator.CreateModelLine C# (CSharp) Метод

CreateModelLine() публичный статический Метод

Create a model line between the two given points. Internally, it creates an arbitrary sketch plane given the model line end points.
public static CreateModelLine ( Document doc, XYZ p, XYZ q ) : ModelLine
doc Document
p XYZ
q XYZ
Результат ModelLine
        public static ModelLine CreateModelLine(
            Document doc,
            XYZ p,
            XYZ q)
        {
            if( p.DistanceTo( q ) < Util.MinLineLength ) return null;

              // Create sketch plane; for non-vertical lines,
              // use Z-axis to span the plane, otherwise Y-axis:

              XYZ v = q - p;

              double dxy = Math.Abs( v.X ) + Math.Abs( v.Y );

              XYZ w = ( dxy > Util.TolPointOnPlane )
            ? XYZ.BasisZ
            : XYZ.BasisY;

              XYZ norm = v.CrossProduct( w ).Normalize();

              //Autodesk.Revit.Creation.Application creApp
              //  = doc.Application.Create;

              //Plane plane = creApp.NewPlane( norm, p ); // 2014
              //Plane plane = new Plane( norm, p ); // 2015, 2016
              Plane plane = Plane.CreateByNormalAndOrigin( norm, p ); // 2017

              //SketchPlane sketchPlane = creDoc.NewSketchPlane( plane ); // 2013
              SketchPlane sketchPlane = SketchPlane.Create( doc, plane ); // 2014

              //Line line = creApp.NewLine( p, q, true ); // 2013
              Line line = Line.CreateBound( p, q ); // 2014

              // The following line is only valid in a project
              // document. In a family, it will throw an exception
              // saying "Document.Create can only be used with
              // project documents. Use Document.FamilyCreate
              // in the Family Editor."

              //Autodesk.Revit.Creation.Document creDoc
              //  = doc.Create;

              //return creDoc.NewModelCurve(
              //  //creApp.NewLine( p, q, true ), // 2013
              //  Line.CreateBound( p, q ), // 2014
              //  sketchPlane ) as ModelLine;

              ModelCurve curve = doc.IsFamilyDocument
            ? doc.FamilyCreate.NewModelCurve( line, sketchPlane )
            : doc.Create.NewModelCurve( line, sketchPlane );

              return curve as ModelLine;
        }

Usage Example

        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            FamilyInstance beam = Util.SelectSingleElementOfType(
                uidoc, typeof(FamilyInstance), "a beam", false) as FamilyInstance;

            BuiltInCategory bic
                = BuiltInCategory.OST_StructuralFraming;

            if (null == beam ||
                null == beam.Category ||
                !beam.Category.Id.IntegerValue.Equals((int)bic))
            {
                message = "Please select a single beam element.";
            }
            else
            {
                LocationCurve curve
                    = beam.Location as LocationCurve;

                if (null == curve)
                {
                    message = "No curve available";
                    return(Result.Failed);
                }

                XYZ p = curve.Curve.GetEndPoint(0);
                XYZ q = curve.Curve.GetEndPoint(1);
                XYZ v = 0.1 * (q - p);
                p = p - v;
                q = q + v;

                //Creator creator = new Creator( doc );
                //creator.CreateModelLine( p, q );

                using (Transaction t = new Transaction(doc))
                {
                    t.Start("Create Model Line");

                    Creator.CreateModelLine(doc, p, q);

                    t.Commit();
                }
            }
            return(Result.Succeeded);
        }
All Usage Examples Of BuildingCoder.Creator::CreateModelLine