Esempio n. 1
0
        /// <summary>
        /// 从需要标注的对象中获取标注的源位置
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static XYZ GetElementLocation(this CSAModel model, Element element)
        {
            var locationCurve = element.Location as LocationCurve;
            var location      = (locationCurve.Curve.GetEndPoint(0) + locationCurve.Curve.GetEndPoint(1)) / 2;

            return(location);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取 CompoundStructure 对象
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static CompoundStructure GetCompoundStructure(this CSAModel model, Element element)
        {
            CompoundStructure compoundStructure = null;

            if (element is Wall)
            {
                compoundStructure = (element as Wall).WallType.GetCompoundStructure();
                model.TargetType  = TargetType.Wall;
            }
            else if (element is Floor)
            {
                compoundStructure = (element as Floor).FloorType.GetCompoundStructure();
                model.TargetType  = TargetType.Floor;
            }
            else if (element is RoofBase)
            {
                compoundStructure = (element as RoofBase).RoofType.GetCompoundStructure();
                model.TargetType  = TargetType.RoofBase;
            }
            else
            {
                throw new NotImplementedException("暂不支持该类型的对象,未能成功获取CompoundStructure");
            }
            return(compoundStructure);
        }
Esempio n. 3
0
 /// <summary>
 /// 线 参数设置
 /// </summary>
 public static void UpdateLineParameters(this CSAModel model, FamilyInstance line, double lineHeight, double lineWidth, double space, int textCount)
 {
     line.GetParameters(TagProperty.线高度1.ToString()).First().Set(lineHeight);
     line.GetParameters(TagProperty.线宽度.ToString()).First().Set(lineWidth);
     line.GetParameters(TagProperty.间距.ToString()).First().Set(space);
     line.GetParameters(TagProperty.文字行数.ToString()).First().Set(textCount);
 }
Esempio n. 4
0
 public void Regenerate(Document doc, CSAModel model, Element target, XYZ offset)
 {
     //不是选取的文本类型 以Text的文本类型为准
     if (model.TextNoteTypeElementId == null)
     {
         model.TextNoteTypeElementId = (doc.GetElement(model.TextNoteIds[0]) as TextNote).TextNoteType.Id;
     }
     Generate(doc, model, target, offset);
 }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
 public void Clear(Document doc, CSAModel model)
 {
     //删除线
     if (model.LineId != null && doc.GetElement(model.LineId) != null)
     {
         doc.Delete(model.LineId);
     }
     //删除标注
     foreach (var item in model.TextNoteIds)
     {
         if (doc.GetElement(item) != null)
         {
             doc.Delete(item);
         }
     }
 }
Esempio n. 7
0
        private static void SetCurveFromLine(CSAModel model, LocationCurve locationCurve)
        {
            XYZ parallelVector = null;
            XYZ verticalVector = null;

            parallelVector = (locationCurve.Curve as Line).Direction;
            verticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0);
            parallelVector = VLLocationHelper.GetVectorByQuadrant(parallelVector, QuadrantType.OneAndFour);
            verticalVector = VLLocationHelper.GetVectorByQuadrant(verticalVector, QuadrantType.OneAndTwo);
            if ((verticalVector.X - 1).IsMiniValue())
            {
                verticalVector = verticalVector.RevertByCoordinateType(VLCoordinateType.XY);
            }
            model.VerticalVector = verticalVector;
            model.ParallelVector = parallelVector;
        }
Esempio n. 8
0
        /// <summary>
        /// 从 CompoundStructure 中获取标注信息
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="compoundStructure"></param>
        /// <returns></returns>
        public static List <string> FetchTextsFromCompoundStructure(this CSAModel model, Document doc, CompoundStructure compoundStructure)
        {
            var layers = compoundStructure.GetLayers();
            var texts  = new List <string>();

            foreach (var layer in layers)
            {
                string name     = "";
                var    material = doc.GetElement(layer.MaterialId);
                if (material == null)
                {
                    name = "<按类别>";
                }
                else
                {
                    name = doc.GetElement(layer.MaterialId).Name;
                }
                texts.Add(UnitHelper.ConvertFromFootTo(layer.Width, VLUnitType.millimeter) + "厚" + name);
            }
            model.Texts = texts;
            return(texts);
        }
Esempio n. 9
0
        public void Regenerate(Document doc, CSAModel model, Element target)
        {
            FamilyInstance line = doc.GetElement(model.LineId) as FamilyInstance;

            CSAContext.Creator.Regenerate(doc, model, target, (line.Location as LocationPoint).Point - model.LineLocation);
        }
