在Revit API中更改线型后,无法在对象样式中找到新的线型

问题描述

我正在Revit家族中创建一个线型类别,设置它之后,它存在,但我只是在该家族中找不到它,但是我尝试重新创建它时,revit产生了一个已经存在的错误。我尝试使用再生,但这不起作用。

ElementId solidLineId = LinePatternElement.GetSolidPatternId();

        // The new linestyle will be a subcategory of the Lines category        
        Categories categories = doc.Settings.Categories;
        Category lineCat = categories.get_Item(BuiltInCategory.OST_Lines);

        using (Transaction t = new Transaction(doc,"Create LineStyle"))
        {
            t.Start();
            Category newLineStyleCat = categories.NewSubcategory(lineCat,"Black-01-Solid");
            newLineStyleCat.SetLineWeight(1,GraphicsStyleType.Projection);
            newLineStyleCat.LineColor = new Color(28,28,28);
            newLineStyleCat.SetLinePatternId(solidLineId,GraphicsStyleType.Projection);
            t.Commit();
        }

解决方法

这是可以创建新线型的方式

类别cat = famDoc.OwnerFamily.FamilyCategory; 类别newSubCat = null;

        if (!cat.SubCategories.Contains(subCatToAdd))
        {
            using (Transaction t = new Transaction(famDoc,"Add new or find existing subcategory"))
            {
                t.Start();
                newSubCat = famDoc.Settings.Categories.NewSubcategory(cat,subCatToAdd);
                GraphicsStyleType gst = GraphicsStyleType.Projection;
                GraphicsStyle gs = newSubCat.GetGraphicsStyle(gst);
                newSubCat.SetLineWeight(lineWeight,gst);
                t.Commit();
            }
        }

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...