目的是用于导出视图样板中的图形替换,但Revit中视图样板其实也属于视图,所以对于所有视图都通用。
方法十分简单,视图中的样式替换都可以通过OverrideGraphicSettings读取,要注意的地方是需要对读出来的数据一些判别。
对于类别替换的写入其实方法十分类似,几乎可以套用。
以下代码:
private class ViewGraphicOverride
{
static Document _doc;
static View _view;
static Category _category;
public ViewGraphicOverride(Document document,View view,string categoryName)
{
_doc = document;
_view = view;
_category = _doc.Settings.Categories.get_Item(categoryName);
}
//可见性
public string CategoryVisible
{
get
{
return _view.GetVisibility(_category) ? "是" : "否";
}
}
//投影线宽
public string ProjectionLineWeight
{
get
{
string lineWeight = "<无替换>";
OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
if (ogs.ProjectionLineWeight != -1) lineWeight = ogs.ProjectionLineWeight.ToString();
return lineWeight;
}
}
//投影线颜色
public string ProjectionLineColor
{
get
{
string lineColor = "<无替换>";
OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
if (ogs.ProjectionLineColor.IsValid)
{
Color rgb = ogs.ProjectionLineColor;
lineColor = rgb.Red.ToString() + ',' + rgb.Green.ToString() + ',' + rgb.Blue;
}
return lineColor;
}
}
//投影线样式
public string ProjectionLinePatternName
{
get
{
string linePatternName = "<无替换>";
OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
ElementId patternId = ogs.ProjectionLinePatternId;
if (patternId.IntegerValue != -1)
{
if (patternId.IntegerValue == -3000010)
{
linePatternName = "实线";
}
else
{
linePatternName = LinePatternElement.GetLinePattern(_doc, patternId).Name;
}
}
return linePatternName;
}
}
//表面填充样式替换可见性
public string IsProjectionFillPatternVisible
{
get
{
OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
return ogs.IsProjectionFillPatternVisible ? "是" : "否";
}
}
//表面填充颜色
public string ProjectionFillColor
{
get
{
string fillColor = "<无替换>";
OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
if (ogs.ProjectionFillColor.IsValid)
{
Color rgb = ogs.ProjectionFillColor;
fillColor = rgb.Red.ToString() + ',' + rgb.Green.ToString() + ',' + rgb.Blue;
}
return fillColor;
}
}
//表面填充样式
public string ProjectionFillPatternName
{
get
{
string fillPatternName = "<无替换>";
OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
ElementId patternId = ogs.ProjectionFillPatternId;
if (patternId.IntegerValue != -1)
{
fillPatternName = _doc.GetElement(patternId).Name;
}
return fillPatternName;
}
}
//透明度
public int Transparency
{
get
{
OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
return ogs.Transparency;
}
}
//截面线宽
public string CutLineWeight
{
get
{
string lineWeight = "<无替换>";
OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
if (ogs.CutLineWeight != -1) lineWeight = ogs.CutLineWeight.ToString();
return lineWeight;
}
}
//截面线颜色
public string CutLineColor
{
get
{
string lineColor = "<无替换>";
OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
if (ogs.CutLineColor.IsValid)
{
Color rgb = ogs.CutLineColor;
lineColor = rgb.Red.ToString() + ',' + rgb.Green.ToString() + ',' + rgb.Blue;
}
return lineColor;
}
}
//截面线样式
public string CutLinePatternName
{
get
{
string linePatternName = "<无替换>";
OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
ElementId patternId = ogs.CutLinePatternId;
if (patternId.IntegerValue != -1)
{
if (patternId.IntegerValue == -3000010)
{
linePatternName = "实线";
}
else
{
linePatternName = LinePatternElement.GetLinePattern(_doc, patternId).Name;
}
}
return linePatternName;
}
}
//截面填充样式替换可见性
public string IsCutFillPatternVisible
{
get
{
OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
return ogs.IsCutFillPatternVisible ? "是" : "否";
}
}
//截面填充颜色
public string CutFillColor
{
get
{
string fillColor = "<无替换>";
OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
if (ogs.CutFillColor.IsValid)
{
Color rgb = ogs.CutFillColor;
fillColor = rgb.Red.ToString() + ',' + rgb.Green.ToString() + ',' + rgb.Blue;
}
return fillColor;
}
}
//截面填充样式
public string CutFillPatternName
{
get
{
string fillPatternName = "<无替换>";
OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
ElementId patternId = ogs.CutFillPatternId;
if (patternId.IntegerValue != -1)
{
fillPatternName = _doc.GetElement(patternId).Name;
}
return fillPatternName;
}
}
//半色调
public string Halftone
{
get
{
OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
return ogs.Halftone ? "是" : "否";
}
}
//详细程度
public string DetailLevel
{
get
{
string detailLevel;
OverrideGraphicSettings ogs = _view.GetCategoryOverrides(_category.Id);
switch (ogs.DetailLevel)
{
case ViewDetailLevel.Coarse:
detailLevel = "粗略";
break;
case ViewDetailLevel.Medium:
detailLevel = "中等";
break;
case ViewDetailLevel.Fine:
detailLevel = "精细";
break;
default:
detailLevel = "按视图";
break;
}
return detailLevel;
}
}
}
微信公众号:xuebim
关注建筑行业BIM发展、研究建筑新技术,汇集建筑前沿信息!
← 微信扫一扫,关注我们+
评论前必须登录!
注册