Esempio n. 10
0
        //public void Generate(Document doc, CSAModel model, Element element)
        //{
        //    Generate(doc, model, element, new XYZ(0, 0, 0));
        //}

        //private 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;
        //    //主体
        //    model.TargetId = element.Id;

        //    #region old
        //    ////线生成
        //    //model.CalculateLocations(element, offset);//计算内容定位
        //    //List<Line> lines = new List<Line>();
        //    //lines.Add(Line.CreateBound(model.LineStartLocation, model.LineEndLocation));
        //    //foreach (var parallelLinesLocation in model.ParallelLinesLocations)
        //    //    lines.Add(Line.CreateBound(parallelLinesLocation.Start, parallelLinesLocation.End));
        //    //model.LineIds = new List<ElementId>();
        //    //foreach (var line in lines)
        //    //{
        //    //    var lineElement = doc.Create.NewModelCurve(line, VLConstraints.Doc.ActiveView.SketchPlane);
        //    //    model.LineIds.Add(lineElement.Id);
        //    //}
        //    #endregion

        //    //族线
        //    var lineFamilySymbol = VLConstraints.GetMultipleTagSymbol(doc);//获取线标注类型
        //    var 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, 500, 200, AnnotationConstaints.TextHeight, 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);
        //}

        //internal void Regenerate(Document doc, CSAModel model, Element target)
        //{
        //    CSAContext.Creater.Regenerate(doc, model, target, new XYZ(0, 0, 0));
        //}

        //internal void Regenerate(Document doc, CSAModel model, Element target, XYZ offset)
        //{
        //    //不是选取的文本类型 以Text的文本类型为准
        //    if (model.TextNoteTypeElementId == null)
        //        model.TextNoteTypeElementId = (doc.GetElement(model.TextNoteIds[0]) as TextNote).TextNoteType.Id;
        //    //删除线
        //    foreach (var item in model.LineIds)
        //        if (doc.GetElement(item) != null)
        //            doc.Delete(item);
        //    //删除标注
        //    foreach (var item in model.TextNoteIds)
        //        if (doc.GetElement(item) != null)
        //            doc.Delete(item);
        //    Generate(doc, model, target, offset);
        //}

        //internal void Clear(Document doc, CSAModel model)
        //{
        //    //删除线
        //    foreach (var item in model.LineIds)
        //        if (doc.GetElement(item) != null)
        //            doc.Delete(item);
        //    //删除标注
        //    foreach (var item in model.TextNoteIds)
        //        if (doc.GetElement(item) != null)
        //            doc.Delete(item);
        //}
        #endregion


        #region 线族方案
        public void Generate(Document doc, CSAModel model, Element element)
        {
            Generate(doc, model, element, null);
        }
