예제 #1
0
        public void SetTextProperties(Document doc, TextNote txt, TextFormattingContainer format)
        {
            FormattedText tFormatted = txt.GetFormattedText();

            TextNoteType type = doc.GetElement(new ElementId(format.textNoteTypeID)) as TextNoteType;

            txt.TextNoteType = type;

            Debug("textNoteAllCaps Paint " + format.textNoteAllCapsStatus.ToString());

            if (format.textNoteAllCapsStatus)
            {
                string currentPlainText = tFormatted.GetPlainText();
                Debug("text formatted Plain Text Paint " + currentPlainText);
                string upperCase = currentPlainText.ToUpper();
                tFormatted.SetPlainText(upperCase);
                Debug("text formatted Plain Text Updates Paint " + tFormatted.GetPlainText().ToString());
            }

            tFormatted.SetBoldStatus(format.textNoteBoldStatus != FormatStatus.None);
            Debug("textNoteBoldStatus Paint " + format.textNoteBoldStatus.ToString());
            Debug("get textNoteBoldStatus Paint " + tFormatted.GetBoldStatus().ToString());

            tFormatted.SetItalicStatus(format.textNoteItalicsStatus != FormatStatus.None);
            Debug("textNoteItalicsStatus Paint " + format.textNoteItalicsStatus.ToString());
            Debug("get textNoteItalicsStatus Paint " + tFormatted.GetItalicStatus().ToString());

            tFormatted.SetUnderlineStatus(format.textNoteUnderlineStatus != FormatStatus.None);
            Debug("textNoteUnderlineStatus Paint " + format.textNoteUnderlineStatus.ToString());
            Debug("get textNoteUnderlineStatus Paint " + tFormatted.GetUnderlineStatus().ToString());

            txt.SetFormattedText(tFormatted);
        }
예제 #2
0
파일: Util.cs 프로젝트: wclwksn/revitToObj
        void RevitTextColorFromSystemColorUsageExample()
        {
            TextNoteType tnt = null;

            // Set Revit text colour from system colour

            int color = GetRevitTextColorFromSystemColor(System.Drawing.Color.Wheat);

            tnt.get_Parameter(BuiltInParameter.LINE_COLOR).Set(color);
        }
예제 #3
0
        public void CreteaTextnode(Document doc, string value, TextNoteType textNoteType)
        {
            ElementId       defaultTextTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);
            TextNoteOptions opts = new TextNoteOptions(defaultTextTypeId);

            opts.TypeId = textNoteType.Id;
            XYZ      point    = sel.PickPoint();
            PLane3D  pLane3D  = new PLane3D(doc.ActiveView.Origin, doc.ActiveView.ViewDirection);
            var      P        = pLane3D.ProjectPointOnPlane(point);
            TextNote textNote = TextNote.Create(doc, doc.ActiveView.Id, P, value, opts);
        }
 private void btn_OK_Click(object sender, RoutedEventArgs e)
 {
     textnotetype = cbb_typetext.SelectedItem as TextNoteType;
     try
     {
         _data.Setting.TypeText = (cbb_typetext.SelectedItem as TextNoteType).Name;
         _data.Setting.SaveSetting();
     }
     catch { _data.Setting.SaveSetting(); }
     Close();
 }
예제 #5
0
        /// <summary>
        /// 整合表头信息
        /// </summary>
        /// <param name="noteType">贯穿信息(递归过程中国年保持不变)</param>
        /// <param name="rowCount">剩余的行数</param>
        /// <param name="nodes"></param>
        /// <param name="rowIndex"></param>
        /// <param name="columnIndex"></param>
        /// <returns></returns>
        private List <TCell> GetHeaderCells(TextNoteType noteType, int rowCount, List <TNode> nodes, int rowIndex,
                                            int columnIndex)
        {
            List <TCell> cells         = new List <TCell>();
            View         currentView   = this.DrawView;
            Document     doc           = currentView.Document;
            int          currentColumn = columnIndex;
            int          currentRow    = rowIndex;

            for (int k = 0; k < nodes.Count; k++)
            {
                TNode currentNode = nodes[k];
                int   columnSpan  = currentNode.LeafCount;

                int rowUnit = rowCount / currentNode.Depth; //改树形分支剩余的行数
                int rowSpan = rowUnit;

                string        text   = currentNode.Name;
                var           leaves = currentNode.GetLeaves();
                ColumnSetting column = leaves[0].Tag as ColumnSetting;
                if (column != null)
                {
                    var data = new TextNoteData(currentView, XYZ.Zero, XYZ.BasisX, XYZ.BasisY,
                                                BaseDataSupply.ConvertToTextNodeAlgin(column.TextAlignment), text, noteType);
                    TextNote tn    = data.Create(currentView.Document);
                    TCell    tCell = null;
                    cells.Add(tCell = new TCell()
                    {
                        RowIndex    = currentRow,
                        ColumnIndex = currentColumn,
                        RowSpan     = rowSpan,
                        ColumnSpan  = columnSpan,
                        Value       = tn
                    });

                    //if (isAutoFit)
                    //{
                    double tempWidth = doc.ComputeTextNoteWidth(currentView, text, noteType).FromApi() * 0.7;
                    tCell.Tag = tempWidth;
                    //    columnsWidth[k] = columnsWidth[k].IsThanEq(tempWidth) ? columnsWidth[k] : tempWidth;
                    //}
                }

                if (!currentNode.IsLeaf)
                {
                    cells.AddRange(GetHeaderCells(noteType, rowCount - rowSpan, currentNode.Nodes, currentRow + rowSpan,
                                                  currentColumn));
                }
                currentColumn = currentColumn + columnSpan;
            }
            return(cells);
        }
예제 #6
0
        Stream(ArrayList data, TextElementType textAttr)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(TextElementType)));

            // no data at this level

            TextNoteType textNoteAttr = textAttr as TextNoteType;

            if (textNoteAttr != null)
            {
                Stream(data, textNoteAttr);
                return;
            }
        }
