コード例 #1
0
ファイル: PAACreator.cs プロジェクト: wzfxue/Revit
        private bool GenerateMultiplePipe(PAAModel model)
        {
            Document doc  = model.Document;
            View     view = doc.GetElement(model.ViewId) as View;

            if (view == null)
            {
                return(false);
            }
            model.CalculateLocations();
            if (model.IsRegenerate)
            {
                model.Clear();
            }
            XYZ parallelVector    = model.ParallelVector;
            XYZ verticalVector    = model.VerticalVector;
            var pipeAndNodePoints = model.PipeAndNodePoints;
            //线 创建
            FamilyInstance line = doc.Create.NewFamilyInstance(model.TargetLocation, model.GetLineFamily(doc), view);
            //线 旋转处理
            LocationPoint locationPoint = line.Location as LocationPoint;

            locationPoint.RotateByXY(model.TargetLocation, model.VerticalVector);
            model.LineId = line.Id;
            UpdateLineParameters(model, pipeAndNodePoints, line, verticalVector);
            //标注 创建
            model.AnnotationIds = new List <ElementId>();
            for (int i = 0; i < pipeAndNodePoints.Count(); i++)
            {
                var subTag = doc.Create.NewTag(view, pipeAndNodePoints[i].Target, false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, pipeAndNodePoints[i].AnnotationPoint);
                model.AnnotationIds.Add(subTag.Id);
            }
            return(true);
        }
コード例 #2
0
ファイル: CSACreater.cs プロジェクト: wzfxue/Revit
        public void Generate(Document doc, CSAModel model, Element element, XYZ offset)
        {
            CompoundStructure compoundStructure = model.GetCompoundStructure(element);//获取文本载体

            if (compoundStructure == null)
            {
                return;
            }
            var texts = model.FetchTextsFromCompoundStructure(doc, compoundStructure);//获取文本数据

            if (texts.Count == 0)
            {
                return;
            }
            if (texts.Count == 1)
            {
                TaskDialog.Show("警告", "暂不支持单层的结构做法标注");
            }
            else
            {
                model.TargetId = element.Id;                                                     //主体
                var            lineFamilySymbol = VLConstraintsForCSA.GetMultipleTagSymbol(doc); //获取线标注类型
                bool           isRegenerate     = offset != null;
                FamilyInstance line;
                if (isRegenerate)
                {
                    line = doc.GetElement(model.LineId) as FamilyInstance;
                    model.CalculateLocations(element, line, offset);                                         //计算内容定位
                    Clear(doc, model);
                    line = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), lineFamilySymbol, doc.ActiveView); //生成 线
                }
                else
                {
                    line = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), lineFamilySymbol, doc.ActiveView); //生成 线
                    model.CalculateLocations(element, line, offset);                                         //计算内容定位
                }
                var lineLocation  = model.LineLocation;
                var textLocations = model.TextLocations;
                ElementTransformUtils.MoveElement(doc, line.Id, lineLocation); //线定位
                LocationPoint locationPoint = line.Location as LocationPoint;  //线 旋转处理
                locationPoint.RotateByXY(lineLocation, model.VerticalVector);
                model.LineId = line.Id;
                model.UpdateLineParameters(line, model.LineHeight, model.LineWidth, model.LineSpace, model.Texts.Count()); //线参数设置
                List <TextNote> textNotes = new List <TextNote>();
                foreach (var text in model.Texts)                                                                          //生成 文本
                {
                    var textLocation = model.TextLocations[model.Texts.IndexOf(text)];
                    var textNote     = TextNote.Create(doc, doc.ActiveView.Id, textLocation, text, model.TextNoteTypeElementId);
                    textNotes.Add(textNote);
                    textNote.Location.RotateByXY(textLocation, model.VerticalVector);
                }
                model.TextNoteIds = textNotes.Select(c => c.Id).ToList();
                //测试用
                //GraphicsDisplayerManager.Display(@"E:\WorkingSpace\Outputs\Images\1023结构做法标注.png", lines, Model.TextLocations);
            }
        }