Esempio n. 11
0
        /// <summary>
        /// 获取文字的样式方案
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static List <TextNoteType> GetTextNoteTypes(this CSAModel model)
        {
            var textNoteTypes = new FilteredElementCollector(VLConstraintsForCSA.Doc).OfClass(typeof(TextNoteType)).ToElements().Select(p => p as TextNoteType).Where(c => !c.Name.Contains("明细表")).ToList();

            return(textNoteTypes);
        }
        public void Execute(UpdaterData updateData)
        {
            try
            {
                var document   = updateData.GetDocument();
                var edits      = updateData.GetModifiedElementIds();
                var collection = CSAContext.GetCollection(document);
                if (CSAContext.IsEditing == true)
                {
                    CSAContext.IsEditing = false;
                    return;
                }
                List <int> movedEntities = new List <int>();
                foreach (var changeId in edits)
                {
                    CSAModel model = null;
                    if (VLConstraintsForCSA.Doc == null)
                    {
                        VLConstraintsForCSA.Doc = document;
                    }

                    #region 根据Target重新生成
                    var targetMoved = collection.Data.FirstOrDefault(c => c.TargetId.IntegerValue == changeId.IntegerValue);
                    if (targetMoved != null)
                    {
                        model = targetMoved;
                        if (movedEntities.Contains(model.TargetId.IntegerValue))
                        {
                            continue;
                        }
                        var creater = CSAContext.Creator;
                        var target  = document.GetElement(model.TargetId);//标注主体失效时删除
                        if (target == null)
                        {
                            collection.Data.Remove(model);
                            continue;
                        }
                        CSAContext.Creator.Regenerate(document, model, target, new XYZ(0, 0, 0));
                        movedEntities.Add(model.TargetId.IntegerValue);
                        CSAContext.IsEditing = true;
                    }
                    #endregion

                    #region 根据Text重新生成
                    var textMoved = collection.Data.FirstOrDefault(c => c.TextNoteIds.FirstOrDefault(p => p.IntegerValue == changeId.IntegerValue) != null);
                    if (textMoved != null)
                    {
                        model = textMoved;
                        if (movedEntities.Contains(model.TargetId.IntegerValue))
                        {
                            continue;
                        }
                        var creater = CSAContext.Creator;
                        var target  = document.GetElement(model.TargetId);//标注主体失效时删除
                        if (target == null)
                        {
                            collection.Data.Remove(model);
                            continue;
                        }
                        //文本更改处理
                        var index   = model.TextNoteIds.IndexOf(changeId);
                        var newText = (document.GetElement(changeId) as TextNote).Text;
                        if (model.Texts[index] != newText)
                        {
                            CompoundStructure compoundStructure = null;
                            HostObjAttributes hoster            = null;
                            if (target is Wall)
                            {
                                hoster            = (HostObjAttributes)((target as Wall).WallType);
                                compoundStructure = hoster.GetCompoundStructure();
                            }
                            if (target is Floor)
                            {
                                hoster            = (HostObjAttributes)((target as Floor).FloorType);
                                compoundStructure = hoster.GetCompoundStructure();
                            }
                            if (target is RoofBase)//屋顶有多种类型
                            {
                                hoster            = (HostObjAttributes)((target as RoofBase).RoofType);
                                compoundStructure = hoster.GetCompoundStructure();
                            }
                            if (compoundStructure == null)
                            {
                                throw new NotImplementedException("关联更新失败,未获取有效的CompoundStructure类型");
                            }
                            var    layers  = compoundStructure.GetLayers();
                            string pattern = @"([\d+\.]+)厚(.+)[\r]?";
                            Regex  regex   = new Regex(pattern);
                            var    match   = regex.Match(newText);
                            if (!match.Success)
                            {
                                PMMessageBox.ShowError("关联更新失败,文本不符合规范");
                                return;
                            }
                            var length       = match.Groups[1].Value;
                            var lengthFoot   = UnitHelper.ConvertToFoot(Convert.ToDouble(length), VLUnitType.millimeter);
                            var materialName = match.Groups[2].Value;
                            var material     = new FilteredElementCollector(document).OfClass(typeof(Material))
                                               .FirstOrDefault(c => c.Name == materialName);
                            if (material == null)
                            {
                                PMMessageBox.ShowError("关联更新失败,未获取到对应名称的材质");
                                return;
                            }
                            //更新
                            layers[index].Width      = lengthFoot;
                            layers[index].MaterialId = material.Id;
                            compoundStructure.SetLayers(layers);
                            IDictionary <int, CompoundStructureError> report = null;
                            IDictionary <int, int> errorMap;
                            try
                            {
                                compoundStructure.IsValid(document, out report, out errorMap);
                                hoster.SetCompoundStructure(compoundStructure);
                            }
                            catch (Exception ex)
                            {
                                PMMessageBox.ShowError("材质设置失败,错误详情:" + (report != null ? string.Join(",", report.Select(c => c.Value)) : ""));
                                throw ex;
                            }

                            ////报错This operation is valid only for non-vertically compound structures
                            //layer = layers[index];
                            //layer.MaterialId = material.Id;
                            ////compoundStructure.SetLayer(index, layer);
                        }
                        else
                        {
                            var textNote = document.GetElement(changeId) as TextNote;
                            if (model.TextNoteTypeElementId.IntegerValue != textNote.TextNoteType.Id.IntegerValue)
                            {
                                model.TextNoteTypeElementId = textNote.TextNoteType.Id;
                                CSAContext.Creator.Regenerate(document, model, target, new XYZ(0, 0, 0));
                            }
                            else
                            {
                                //文本偏移处理
                                //var index = model.TextNoteIds.IndexOf(changeId);
                                //var offset = (document.GetElement(changeId) as TextNote).Coord - model.TextLocations[index];
                                //CompoundStructureAnnotationContext.Creater.Regenerate(document, model, target, offset);
                                //CSAContext.IsEditing = true;//移动会导致偏移 从而二次触发
                            }
                        }
                        movedEntities.Add(model.TargetId.IntegerValue);
                    }
                    #endregion

                    #region 根据Line重新生成
                    var lineMoved = collection.Data.FirstOrDefault(c => c.LineId.IntegerValue == changeId.IntegerValue);
                    if (lineMoved != null)
                    {
                        model = lineMoved;
                        if (movedEntities.Contains(model.TargetId.IntegerValue))
                        {
                            continue;
                        }
                        var creater = CSAContext.Creator;
                        var target  = document.GetElement(model.TargetId);
                        if (target == null)
                        {
                            collection.Data.Remove(model);
                            continue;
                        }
                        CSAContext.Creator.Regenerate(document, model, target);
                        movedEntities.Add(model.TargetId.IntegerValue);
                        CSAContext.IsEditing = true;
                    }
                    #endregion
                }
                CSAContext.Save(document);
            }
            catch (Exception ex)
            {
                VLLogHelper.Error(ex);
            }
        }