社区
Q:
我想开发一个插件用来从视图中导出构件的信息到其他的格式,我现在想根据构件所在视图的不同,材质的不同等来获取构件最终的图形样式,因为在某个视图中可能存在这个样式替换的可能,请问有什么办法可以实现吗?
已解决! 转到解答。
Q:
我想开发一个插件用来从视图中导出构件的信息到其他的格式,我现在想根据构件所在视图的不同,材质的不同等来获取构件最终的图形样式,因为在某个视图中可能存在这个样式替换的可能,请问有什么办法可以实现吗?
已解决! 转到解答。
A:
您需要自己通过判断去获取,首先通过类别来获取到图形样式,如何看这个构件在视图中是否被替换了图形样式,如果被替换的话,就获取替换后的图形样式。下面的代码供您参考:
public void GetGraphicsStyleInView(Document doc, View view, Element e) { /* * first get graphics style from element's category, * if override graphics setting setted, get from override */ Color color = null; int? lineWeight = null; LinePattern linePattern = null; //get line weight& color from category lineWeight = e.Category.GetLineWeight(GraphicsStyleType.Projection); color = e.Category.LineColor; ElementId patternId = e.Category.GetLinePatternId(GraphicsStyleType.Projection); if(patternId != ElementId.InvalidElementId) { LinePatternElement patternElement = doc.GetElement(patternId) as LinePatternElement; if (patternElement != null) linePattern = patternElement.GetLinePattern(); } //if element has override, then get from override OverrideGraphicSettings overrideGraphicSettings = doc.ActiveView.GetElementOverrides(e.Id); if (null != overrideGraphicSettings) { if(overrideGraphicSettings.CutLineColor.IsValid) color = overrideGraphicSettings.CutLineColor; if(overrideGraphicSettings.CutLineWeight > 0) lineWeight = overrideGraphicSettings.CutLineWeight; if (overrideGraphicSettings.CutLinePatternId != ElementId.InvalidElementId) { LinePatternElement patternElement = doc.GetElement(overrideGraphicSettings.CutLinePatternId) as LinePatternElement; if (patternElement.GetLinePattern() != null) linePattern = patternElement.GetLinePattern(); } } }
A:
您需要自己通过判断去获取,首先通过类别来获取到图形样式,如何看这个构件在视图中是否被替换了图形样式,如果被替换的话,就获取替换后的图形样式。下面的代码供您参考:
public void GetGraphicsStyleInView(Document doc, View view, Element e) { /* * first get graphics style from element's category, * if override graphics setting setted, get from override */ Color color = null; int? lineWeight = null; LinePattern linePattern = null; //get line weight& color from category lineWeight = e.Category.GetLineWeight(GraphicsStyleType.Projection); color = e.Category.LineColor; ElementId patternId = e.Category.GetLinePatternId(GraphicsStyleType.Projection); if(patternId != ElementId.InvalidElementId) { LinePatternElement patternElement = doc.GetElement(patternId) as LinePatternElement; if (patternElement != null) linePattern = patternElement.GetLinePattern(); } //if element has override, then get from override OverrideGraphicSettings overrideGraphicSettings = doc.ActiveView.GetElementOverrides(e.Id); if (null != overrideGraphicSettings) { if(overrideGraphicSettings.CutLineColor.IsValid) color = overrideGraphicSettings.CutLineColor; if(overrideGraphicSettings.CutLineWeight > 0) lineWeight = overrideGraphicSettings.CutLineWeight; if (overrideGraphicSettings.CutLinePatternId != ElementId.InvalidElementId) { LinePatternElement patternElement = doc.GetElement(overrideGraphicSettings.CutLinePatternId) as LinePatternElement; if (patternElement.GetLinePattern() != null) linePattern = patternElement.GetLinePattern(); } } }