示例#1
0
文件: Creator.cs 项目: wzfxue/Revit
        internal bool Generate(PBPAModel model)
        {
            Document doc  = model.Document;
            View     view = doc.GetElement(model.ViewId) as View;

            if (view == null)
            {
                return(false);
            }

            //主体
            var target         = doc.GetElement(model.TargetId);
            var targetLocation = target.Location as LocationCurve;
            var p0             = targetLocation.Curve.GetEndPoint(0);
            var p1             = targetLocation.Curve.GetEndPoint(1);
            var pMiddle        = new XYZ((p0.X + p1.X) / 2, (p0.Y + p1.Y) / 2, (p0.Z + p1.Z) / 2);

            model.TargetLocation = pMiddle;
            //线生成
            List <Line> lines = new List <Line>();

            model.CalculateLocations();                                            //计算内容定位
            lines.Add(Line.CreateBound(model.BodyStartPoint, model.BodyEndPoint)); //竖干线
            lines.Add(Line.CreateBound(model.BodyEndPoint, model.LeafEndPoint));   //斜支线
            model.LineIds = new List <ElementId>();
            foreach (var line in lines)
            {
                var lineElement = doc.Create.NewDetailCurve(view, line);
                model.LineIds.Add(lineElement.Id);
            }
            //文本生成
            IndependentTag subTag = doc.Create.NewTag(view, doc.GetElement(model.TargetId), false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, model.AnnotationLocation);

            model.AnnotationId     = subTag.Id;
            subTag.TagHeadPosition = model.AnnotationLocation;
            subTag.ChangeTypeId(model.GetAnnotationFamily(doc, model.TargetId).Id);
            return(true);
        }
示例#2
0
        public void Execute(UpdaterData updateData)
        {
            try
            {
                //if (PBPAContext.IsEditing == true)
                //{
                //    PBPAContext.IsEditing = false;
                //    return;
                //}
                var        document      = updateData.GetDocument();
                var        edits         = updateData.GetModifiedElementIds();
                var        collection    = PBPAContext.GetCollection(document);
                List <int> movedEntities = new List <int>();
                foreach (var changeId in edits)
                {
                    PBPAModel model = null;

                    #region 单管 主体 重新生成
                    var targetMoved = collection.Data.FirstOrDefault(c => c.TargetId == changeId);
                    if (targetMoved != null)
                    {
                        model = targetMoved;
                        if (movedEntities.Contains(model.TargetId.IntegerValue))
                        {
                            continue;
                        }
                        var creater        = PBPAContext.Creator;
                        var target         = document.GetElement(model.TargetId);//标注主体失效时删除
                        var targetLocation = target.Location as LocationCurve;
                        var p0             = targetLocation.Curve.GetEndPoint(0);
                        var p1             = targetLocation.Curve.GetEndPoint(1);
                        var pMiddle        = new XYZ((p0.X + p1.X) / 2, (p0.Y + p1.Y) / 2, (p0.Z + p1.Z) / 2);
                        var offset         = pMiddle - model.TargetLocation;
                        offset.ToSameZ(new XYZ(0, 0, 0));
                        model.BodyStartPoint += offset;
                        model.BodyEndPoint   += offset;
                        model.LeafEndPoint   += offset;
                        //必要族
                        model.Document     = document;
                        model.IsRegenerate = true;
                        if (!PBPAContext.Creator.Regenerate(model))
                        {
                            collection.Data.Remove(model);
                        }
                        movedEntities.Add(model.TargetId.IntegerValue);
                        //PBPAContext.IsEditing = true;//重新生成无需避免移动导致的重复触发
                        continue;
                    }
                    #endregion

                    #region 根据 标注 重新生成
                    var textMoved = collection.Data.FirstOrDefault(c => c.AnnotationId == changeId);
                    if (textMoved != null)
                    {
                        model = textMoved;
                        if (movedEntities.Contains(model.TargetId.IntegerValue))
                        {
                            continue;
                        }
                        var creater    = PBPAContext.Creator;
                        var annotation = document.GetElement(changeId) as IndependentTag;
                        var offset     = annotation.TagHeadPosition - model.AnnotationLocation;
                        offset.ToSameZ(new XYZ(0, 0, 0));
                        model.BodyEndPoint += offset;
                        model.LeafEndPoint += offset;
                        model.Document      = document;
                        model.IsRegenerate  = true;
                        if (!PBPAContext.Creator.Regenerate(model))
                        {
                            collection.Data.Remove(model);
                        }
                        movedEntities.Add(model.TargetId.IntegerValue);
                        //PBPAContext.IsEditing = true;//重新生成无需避免移动导致的重复触发
                        continue;
                    }
                    #endregion
                }
                PBPAContext.SaveCollection(document);
            }
            catch (Exception ex)
            {
                VLLogHelper.Error(ex);
            }
        }
示例#3
0
文件: Creator.cs 项目: wzfxue/Revit
 internal bool Regenerate(PBPAModel model)
 {
     model.Clear();
     return(Generate(model));
 }