예제 #7
0
            public void AddTextNoteType(
                TextNoteType tnt,
                bool updated)
            {
                if (null == TextNoteTypeResults)
                {
                    TextNoteTypeResults
                        = new List <TextNoteTypeResult>();
                }
                TextNoteTypeResult r = new TextNoteTypeResult();

                r.Name    = tnt.Name;
                r.Updated = updated;
                TextNoteTypeResults.Add(r);
            }
예제 #8
0
        //首先判断目标字体类型在不在,如果不存在,则创建字体类型
        public bool isCreatTextNoteType(Document doc, string str)
        {
            IList <Element> textNoteTypes = (new FilteredElementCollector(doc)).OfClass(typeof(TextNoteType)).ToElements();
            IList <string>  tntNames      = getIcollecionNames(doc, textNoteTypes);
            string          tntfield      = str;//目标文字注释类型

            if (!tntNames.Contains(tntfield))
            {
                //创建该字体名称
                ElementId    defaultTextTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);//创建标准字体
                TextNoteType textNoteType      = doc.GetElement(defaultTextTypeId) as TextNoteType;
                TextNoteType newtnType;
                using (Transaction createNewtnType = new Transaction(doc))   //事务结束
                {
                    createNewtnType.Start("createNewtnType");                //开启事务
                    newtnType = textNoteType.Duplicate(str) as TextNoteType; //移动文字至中心位置
                    createNewtnType.Commit();                                //提交事务
                }
                //创建两个事务,否则前者不存在文档中
                using (Transaction modifyNewtnType = new Transaction(doc)) //事务结束
                {
                    modifyNewtnType.Start("modifyNewtnType");              //开启事务

                    //图形
                    newtnType.get_Parameter(BuiltInParameter.LINE_COLOR).Set(0);                               //颜色
                    newtnType.get_Parameter(BuiltInParameter.LINE_PEN).SetValueString("1");                    //线宽
                    newtnType.get_Parameter(BuiltInParameter.TEXT_BACKGROUND).Set(1);;                         //背景
                    newtnType.get_Parameter(BuiltInParameter.TEXT_BOX_VISIBILITY).SetValueString("否");         //显示边框
                    newtnType.get_Parameter(BuiltInParameter.LEADER_OFFSET_SHEET).SetValueString("0.0000 mm"); //引线/边界偏移值
                    newtnType.get_Parameter(BuiltInParameter.LEADER_ARROWHEAD).SetValueString("无");            //引线箭头---无效设置
                    //文字
                    newtnType.get_Parameter(BuiltInParameter.TEXT_FONT).Set("Arial Narrow");                   //文字字体
                    newtnType.get_Parameter(BuiltInParameter.TEXT_SIZE).SetValueString("2.0000 mm");           //文字大小
                    newtnType.get_Parameter(BuiltInParameter.TEXT_TAB_SIZE).SetValueString("8.0000 mm");       //标签尺寸
                    newtnType.get_Parameter(BuiltInParameter.TEXT_STYLE_BOLD).Set(0);                          //粗体
                    newtnType.get_Parameter(BuiltInParameter.TEXT_STYLE_ITALIC).Set(1);                        //斜体
                    newtnType.get_Parameter(BuiltInParameter.TEXT_STYLE_UNDERLINE).Set(0);;                    //下划线
                    newtnType.get_Parameter(BuiltInParameter.TEXT_WIDTH_SCALE).SetValueString("1");            //宽度系数

                    modifyNewtnType.Commit();                                                                  //提交事务
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #9
0
 private void btOk_Click(object sender, RoutedEventArgs e)
 {
     if (Checkvalue())
     {
         val                    = txt_val.Text;
         tru                    = txt_tru.Text;
         Suffix                 = txt_suffix.Text;
         Prefix                 = txt_Prefix.Text;
         TextNoteType           = cbb_textNotes.SelectedItem as TextNoteType;
         check                  = true;
         _data.Setting.Prefix   = Prefix;
         _data.Setting.Suffix   = Suffix;
         _data.Setting.cong     = val;
         _data.Setting.tru      = tru;
         _data.Setting.Textnote = TextNoteType.Name;
         _data.Setting.SaveSetting();
         Close();
     }
 }
예제 #10
0
        public static void EditTextStyles(UIDocument uiDoc)
        {
            Document         currentDoc      = uiDoc.Document;
            Selection        sel             = uiDoc.Selection;
            ISelectionFilter selectionFilter = new TextSelectionFilter();

            Reference ChangedObject  = sel.PickObject(ObjectType.Element, selectionFilter);
            TextNote  ChangedElement = currentDoc.GetElement(ChangedObject.ElementId) as TextNote;

            Reference    NewObject  = sel.PickObject(ObjectType.Element, selectionFilter);
            TextNote     NewElement = currentDoc.GetElement(NewObject.ElementId) as TextNote;
            TextNoteType type       = NewElement.TextNoteType;

            TextNoteType oldType = ChangedElement.TextNoteType;

            FilteredElementCollector TextCollector = new FilteredElementCollector(currentDoc);
            List <ElementId>         Notes         = TextCollector.OfCategory(BuiltInCategory.OST_TextNotes).ToElementIds().ToList();

            foreach (ElementId EID in Notes)
            {
                TextNote TN = currentDoc.GetElement(EID) as TextNote;
                if (TN.TextNoteType.Name == oldType.Name)
                {
                    if (TN.GroupId == ElementId.InvalidElementId)
                    {
                        TN.TextNoteType = type;
                    }
                    else
                    {
                        Group group = currentDoc.GetElement(TN.GroupId) as Group;
                    }
                }
            }

            currentDoc.Delete(oldType.Id);
        }
예제 #11
0
        public void CreateTextNote(Document doc, Dictionary <string, List <string> > dic, TextNoteType textNoteType, Selection sel)
        {
            var point = sel.PickPoint();

            if (doc.ActiveView.IsAssemblyView)
            {
                XYZ    direction    = doc.ActiveView.UpDirection;
                string assemblyname = (doc.GetElement(doc.ActiveView.AssociatedAssemblyInstanceId) as AssemblyInstance).Name;
                var    list         = dic[assemblyname].ToList();
                list.Sort();
                Sortliststring(list);
                if (direction.X != 0)
                {
                    using (Transaction tran = new Transaction(doc, "Create new type text"))
                    {
                        XYZ xYZ = XYZ.Zero;
                        tran.Start();
                        for (int i = 0, j = 0; i < list.Count; i++, j += 1)
                        {
                            if (i == 0)
                            {
                                var p2 = new XYZ(point.X, point.Y, point.Z + 0.016);
                                xYZ = p2;
                                TextNote textNote = TextNote.Create(doc, doc.ActiveView.Id, xYZ, list[i], textNoteType.Id);
                            }
                            else
                            {
                                var p2 = new XYZ(xYZ.X, xYZ.Y, xYZ.Z + 0.016);
                                xYZ = p2;
                                TextNote textNote = TextNote.Create(doc, doc.ActiveView.Id, xYZ, list[i], textNoteType.Id);
                            }
                        }
                        tran.Commit();
                    }
                }
                if (direction.Y != 0)
                {
                    using (Transaction tran = new Transaction(doc, "Create new type text"))
                    {
                        XYZ xYZ = XYZ.Zero;
                        tran.Start();
                        for (int i = 0, j = 0; i < list.Count; i++, j += 1)
                        {
                            if (i == 0)
                            {
                                var p2 = new XYZ(point.X, point.Y + 0.016, point.Z);
                                xYZ = p2;
                                TextNote textNote = TextNote.Create(doc, doc.ActiveView.Id, xYZ, list[i], textNoteType.Id);
                            }
                            else
                            {
                                var p2 = new XYZ(xYZ.X, xYZ.Y + 0.016, xYZ.Z);
                                xYZ = p2;
                                TextNote textNote = TextNote.Create(doc, doc.ActiveView.Id, xYZ, list[i], textNoteType.Id);
                            }
                        }
                        tran.Commit();
                    }
                }
                if (direction.Z != 0)
                {
                    using (Transaction tran = new Transaction(doc, "Create new type text"))
                    {
                        XYZ xYZ = XYZ.Zero;
                        tran.Start();
                        for (int i = 0, j = 0; i < list.Count; i++, j += 1)
                        {
                            if (i == 0)
                            {
                                var p2 = new XYZ(point.X, point.Y, point.Z + 0.016);
                                xYZ = p2;
                                TextNote textNote = TextNote.Create(doc, doc.ActiveView.Id, xYZ, list[i], textNoteType.Id);
                            }
                            else
                            {
                                var p2 = new XYZ(xYZ.X, xYZ.Y, xYZ.Z + 0.016);
                                xYZ = p2;
                                TextNote textNote = TextNote.Create(doc, doc.ActiveView.Id, xYZ, list[i], textNoteType.Id);
                            }
                        }
                        tran.Commit();
                    }
                }
            }
        }
예제 #12
0
        private void Stream(ArrayList data, TextNoteType textAttr)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(TextNoteType)));

             // no data at this level
        }
        private void ImportAutoCADFile(int id)
        {
            if (uidoc.Document != null)
            {
                preCurveElementIds.Clear();
                FilteredElementCollector preElementDocFilter = new FilteredElementCollector(doc);
                if (preElementDocFilter != null)
                {
                    FilteredElementIdIterator preElementsIdsIterator = preElementDocFilter.OfClass(typeof(CurveElement)).GetElementIdIterator();
                    while (preElementsIdsIterator.MoveNext())
                    {
                        preCurveElementIds.Add(preElementsIdsIterator.Current);
                    }
                }

                preTextNotesIds.Clear();
                FilteredElementCollector preTextNoteDocFilter = new FilteredElementCollector(doc);
                if (preTextNoteDocFilter != null)
                {
                    FilteredElementIdIterator preElementsIdsIterator = preTextNoteDocFilter.OfClass(typeof(TextNote)).GetElementIdIterator();
                    while (preElementsIdsIterator.MoveNext())
                    {
                        preTextNotesIds.Add(preElementsIdsIterator.Current);
                    }
                }

                preTextNoteTypesIds.Clear();
                FilteredElementCollector preTextNoteTypeDocFilter = new FilteredElementCollector(doc);
                if (preTextNoteTypeDocFilter != null)
                {
                    FilteredElementIdIterator preElementsIdsIterator = preTextNoteTypeDocFilter.OfClass(typeof(TextNoteType)).GetElementIdIterator();
                    while (preElementsIdsIterator.MoveNext())
                    {
                        preTextNoteTypesIds.Add(preElementsIdsIterator.Current);

                        TextNoteType preTextNodeType = doc.GetElement(preElementsIdsIterator.Current) as TextNoteType;
                        if (preTextNodeType != null)
                        {
                            this.revitTextNoteTypesDict.Add(preTextNodeType.Name, preTextNodeType);
                        }
                    }
                }

                Category preLinesStyles = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);
                foreach (Category preLineCategory in preLinesStyles.SubCategories)
                {
                    preLineCategoriesIds.Add(preLineCategory.Id);
                    this.revitCategoriesDict.Add(preLineCategory.Name, preLineCategory);
                }


                preGraphycStyleIds.Clear();
                FilteredElementCollector preGraphycsStyleDocFilter = new FilteredElementCollector(doc);
                if (preGraphycsStyleDocFilter != null)
                {
                    FilteredElementIdIterator preElementsIdsIterator = preGraphycsStyleDocFilter.OfClass(typeof(GraphicsStyle)).GetElementIdIterator();
                    while (preElementsIdsIterator.MoveNext())
                    {
                        GraphicsStyle preGraphicsStyle = doc.GetElement(preElementsIdsIterator.Current) as GraphicsStyle;
                        if (preGraphicsStyle != null)
                        {
                            if (preLineCategoriesIds.Contains(preGraphicsStyle.GraphicsStyleCategory.Id))
                            {
                                preGraphycStyleIds.Add(preElementsIdsIterator.Current);

                                revitLineStylesDict.Add(preGraphicsStyle.Name, preGraphicsStyle);
                            }
                        }
                    }
                }

                #region
                deleteImportInstances();
                DWGImportOptions importOptions = new DWGImportOptions();
                importOptions.OrientToView = true;
                importOptions.Placement    = ImportPlacement.Origin;
                doc.Import(fileName, importOptions, importView, out importInstanceId);
                if (importInstanceId != null)
                {
                    explodeImportInstance();
                }
                uidoc.RefreshActiveView();


                curCurveElementIds.Clear();
                FilteredElementCollector curElementDocFilter = new FilteredElementCollector(doc);
                if (curElementDocFilter != null)
                {
                    FilteredElementIdIterator curElementsIdsIterator = curElementDocFilter.OfClass(typeof(CurveElement)).GetElementIdIterator();
                    while (curElementsIdsIterator.MoveNext())
                    {
                        curCurveElementIds.Add(curElementsIdsIterator.Current);
                    }
                }

                curTextNotesIds.Clear();
                FilteredElementCollector curDocFilter = new FilteredElementCollector(doc);
                if (curDocFilter != null)
                {
                    FilteredElementIdIterator curElementsIdsIterator = curDocFilter.OfClass(typeof(TextNote)).GetElementIdIterator();
                    while (curElementsIdsIterator.MoveNext())
                    {
                        curTextNotesIds.Add(curElementsIdsIterator.Current);
                    }
                }

                curTextNoteTypesIds.Clear();
                FilteredElementCollector curTextNoteTypeDocFilter = new FilteredElementCollector(doc);
                if (curTextNoteTypeDocFilter != null)
                {
                    FilteredElementIdIterator curElementsIdsIterator = curTextNoteTypeDocFilter.OfClass(typeof(TextNoteType)).GetElementIdIterator();
                    while (curElementsIdsIterator.MoveNext())
                    {
                        curTextNoteTypesIds.Add(curElementsIdsIterator.Current);
                    }
                }

                Category curLinesStyles = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);
                foreach (Category curLineCategory in curLinesStyles.SubCategories)
                {
                    curLineCategoriesIds.Add(curLineCategory.Id);
                }


                curGraphycStyleIds.Clear();
                FilteredElementCollector curGraphycsStyleDocFilter = new FilteredElementCollector(doc);
                if (curGraphycsStyleDocFilter != null)
                {
                    FilteredElementIdIterator curElementsIdsIterator = curGraphycsStyleDocFilter.OfClass(typeof(GraphicsStyle)).GetElementIdIterator();
                    while (curElementsIdsIterator.MoveNext())
                    {
                        GraphicsStyle curGraphicsStyle = doc.GetElement(curElementsIdsIterator.Current) as GraphicsStyle;
                        if (curGraphicsStyle != null)
                        {
                            if (curLineCategoriesIds.Contains(curGraphicsStyle.GraphicsStyleCategory.Id))
                            {
                                curGraphycStyleIds.Add(curElementsIdsIterator.Current);
                            }
                        }
                    }
                }
                #endregion

                difCurveElementIds.Clear();
                difCurveElementIds.UnionWith(curCurveElementIds);
                difCurveElementIds.ExceptWith(preCurveElementIds);

                difTextNotesIds.Clear();
                difTextNotesIds.UnionWith(curTextNotesIds);
                difTextNotesIds.ExceptWith(preTextNotesIds);

                difTextNoteTypesIds.Clear();
                difTextNoteTypesIds.UnionWith(curTextNoteTypesIds);
                difTextNoteTypesIds.ExceptWith(preTextNoteTypesIds);

                difLineCategoriesIds.Clear();
                difLineCategoriesIds.UnionWith(curLineCategoriesIds);
                difLineCategoriesIds.ExceptWith(preLineCategoriesIds);

                difGraphycStyleIds.Clear();
                difGraphycStyleIds.UnionWith(curGraphycStyleIds);
                difGraphycStyleIds.ExceptWith(preGraphycStyleIds);


                foreach (Category curLineCategory in curLinesStyles.SubCategories)
                {
                    if (difLineCategoriesIds.Contains(curLineCategory.Id))
                    {
                        Color curColor = curLineCategory.LineColor;
                        Tuple <byte, byte, byte> curColorTuple = new Tuple <byte, byte, byte>(curColor.Red, curColor.Green, curColor.Blue);

                        if (autocadColorLineStylesDict.ContainsKey(curColorTuple))
                        {
                            autocadColorLineStylesDict[curColorTuple].Add(curLineCategory);
                        }
                        else
                        {
                            List <Category> norList = new List <Category>();
                            norList.Add(curLineCategory);
                            autocadColorLineStylesDict.Add(curColorTuple, norList);
                        }
                    }
                }

                #region
                Autodesk.Revit.DB.Options geoOptions = uiapp.Application.Create.NewGeometryOptions();
                geoOptions.ComputeReferences = true;
                FilteredElementCollector curElementsDocFilter = new FilteredElementCollector(doc);
                if (curElementsDocFilter != null)
                {
                    FilteredElementIdIterator curElementsIdsIterator = curElementsDocFilter.WhereElementIsNotElementType().GetElementIdIterator();
                    while (curElementsIdsIterator.MoveNext())
                    {
                        ElementId curElementId = curElementsIdsIterator.Current;
                        if (curElementId != null)
                        {
                            Element curElement = doc.GetElement(curElementId);
                            if (curElement != null)
                            {
                                GeometryElement curGeometryElement = curElement.get_Geometry(geoOptions);
                                if (curGeometryElement != null)
                                {
                                    foreach (GeometryObject curGeometryObject in curGeometryElement)
                                    {
                                        ElementId curGraphicsStyleId = curGeometryObject.GraphicsStyleId;
                                        if (curGraphicsStyleId != null)
                                        {
                                            GraphicsStyle curGraphicsStyle = doc.GetElement(curGraphicsStyleId) as GraphicsStyle;
                                            if (curGraphicsStyle != null)
                                            {
                                                string curGraphicsStyleName = curGraphicsStyle.Name;

                                                Category curGraphicsStyleCategory = curGraphicsStyle.GraphicsStyleCategory;
                                                if (curGraphicsStyleCategory != null)
                                                {
                                                    string curGraphicsStyleCategoryName = curGraphicsStyleCategory.Name;

                                                    if (this.curGraphicsStylesNamesCount.ContainsKey(curGraphicsStyleCategoryName))
                                                    {
                                                        this.curGraphicsStylesNamesCount[curGraphicsStyleCategoryName]++;
                                                    }
                                                    else
                                                    {
                                                        this.curGraphicsStylesNamesCount.Add(curGraphicsStyleCategoryName, 1);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion


                CadDetailConverterOutputForm outputForm = new CadDetailConverterOutputForm(this);
                outputForm.ShowDialog();

                uiapp.Idling += uiapp_Idling;
            }
        }
예제 #14
0
파일: TextFonts.cs 프로젝트: giobel/ReviTab
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            try
            {
                XYZ origin = uidoc.Selection.PickPoint("Select insertion point");

                double Yoffset = origin.Y;

                double width = 0.5; //feet

                TextNoteOptions options = new TextNoteOptions();
                options.HorizontalAlignment = HorizontalTextAlignment.Left;
                options.TypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);

                ICollection <Element> textNoteTypes = new FilteredElementCollector(doc).OfClass(typeof(TextNoteType)).OrderBy(x => x.Name).ToList();

                ElementClassFilter filter = new ElementClassFilter(typeof(TextNote));

                using (Transaction t = new Transaction(doc, "Place text"))
                {
                    t.Start();

                    foreach (Element e in textNoteTypes)
                    {
                        TextNoteType textNoteElement = doc.GetElement(e.Id) as TextNoteType;

                        FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType();

                        var query = from element in collector
                                    where element.GetTypeId() == e.Id
                                    select element;

                        double fontSize = Convert.ToDouble(textNoteElement.LookupParameter("Text Size").AsValueString().Replace("mm", "")) / 304.8;

                        double borderOffset = textNoteElement.LookupParameter("Leader/Border Offset").AsDouble();

                        XYZ offsetPoint = new XYZ(origin.X, Yoffset, 0);

                        TextNote note = TextNote.Create(doc, doc.ActiveView.Id, offsetPoint, width, textNoteElement.Name + " count: " + query.Count().ToString(), options);

                        note.ChangeTypeId(e.Id);

                        Yoffset -= (fontSize + borderOffset * 2 + 0.03);
                    }

                    t.Commit();
                }
                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Error", ex.Message);
                return(Result.Failed);
            }
        }
예제 #15
0
        Stream(ArrayList data, TextNoteType textAttr)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(TextNoteType)));

            // no data at this level
        }
예제 #16
0
        public void Draw(TSheet sheet)
        {
            if (Items == null || Items.Count == 0 || DrawView == null || Location == null)
            {
                return;
            }
            //获取列信息
            var columns         = sheet.ColumnSettings.OrderBy(s => s.Index).Where(s => s.IsShow).ToList();
            int showColumnCount = columns.Count;

            if (showColumnCount == 0)
            {
                return;
            }

            View   currentView = DrawView;
            int    scale       = DrawView.Scale;
            string fontString  = sheet.FontString;
            bool   isBottom    = sheet.IsBottom;

            TextNoteType ntypeSheet   = currentView.Document.GetTextNodeType(fontString, sheet.TitleWordSetting.WordHeight, 0.7);
            TextNoteType ntypeHead    = currentView.Document.GetTextNodeType(fontString, sheet.SheetHeaderWordSetting.WordHeight, 0.7);
            TextNoteType ntypeContent = currentView.Document.GetTextNodeType(fontString, sheet.SheetRowWordSetting.WordHeight, 0.7);

            #region 分页
            List <List <object> > pages = new List <List <object> >();
            if (sheet.IsUsePagination && sheet.RowCountPrePage > 1)
            {
                int           count       = 0;
                List <object> pageElement = new List <object>();
                int           groupCount  = this.Items.Count;
                for (int i = 0; i < groupCount; i++)
                {
                    count++;

                    if (count < sheet.RowCountPrePage && i != groupCount - 1)
                    {
                        pageElement.Add(this.Items[i]);
                    }
                    else if (count == sheet.RowCountPrePage || i == groupCount - 1)//相等
                    {
                        pageElement.Add(this.Items[i]);
                        pages.Add(pageElement);
                        pageElement = new List <object>();
                        count       = 0;
                    }
                }
            }
            else
            {
                pages.Add(this.Items);
            }
            #endregion
            #region 处理表头树
            var          tuples      = columns.Select(c => new Tuple <string, object>(c.Display.ToString(), c)).ToList();
            List <TNode> headerNotes = TreePathParse.Parse(tuples);
            int          headerRows  = headerNotes.Max(h => h.Depth);
            #endregion

            #region 写数据
            Document doc = currentView.Document;
            Dictionary <int, double> columnsWidth = null;
            bool isAutoFit           = sheet.AutoFit;
            int  refCount            = TSheet.GetRowCount(this.Items[0]);//一个元素对应多少行revit表格
            List <RevitTalbe> tables = new List <RevitTalbe>();
            //每一页重新编号
            //int num = 0;
            foreach (var page in pages)
            {
                //num =1;
                if (isAutoFit)
                {
                    columnsWidth = new Dictionary <int, double>();
                    for (int i = 0; i < showColumnCount; i++)
                    {
                        columnsWidth[i] = 0;
                    }
                }
                int currentRowCount = page.Count * refCount + headerRows;
                if (sheet.IsShowTitleName)
                {
                    currentRowCount++;
                }
                RevitTalbe table               = new RevitTalbe(currentRowCount, showColumnCount);
                int        currentRowIndex     = 0;
                Func <int> currentRowIndexMove = () => currentRowIndex++;
                if (isBottom)
                {
                    currentRowIndex     = currentRowCount - 1;
                    currentRowIndexMove = () => currentRowIndex--;
                }

                #region 表格维护

                {
                    if (sheet.IsShowTitleName)
                    {
                        var      data = new TextNoteData(currentView, XYZ.Zero, XYZ.BasisX, XYZ.BasisY, TextAlignFlags.TEF_ALIGN_CENTER, sheet.TitleName, ntypeSheet);
                        TextNote tn   = data.Create(currentView.Document);
                        table.SetValueMerge(currentRowIndex, 0, currentRowIndex, showColumnCount - 1, tn);
                        table.Rows[currentRowIndex].Height = sheet.TitleWordSetting.RowHeight * scale;
                        currentRowIndexMove();
                    }
                }

                #endregion

                #region 表头处理

                {
                    List <TCell> cells = GetHeaderCells(ntypeHead, headerRows, headerNotes, 0, 0);
                    int          k     = 0;
                    foreach (TCell cell in cells)
                    {
                        table.SetValueMerge(cell.RowIndex, cell.ColumnIndex, cell.RowIndex + cell.RowSpan - 1, cell.ColumnIndex + cell.ColumnSpan - 1, cell.Value);
                        if (isAutoFit && cell.ColumnSpan == 1)
                        {
                            double tempWidth = Convert.ToDouble(cell.Tag);
                            columnsWidth[k] = columnsWidth[k].IsThanEq(tempWidth) ? columnsWidth[k] : tempWidth;
                            k++;
                        }
                    }
                    for (int i = 0; i < headerRows; i++)
                    {
                        table.Rows[currentRowIndex].Height = sheet.SheetHeaderWordSetting.RowHeight * scale;
                        currentRowIndexMove();
                    }
                }
                #endregion

                #region 表格处理

                {
                    List <Dictionary <string, object> > tempPage = TSheet.GetSheetData(page);
                    for (int no = 0; no < tempPage.Count; no++)
                    {
                        var item = tempPage[no];
                        #region 自动编号
                        if (sheet.AutoBuildNo && !string.IsNullOrEmpty(sheet.NoColumnName) && no % refCount == 0)
                        {
                            item[sheet.NoColumnName] = no / refCount + 1;
                        }
                        #endregion
                        for (int i = 0; i < showColumnCount; i++)
                        {
                            //图例暂时不处理
                            object tempValue = item.GetValue(columns[i].Name);

                            string   text = tempValue == null?"":item.GetValue(columns[i].Name).ToString();
                            var      data = new TextNoteData(currentView, XYZ.Zero, XYZ.BasisX, XYZ.BasisY, BaseDataSupply.ConvertToTextNodeAlgin(columns[i].TextAlignment), text, ntypeContent);
                            TextNote tn   = data.Create(currentView.Document);

                            table.SetValue(currentRowIndex, i, tn);
                            if (isAutoFit)
                            {
                                double tempWidth = doc.ComputeTextNoteWidth(currentView, text, ntypeContent).FromApi() * 0.7;
                                columnsWidth[i] = columnsWidth[i].IsThanEq(tempWidth) ? columnsWidth[i] : tempWidth;
                            }
                        }
                        table.Rows[currentRowIndex].Height = sheet.SheetRowWordSetting.RowHeight * scale;
                        currentRowIndexMove();
                    }
                }
                #endregion
                #region 样式设置

                if (isAutoFit)
                {
                    //自适应列宽
                    foreach (var d in columnsWidth)
                    {
                        table.Columns[d.Key].Width = d.Value * scale;
                    }
                }
                else
                {
                    for (int i = 0; i < Math.Min(table.Columns.Count, columns.Count); i++)
                    {
                        table.Columns[i].Width = columns[i].ColomnWidth * scale;
                    }
                }
                tables.Add(table);
                #endregion
            }
            #endregion

            #region 放置表格
            List <XYZ> locations       = new List <XYZ>();
            double     sapce           = 2000d;// 2000d.ToApi();
            XYZ        baseLocation    = Location;
            XYZ        currentLocation = baseLocation.AddX(0);
            for (int i = 0; i < tables.Count; i++)
            {
                if (sheet.Arrange == ContentArragne.Landscape)
                {
                    if (i != 0)
                    {
                        double tempWidth = tables[i - 1].Columns.Sum(c => c.Width);
                        tempWidth = tempWidth + sapce;
                        locations.Add(currentLocation = currentLocation.AddX(tempWidth.ToApi()));
                    }
                    else
                    {
                        locations.Add(currentLocation = currentLocation.AddX(0));
                    }
                }
                else
                {
                    if (i != 0)
                    {
                        double tempHeight = tables[i - 1].Rows.Sum(r => r.Height);
                        tempHeight = tempHeight + sapce;
                        locations.Add(currentLocation = currentLocation.OffsetPoint(-XYZ.BasisY, tempHeight.ToApi()));
                    }
                    else
                    {
                        //double tempHeight = tables[i].Rows.Sum(r => r.Height);
                        //tempHeight = tempHeight;
                        //locations.Add(currentLocation=currentLocation.OffsetPoint(-XYZ.BasisY, tempHeight.ToApi()));
                        locations.Add(currentLocation = currentLocation.AddY(0));
                    }
                }
            }
            for (int i = 0; i < tables.Count; i++)
            {
                var revitTalbe = tables[i];
                revitTalbe.DrawTable(locations[i], currentView);
            }
            #endregion
        }
예제 #17
0
        /// <summary>
        /// Set analysis display style to switch off grid lines
        /// and use greyscale values in active view.
        /// </summary>
        void SetAnalysisDisplayStyle(Document doc)
        {
            AnalysisDisplayStyle analysisDisplayStyle;

            const string styleName
                = "Revit Webcam Display Style";

            // extract existing display styles with specific name

            FilteredElementCollector a
                = new FilteredElementCollector(doc);

            IList <Element> elements = a
                                       .OfClass(typeof(AnalysisDisplayStyle))
                                       .Where(x => x.Name.Equals(styleName))
                                       .Cast <Element>()
                                       .ToList();

            if (0 < elements.Count)
            {
                // use the existing display style

                analysisDisplayStyle = elements[0]
                                       as AnalysisDisplayStyle;
            }
            else
            {
                // create new display style:

                // coloured surface settings:

                AnalysisDisplayColoredSurfaceSettings
                    coloredSurfaceSettings
                    = new AnalysisDisplayColoredSurfaceSettings();

                coloredSurfaceSettings.ShowGridLines = false;

                // color settings:

                AnalysisDisplayColorSettings colorSettings
                    = new AnalysisDisplayColorSettings();

                colorSettings.MaxColor = new Color(255, 255, 255);
                colorSettings.MinColor = new Color(0, 0, 0);

                // legend settings:

                AnalysisDisplayLegendSettings legendSettings
                    = new AnalysisDisplayLegendSettings();

                legendSettings.NumberOfSteps       = 10;
                legendSettings.Rounding            = 0.05;
                legendSettings.ShowDataDescription = false;
                legendSettings.ShowLegend          = true;

                // extract legend text:

                a = new FilteredElementCollector(doc);

                elements = a
                           .OfClass(typeof(TextNoteType))
                           .Where(x => x.Name == "LegendText")
                           .Cast <Element>()
                           .ToList();

                if (0 < elements.Count)
                {
                    // if LegendText exists, use it for this display style

                    TextNoteType textType = elements[0] as TextNoteType;

                    legendSettings.SetTextTypeId(textType.Id, doc);
                }

                // create the analysis display style:

                analysisDisplayStyle = AnalysisDisplayStyle
                                       .CreateAnalysisDisplayStyle(
                    doc, styleName, coloredSurfaceSettings,
                    colorSettings, legendSettings);
            }

            // assign the display style to the active view

            doc.ActiveView.AnalysisDisplayStyleId
                = analysisDisplayStyle.Id;
        }
예제 #18
0
파일: CMD.cs 프로젝트: inktan/RevitApi_
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            APP.UIApp = commandData.Application;
            UIApplication uiapp        = commandData.Application;
            UIDocument    uidoc        = uiapp.ActiveUIDocument;
            Document      doc          = uidoc.Document;
            Selection     sel          = uidoc.Selection;//Revit文档数据读取
            View          activeView   = doc.ActiveView;
            ElementId     activeViewId = activeView.Id;

            ICollection <Element> targetMoGroupTypes = (new FilteredElementCollector(doc)).OfCategory(BuiltInCategory.OST_IOSModelGroups).WhereElementIsElementType().ToElements();
            MainWindow            mainWindow         = new MainWindow(uidoc);

            mainWindow.Show();
            return(Result.Succeeded);

            Element ele = doc.GetElement(sel.PickObject(ObjectType.Element));


            Group             group      = ele as Group;
            IList <ElementId> elementIds = group.GetMemberIds();

            string str = "";

            foreach (ElementId _eleid in elementIds)
            {
                ElementId eleid = doc.GetElement(_eleid).GetTypeId();

                str += doc.GetElement(_eleid).Name + ",,," + eleid + "\n\r";

                if (eleid.IntegerValue != -1)//判断一个元素是否存在族类型
                {
                    TaskDialog.Show("1", "1");
                }
            }
            TaskDialog.Show("1", str);

            return(Result.Succeeded);

            IList <Element> textNoteTypes = (new FilteredElementCollector(doc)).OfClass(typeof(TextNoteType)).ToElements();
            IList <string>  tntNames      = getIcollecionNames(doc, textNoteTypes);

            string tntfield = "Arial Narrow-2.0-1.00-HDDN";//目标文字注释类型

            if (!tntNames.Contains(tntfield))
            {
                //创建该字体名称
                ElementId    defaultTextTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);//创建标准字体
                TextNoteType textNoteType      = doc.GetElement(defaultTextTypeId) as TextNoteType;
                TextNoteType newtnType;
                using (Transaction createNewtnType = new Transaction(doc))                               //事务结束
                {
                    createNewtnType.Start("createNewtnType");                                            //开启事务
                    newtnType = textNoteType.Duplicate("Arial Narrow-2.0-1.00-HDDN123") as TextNoteType; //移动文字至中心位置
                    createNewtnType.Commit();                                                            //提交事务
                }
                //创建两个事务,否则前者不存在文档中
                using (Transaction modifyNewtnType = new Transaction(doc)) //事务结束
                {
                    modifyNewtnType.Start("modifyNewtnType");              //开启事务

                    //图形
                    newtnType.get_Parameter(BuiltInParameter.LINE_COLOR).Set(0);                               //颜色
                    newtnType.get_Parameter(BuiltInParameter.LINE_PEN).SetValueString("1");                    //线宽
                    newtnType.get_Parameter(BuiltInParameter.TEXT_BACKGROUND).SetValueString("透明");            //背景
                    newtnType.get_Parameter(BuiltInParameter.TEXT_BOX_VISIBILITY).SetValueString("否");         //显示边框
                    newtnType.get_Parameter(BuiltInParameter.LEADER_OFFSET_SHEET).SetValueString("0.0000 mm"); //引线/边界偏移值
                    newtnType.get_Parameter(BuiltInParameter.LEADER_ARROWHEAD).SetValueString("无");            //引线箭头---无效设置
                    //文字
                    newtnType.get_Parameter(BuiltInParameter.TEXT_FONT).Set("Arial Narrow");                   //文字字体
                    newtnType.get_Parameter(BuiltInParameter.TEXT_SIZE).SetValueString("2.0000 mm");           //文字大小
                    newtnType.get_Parameter(BuiltInParameter.TEXT_TAB_SIZE).SetValueString("8.0000 mm");       //标签尺寸
                    newtnType.get_Parameter(BuiltInParameter.TEXT_STYLE_BOLD).Set(0);                          //粗体
                    newtnType.get_Parameter(BuiltInParameter.TEXT_STYLE_ITALIC).Set(1);                        //斜体
                    newtnType.get_Parameter(BuiltInParameter.TEXT_STYLE_UNDERLINE).Set(0);;                    //下划线
                    newtnType.get_Parameter(BuiltInParameter.TEXT_WIDTH_SCALE).SetValueString("1");            //宽度系数

                    modifyNewtnType.Commit();                                                                  //提交事务
                }
            }
            else
            {
            }

            return(Result.Succeeded);
        }
예제 #19
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc     = commandData.Application.ActiveUIDocument;
            Document   doc       = commandData.Application.ActiveUIDocument.Document;
            var        selection = uidoc.Selection;

            if (selection == null)
            {
                TaskDialog.Show("wrong", "未选中符号线"); return(Result.Failed);
            }
            List <ElementId>   elementIds   = selection.GetElementIds().ToList();
            List <DetailCurve> detailCurves = new List <DetailCurve>();
            List <double>      doubles      = new List <double>();
            double             length       = 0;

            foreach (ElementId id in elementIds)
            {
                DetailCurve detailCurve = uidoc.Document.GetElement(id) as DetailCurve;
                if (detailCurve == null)
                {
                    continue;
                }

                detailCurves.Add(detailCurve);
                doubles.Add(detailCurve.GeometryCurve.Length);
                length += detailCurve.GeometryCurve.Length;
            }
            string str1 = "疏散距离" + (length * 304.8 / 1000).ToString("f1") + "M";

            //prompt
            string str2 = "总共选中了" + Convert.ToString(detailCurves.Count) + "条线\n" + "分别长:";

            foreach (double dou in doubles)
            {
                str2 += "\n" + Convert.ToString(dou * 304.8);
            }
            str2 += "\n总长度:" + Convert.ToString(length * 304.8);
            str2 += "\n 请点击一点以确定放置标注的位置";
            TaskDialog.Show("GOA", str2);

            //get type
            FilteredElementCollector collector = new FilteredElementCollector(doc);

            collector.OfClass(typeof(TextNoteType));
            TextNoteType textnotetype = null;

            foreach (TextNoteType type in collector)
            {
                if (type.Name == "G-Simhei-4.0-0.60-FIRE")
                {
                    textnotetype = type;
                }
            }
            if (textnotetype == null)
            {
                TaskDialog.Show("wrong", "未找到名为G-Simhei-4.0-0.60-FIRE的字体"); return(Result.Failed);
            }

            #region 开启事务
            using (Transaction transaction = new Transaction(doc))  //放置文字
            {
                transaction.Start("疏散距离标注");
                ElementId elementid  = doc.ActiveView.Id;
                ElementId elementid2 = textnotetype.Id;
                var       point      = uidoc.Selection.PickPoint(Autodesk.Revit.UI.Selection.ObjectSnapTypes.None, "选择文字插入点");
                TextNote  textnote   = TextNote.Create(doc, elementid, point, str1, elementid2);
                transaction.Commit();
            }
            #endregion

            return(Result.Succeeded);
        }
