Exemple #1
0
        public static MEPCurve BreakCurve(this MEPCurve mep, XYZ point)
        {
            var locationline = mep.LocationLine();
            var start        = locationline.StartPoint();
            var end          = locationline.EndPoint();
            var executeflag  = point.IsOnLine(locationline) && point.DistanceTo(start) > 1d.MetricToFeet() &&
                               point.DistanceTo(end) > 1d.MetricToFeet();

            if (!executeflag)
            {
                throw new Exception("点不在线上");
            }
            var doc = mep.Document;

#if Revit2016
            return(null);
#endif
#if Revit2019
            ElementId result = null;
            if (mep is Duct)
            {
                result = MechanicalUtils.BreakCurve(doc, mep.Id, point);
            }
            else if (mep is Pipe)
            {
                result = PlumbingUtils.BreakCurve(doc, mep.Id, point);
            }
            else if (mep is CableTray)
            {
                var newline1 = Line.CreateBound(start, point);
                var newline2 = Line.CreateBound(point, end);
                (mep.Location as LocationCurve).Curve = newline1;
                var newcabletray = CableTray.Create(doc, mep.GetTypeId(), point, end, mep.ReferenceLevel.Id);
                var para_w       = newcabletray.get_Parameter(BuiltInParameter.RBS_CABLETRAY_WIDTH_PARAM);
                var para_H       = newcabletray.get_Parameter(BuiltInParameter.RBS_CABLETRAY_HEIGHT_PARAM);
                para_w.Set(mep.Width);
                para_H.Set(mep.Height);
                result = newcabletray.Id;
            }
            return(result.GetElement(doc) as MEPCurve);
#endif
        }
        /// <summary>
        /// what can i do with revit api now?
        /// move wall by location
        /// </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)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            Selection sel = uidoc.Selection;

            ElementId eleId = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Wall)).ElementId;

            // doc.Invoke(m => { ElementTransformUtils.MoveElement(doc, eleId, new XYZ(1000d.MmToFeet(), 1000d.MmToFeet(), 0)); },
            //            "移动一片墙");

            doc.Invoke(m =>
            {
                LocationCurve wallLine = eleId.GetElement(doc).Location as LocationCurve;

                XYZ transVec = new XYZ(1000d.MmToFeet(), 1000d.MmToFeet(), 0);

                wallLine.Move(transVec);//墙上的窗户会跟着一起移动
            }, "移动墙通过location");

            return(Result.Succeeded);
        }