コード例 #3
0
ファイル: AnnotationCreater.cs プロジェクト: wzfxue/Revit
        /// <summary>
        /// 生成标注
        /// </summary>
        /// <param name="selectedIds"></param>
        /// <param name="entity"></param>
        /// <param name="view"></param>
        /// <returns></returns>
        AnnotationBuildResult GenerateMultipleTagSymbol(Document document, IEnumerable <ElementId> selectedIds, PipeAnnotationEntity entity, MultiPipeAnnotationSettings setting)
        {
            View                    view              = document.ActiveView;
            XYZ                     startPoint        = null;
            FamilyInstance          line              = null;
            List <PipeAndNodePoint> pipeAndNodePoints = new List <PipeAndNodePoint>();
            var                     tags              = new List <IndependentTag>();

            //管道 获取
            foreach (var selectedId in selectedIds)
            {
                pipeAndNodePoints.Add(new PipeAndNodePoint(Document.GetElement(selectedId) as Pipe));
            }
            //平行,垂直 向量
            XYZ parallelVector = null;
            XYZ verticalVector = null;

            parallelVector = ((pipeAndNodePoints.First().Pipe.Location as LocationCurve).Curve as Line).Direction;
            verticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0);
            parallelVector = LocationHelper.GetVectorByQuadrant(parallelVector, QuadrantType.OneAndFour);
            verticalVector = LocationHelper.GetVectorByQuadrant(verticalVector, QuadrantType.OneAndTwo);
            if (parallelVector.Y == 1)
            {
                verticalVector = -verticalVector;
            }
            //平行检测
            if (!CheckParallel(pipeAndNodePoints.Select(c => c.Pipe), verticalVector))
            {
                return(AnnotationBuildResult.NotParallel);
            }
            XYZ rightOfLefts; //左侧点的右边界
            XYZ leftOfRights; //右侧点的左边界

            //节点计算
            if (!GetNodePoints(pipeAndNodePoints, out rightOfLefts, out leftOfRights))
            {
                return(AnnotationBuildResult.NoOverlap);
            }
            pipeAndNodePoints = pipeAndNodePoints.OrderByDescending(c => c.NodePoint.Y).ToList();
            var pipes             = pipeAndNodePoints.Select(c => c.Pipe).ToList();
            var orderedNodePoints = pipeAndNodePoints.Select(c => c.NodePoint).ToList();

            //起始点
            startPoint = orderedNodePoints.First();
            //线 创建
            var multipleTagSymbol = PAContext.GetMultipleTagSymbol(document);

            if (!multipleTagSymbol.IsActive)
            {
                multipleTagSymbol.Activate();
            }
            line = Document.Create.NewFamilyInstance(startPoint, multipleTagSymbol, view);
            //线 旋转处理
            LocationPoint locationPoint = line.Location as LocationPoint;

            if (locationPoint != null)
            {
                locationPoint.RotateByXY(startPoint, verticalVector);
            }
            //线 参数设置
            UpdateLineParameters(orderedNodePoints, line, verticalVector);
            //标注 创建
            var textSize   = PAContext.TextSize;
            var widthScale = PAContext.WidthScale;
            //碰撞检测区域点
            XYZ avoidP1_Line1       = orderedNodePoints.Last();
            XYZ avoidP2_Line2       = null;
            XYZ avoidP3_Annotation1 = null;

            switch (entity.LocationType)
            {
            case MultiPipeTagLocation.OnLineEdge:
                //添加对应的单管直径标注
                line.GetParameters(TagProperty.线宽度.ToString()).First().Set(UnitHelper.ConvertToFoot(200, AnnotationConstaints.UnitType));
                var height = Convert.ToDouble(line.GetParameters(TagProperty.线高度1.ToString()).First().AsValueString()) + (orderedNodePoints.Count() - 1) * AnnotationConstaints.TextHeight;
                avoidP2_Line2 = avoidP1_Line1 + UnitHelper.ConvertToFoot(height, AnnotationConstaints.UnitType) * verticalVector;
                var skewLength = AnnotationConstaints.SkewLengthForOffLine;
                for (int i = 0; i < pipes.Count(); i++)
                {
                    var subTag       = Document.Create.NewTag(view, pipes[i], false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, startPoint);
                    var text         = subTag.TagText;
                    var textLength   = System.Windows.Forms.TextRenderer.MeasureText(text, AnnotationConstaints.Font).Width;
                    var actualLength = textLength / (textSize * widthScale);
                    subTag.TagHeadPosition = startPoint + skewLength * parallelVector + UnitHelper.ConvertToInch(actualLength, VLUnitType.millimeter) * parallelVector
                                             + UnitHelper.ConvertToFoot(height - i * AnnotationConstaints.TextHeight, AnnotationConstaints.UnitType) * verticalVector;
                    tags.Add(subTag);
                    if (i == 0)
                    {
                        avoidP3_Annotation1 = subTag.TagHeadPosition + skewLength * parallelVector + UnitHelper.ConvertToInch(actualLength, VLUnitType.millimeter) * parallelVector
                                              + UnitHelper.ConvertToFoot(0.5 * AnnotationConstaints.TextHeight, AnnotationConstaints.UnitType) * verticalVector;
                    }
                }
                break;

            case MultiPipeTagLocation.OnLine:
                //添加对应的单管直径标注
                line.GetParameters(TagProperty.线宽度.ToString()).First().Set(UnitHelper.ConvertToFoot(800, AnnotationConstaints.UnitType));
                height        = Convert.ToDouble(line.GetParameters(TagProperty.线高度1.ToString()).First().AsValueString()) + (orderedNodePoints.Count() - 1) * AnnotationConstaints.TextHeight;
                avoidP2_Line2 = avoidP1_Line1 + UnitHelper.ConvertToFoot(height, AnnotationConstaints.UnitType) * verticalVector;
                skewLength    = AnnotationConstaints.SkewLengthForOnLine;
                for (int i = 0; i < pipes.Count(); i++)
                {
                    var subTag       = Document.Create.NewTag(view, pipes[i], false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, startPoint);
                    var text         = subTag.TagText;
                    var textLength   = System.Windows.Forms.TextRenderer.MeasureText(text, AnnotationConstaints.Font).Width;
                    var actualLength = textLength / (textSize * widthScale);
                    subTag.TagHeadPosition = startPoint + skewLength * parallelVector + UnitHelper.ConvertToInch(actualLength, VLUnitType.millimeter) * parallelVector
                                             + UnitHelper.ConvertToFoot(height - i * AnnotationConstaints.TextHeight + 0.5 * AnnotationConstaints.TextHeight, AnnotationConstaints.UnitType) * verticalVector;
                    tags.Add(subTag);
                    if (i == 0)
                    {
                        avoidP3_Annotation1 = subTag.TagHeadPosition + skewLength * parallelVector + UnitHelper.ConvertToInch(actualLength, VLUnitType.millimeter) * parallelVector
                                              + UnitHelper.ConvertToFoot(AnnotationConstaints.TextHeight, AnnotationConstaints.UnitType) * verticalVector;
                    }
                }
                break;

            default:
                return(AnnotationBuildResult.NoLocationType);
            }
            entity.ViewId = view.Id.IntegerValue;
            entity.LineId = line.Id.IntegerValue;
            foreach (var pipe in pipes)
            {
                entity.PipeIds.Add(pipe.Id.IntegerValue);
            }
            foreach (var tag in tags)
            {
                entity.TagIds.Add(tag.Id.IntegerValue);
            }
            entity.StartPoint = startPoint;
            //碰撞检测
            VLTriangle    triangle       = new VLTriangle(avoidP1_Line1, avoidP2_Line2, avoidP3_Annotation1);
            List <Line>   lines          = triangle.GetLines();
            AvoidData     data           = new AvoidData(document, selectedIds, entity, lines, triangle, multipleTagSymbol, parallelVector, rightOfLefts.GetLength(), leftOfRights.GetLength());
            AvoidStrategy strategty      = AvoidStrategy.MoveLeft;
            var           strategyEntity = AvoidStrategyFactory.GetAvoidStrategyEntity(strategty);

            strategyEntity.Data = data;
            while (strategyEntity.CheckCollision(strategyEntity.Data))
            {
                if (strategyEntity.TryAvoid())
                {
                    strategyEntity.Apply(data);
                    break;
                }
                else
                {
                    strategyEntity = strategyEntity.GetNextStratetyEntity();
                }
            }
            return(AnnotationBuildResult.Success);

            #region old
            //if (CheckCollision(document, view, selectedIds, line, lines, triangle, multipleTagSymbol))
            //{
            //    int offsetLength = 10;
            //    XYZ offset = null;
            //    if (rightOfLefts.GetLength() > offsetLength)
            //        offset = parallelVector * offsetLength;
            //    else if (leftOfRights.GetLength() > offsetLength)
            //        offset = -parallelVector * offsetLength;
            //    else
            //        return AnnotationBuildResult.Success;

            //    avoidP1_Line1 += offset;
            //    avoidP2_Line2 += offset;
            //    avoidP3_Annotation1 += offset;
            //    lines = GetLines(avoidP1_Line1, avoidP2_Line2, avoidP3_Annotation1);
            //    triangle = new Triangle(avoidP1_Line1, avoidP2_Line2, avoidP3_Annotation1);
            //    if (!CheckCollision(document, view, selectedIds, line, lines, triangle, multipleTagSymbol))
            //    {
            //        //TODO 偏移处理
            //        Autodesk.Revit.DB.ElementTransformUtils.MoveElement(document, new ElementId(entity.LineId), offset);
            //        foreach (var tagId in entity.TagIds)
            //        {
            //            Autodesk.Revit.DB.ElementTransformUtils.MoveElement(document, new ElementId(tagId), offset);
            //        }
            //    }
            //}
            //return AnnotationBuildResult.Success;
            #endregion
        }