예제 #20
0
        private void ImportAutoCADFileFinal(int id)
        {
            if (this.parentHandler.requestData != null)
            {
                TextNoteType selectedTextNoteType = null;
                foreach (ElementId preTextNoteTypeId in this.parentHandler.preTextNoteTypesIds)
                {
                    TextNoteType preTextNoteType = doc.GetElement(preTextNoteTypeId) as TextNoteType;
                    if (preTextNoteType != null)
                    {
                        if (preTextNoteType.Name == this.parentHandler.requestData.selectedTextStyleName)
                        {
                            selectedTextNoteType = preTextNoteType;
                        }
                    }
                }

                int convertedTextNotesNumber = 0;
                if (selectedTextNoteType != null)
                {
                    foreach (ElementId difTextNoteId in this.parentHandler.difTextNotesIds)
                    {
                        try
                        {
                            TextNote difTextNote = doc.GetElement(difTextNoteId) as TextNote;
                            if (difTextNote != null)
                            {
                                difTextNote.TextNoteType = selectedTextNoteType;
                                convertedTextNotesNumber++;
                            }
                        }
                        catch (Exception ex)
                        {
                            TaskDialog.Show("Exception", ex.Message);
                        }
                    }
                }


                Dictionary <Tuple <byte, byte, byte>, GraphicsStyle> colorToGraphicsStyle = new Dictionary <Tuple <byte, byte, byte>, GraphicsStyle>();
                foreach (KeyValuePair <Tuple <byte, byte, byte>, string> keyValuePair in this.parentHandler.requestData.colorsToLineStyles)
                {
                    string revitStyleName = keyValuePair.Value;
                    if (this.parentHandler.revitLineStylesDict.ContainsKey(revitStyleName))
                    {
                        GraphicsStyle revitGraphicsStyle = this.parentHandler.revitLineStylesDict[revitStyleName];
                        colorToGraphicsStyle.Add(keyValuePair.Key, revitGraphicsStyle);
                    }
                }


                Dictionary <Tuple <byte, byte, byte>, int> lineStylesDict = new Dictionary <Tuple <byte, byte, byte>, int>();
                foreach (ElementId difElementId in parentHandler.difCurveElementIds)
                {
                    CurveElement difCurveElement = doc.GetElement(difElementId) as CurveElement;
                    if (difCurveElement != null)
                    {
                        GraphicsStyle difLineStyle = difCurveElement.LineStyle as GraphicsStyle;
                        if (difLineStyle != null)
                        {
                            Category difLineStyleCategory = difLineStyle.GraphicsStyleCategory;
                            if (difLineStyleCategory != null)
                            {
                                Color difLineStyleColor = difLineStyleCategory.LineColor;
                                if (difLineStyleColor != null)
                                {
                                    Tuple <byte, byte, byte> difLineStyleColorTuple = new Tuple <byte, byte, byte>(difLineStyleColor.Red, difLineStyleColor.Green, difLineStyleColor.Blue);
                                    if (colorToGraphicsStyle.ContainsKey(difLineStyleColorTuple))
                                    {
                                        GraphicsStyle norGraphicsStyle = colorToGraphicsStyle[difLineStyleColorTuple];
                                        difCurveElement.LineStyle = norGraphicsStyle;
                                    }
                                }
                            }
                        }
                    }
                }

                doc.Delete(this.parentHandler.difTextNoteTypesIds);
                doc.Delete(this.parentHandler.difLineCategoriesIds);

                doc.Regenerate();
                uiapp.ActiveUIDocument.RefreshActiveView();

                TaskDialog.Show("Info", "Finished AutoCAD Details Conversion");
            }
        }
예제 #21
0
        public void Create_ValidArgs()
        {
            var note = TextNote.ByLocation(Revit.Application.Document.Current.ActiveView, Point.ByCoordinates(0, 0, 0), "Hello World", "Center", TextNoteType.Default());

            Assert.NotNull(note);

            Assert.AreEqual(note.Text.Replace("\r", ""), "Hello World");
        }