コード例 #4
0
ファイル: AnnotationBuilder.cs プロジェクト: wzfxue/Revit
        private AnnotationBuildResult GenerateMultipleTagSymbol(IEnumerable <ElementId> selectedIds, PipeAnnotationEntity entity, View view)
        {
            XYZ            startPoint = null;
            FamilyInstance line       = null;
            var            pipes      = new List <Pipe>();
            var            tags       = new List <IndependentTag>();

            //管道 获取
            foreach (var selectedId in selectedIds)
            {
                pipes.Add(Document.GetElement(selectedId) as Pipe);
            }
            //平行,垂直 向量
            XYZ parallelVector = null;
            XYZ verticalVector = null;

            parallelVector = ((pipes.First().Location as LocationCurve).Curve as Line).Direction;
            verticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0);
            parallelVector = VLLocationHelper.GetVectorByQuadrant(parallelVector, QuadrantType.OneAndFour, VLCoordinateType.XY);
            verticalVector = VLLocationHelper.GetVectorByQuadrant(verticalVector, QuadrantType.OneAndTwo, VLCoordinateType.XY);
            //平行检测
            if (!CheckParallel(pipes, verticalVector))
            {
                return(AnnotationBuildResult.NotParallel);
            }
            //节点计算
            List <XYZ> nodePoints = GetNodePoints(pipes).OrderByDescending(c => c.Y).ToList();

            if (nodePoints.Count() == 0)
            {
                return(AnnotationBuildResult.NoOverlap);
            }
            //起始点
            startPoint = nodePoints.First();
            //线 创建
            if (!MultipleTagSymbol.IsActive)
            {
                MultipleTagSymbol.Activate();
            }
            line = Document.Create.NewFamilyInstance(startPoint, MultipleTagSymbol, view);
            //线 旋转处理
            if (verticalVector.Y != 1)
            {
                LocationPoint locationPoint = line.Location as LocationPoint;
                if (locationPoint != null)
                {
                    locationPoint.RotateByXY(startPoint, verticalVector);
                }
            }
            //线 参数设置
            UpdateLineParameters(nodePoints, line);
            //标注 创建
            switch (entity.LocationType)
            {
            case MultiPipeTagLocation.OnLineEdge:
                //添加对应的单管直径标注
                line.GetParameters(TagProperty.线宽度.ToString()).First().Set(UnitHelper.ConvertToInch(200, AnnotationConstaints.UnitType));
                var height     = Convert.ToDouble(line.GetParameters(TagProperty.线高度1.ToString()).First().AsValueString()) + (nodePoints.Count() - 1) * AnnotationConstaints.TextHeight;
                var skewLength = AnnotationConstaints.SkewLengthForOffLine;
                for (int i = 0; i < pipes.Count(); i++)
                {
                    var subTag       = Document.Create.NewTag(view, pipes[i], false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, startPoint);
                    var text         = subTag.TagText;
                    var textLength   = System.Windows.Forms.TextRenderer.MeasureText(text, AnnotationConstaints.Font).Width;
                    var actualLength = textLength / (TextSize * WidthScale);
                    subTag.TagHeadPosition = startPoint + skewLength * parallelVector + actualLength / 25.4 * parallelVector
                                             + UnitHelper.ConvertToInch(height - i * AnnotationConstaints.TextHeight, AnnotationConstaints.UnitType) * verticalVector;
                    tags.Add(subTag);
                }
                break;

            case MultiPipeTagLocation.OnLine:
                //添加对应的单管直径标注
                line.GetParameters(TagProperty.线宽度.ToString()).First().Set(UnitHelper.ConvertToInch(800, AnnotationConstaints.UnitType));
                height = Convert.ToDouble(line.GetParameters(TagProperty.线高度1.ToString()).First().AsValueString()) +
                         (nodePoints.Count() - 1) * AnnotationConstaints.TextHeight;
                skewLength = AnnotationConstaints.SkewLengthForOnLine;
                for (int i = 0; i < pipes.Count(); i++)
                {
                    var subTag       = Document.Create.NewTag(view, pipes[i], false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, startPoint);
                    var text         = subTag.TagText;
                    var textLength   = System.Windows.Forms.TextRenderer.MeasureText(text, AnnotationConstaints.Font).Width;
                    var actualLength = textLength / (TextSize * WidthScale);
                    subTag.TagHeadPosition = startPoint + skewLength * parallelVector + actualLength / 25.4 * parallelVector
                                             + UnitHelper.ConvertToInch(height - i * AnnotationConstaints.TextHeight + 0.5 * AnnotationConstaints.TextHeight, AnnotationConstaints.UnitType) * verticalVector;
                    tags.Add(subTag);
                }
                break;

            default:
                return(AnnotationBuildResult.NoLocationType);
            }
            entity.ViewId = view.Id.IntegerValue;
            entity.LineId = line.Id.IntegerValue;
            foreach (var pipe in pipes)
            {
                entity.PipeIds.Add(pipe.Id.IntegerValue);
            }
            foreach (var tag in tags)
            {
                entity.TagIds.Add(tag.Id.IntegerValue);
            }
            entity.StartPoint = startPoint;
            return(AnnotationBuildResult.Success);
        }