Material. Autodesk 2014 Platform API
Реклама
Реклама
The GeometryCurve property return value is a general Geometry.Curve object, therefore, you must use an As operator to convert the object type.
Note
The following information applies to GeometryCurve:
•
In Revit you cannot create a Hermite curve but you can import it from other software such as AutoCAD. Geometry.Curve is the only geometry class that represents the Hermite curve.
• The SetPlaneAndCurve() method and the Curve and SketchPlane property setters are used in different situations. o
When the new Curve lies in the same SketchPlane, or the new SketchPlane lies on the same planar face with the old
SketchPlane, use the Curve or SketchPlane property setters. o
If new Curve does not lay in the same SketchPlane, or the new SketchPlane does not lay on the same planar face with the old SketchPlane, you must simultaneously change the Curve value and the SketchPlane value using SetPlaneAndCurve() to avoid internal data inconsistency.
Line Styles
Line styles are represented by the GraphicsStyle class. All line styles for a ModelCurve are available from the GetLineStyleIds() method which returns a set of ElementIds of GraphicsStyle elements.
Material
In the Revit Platform API, material data is stored and managed as an Element. Just as in the Revit UI, a material can have several assets associated with it, but only thermal and structural (referred to as Physical in the Revit UI) assets can be assigned using the API.
Some material features are represented by properties on the Material class itself, such as FillPattern, Color, or Render while others are available as properties of either a structural or thermal asset associated with the material.
In this chapter, you learn how to access material elements and how to manage the Material objects in the document. Walkthrough: Get Materials of a Window provides a walkthrough showing how to get a window material.
General Material Information
Before you begin the walkthrough, read through the following section for a better understanding of the Material class.
All Material objects can be retrieved using a Material class filter. Material objects are also available in Document, Category, Element, Face, and so on, and are discussed in the pertinent sections in this chapter. Wherever you get a material object, it is represented as the Material class.
Properties
A material will have one or more aspects pertaining to rendering appearance, structure, or other major material category. Each aspect is represented by properties on the Material class itself or via one of its assets, structural or thermal. The StructuralAsset class represents the properties of a material pertinent to structural analysis. The ThermalAsset class represents the properties of a material pertinent to energy analysis.
Code Region 19-3: Getting material properties
1.
private void
ReadMaterialProps(Document document, Material material)
2. {
3. ElementId strucAssetId = material.StructuralAssetId;
4.
if
(strucAssetId != ElementId.InvalidElementId)
5. {
6. PropertySetElement pse = document.GetElement(strucAssetId) asPropertySetElement;
7.
if
(pse !=
null
)
8. {
9. StructuralAsset asset = pse.GetStructuralAsset();
10.
11.
// Check the material behavior and only read if Isotropic
12.
if
(asset.Behavior == StructuralBehavior.Isotropic)
13. {
14.
// Get the class of material
// Get other material properties
15. StructuralAssetClass assetClass = asset.StructuralAssetClass;
16.
17.
18.
double
poisson = asset.PoissonRatio.X;
19.
double
youngMod = asset.YoungModulus.X;
20.
double
thermCoeff = asset.ThermalExpansionCoefficient.X;
21.
double
unitweight = asset.Density;
22.
double
shearMod = asset.ShearModulus.X;
23.
double
dampingRatio = asset.DampingRatio;
24.
if
(assetClass == StructuralAssetClass.Metal)
25. {
26.
double
dMinStress = asset.MinimumYieldStress;
27. }
28. elseif (assetClass == StructuralAssetClass.Concrete)
29. {
30.
double
dConcComp = asset.ConcreteCompression;
31. }
32. }
33. }
34. }
35. }
// Get other material properties
1. }
Classification
The material classification relevant to structural analysis (i.e. steel, concrete, wood) can be obtained from the StructuralAssetClass property of the StructuralAsset associated with the material.
Note: The API does not provide access to the values of Concrete Type for Concrete material.
The material classification relevant to energy analysis (i.e. solid, liquid, gas) can be obtained from the ThermalMaterialType property of the
ThermalAsset associated with the material.
Other Properties
The material object properties identify a specific type of material including color, fill pattern, and more.
Properties and Parameter
Some Material properties are only available as a Parameter. A few, such as Color, are available as a property or as a Parameter using the
BuiltInParameter MATERIAL_PARAM_COLOR.
Rendering Information
Collections of rendering data are organized into objects called Assets, which are read-only. You can obtain all available Appearance-related assets from the Application.Assets property. An appearance asset can be accessed from a material via the Material.RenderAppearance property.
The following figure shows the Appearance Library section of the Asset Browser dialog box, which shows how some rendering assets are displayed in the UI.
Figure 106: Appearance Library
The Materials sample application included with the SDK shows how to set the RenderApperance property to a material selected in a dialog.
The dialog is populated with all the Asset objects in Application.Assets.
FillPattern
All FillPatterns in a document are available using a FilteredElementCollector filtering on class FillPatternElement. A FillPatternElement is an element that contains a FillPattern while the FillPattern class provides access to the pattern name and the set of FillGrids that make up the pattern.
There are two kinds of FillPatterns: Drafting and Model. In the UI, you can only set Drafting fill patterns to Material.CutPattern. The fill pattern type is exposed via the FillPattern.Target property. The following example shows how to change the material FillPattern.
Code Region 19-4: Setting the fill pattern
1.
public void
SetFillPattern(Document document, Material material)
2. {
3. FilteredElementCollector collector =
new
FilteredElementCollector(document);
4. ICollection<FillPatternElement> fillPatternElements =
5. collector.OfClass(
typeof
(FillPatternElement)).Cast<FillPatternElement>().ToList();
6.
foreach
(FillPatternElement fillPattern
in
fillPatternElements)
7. {
8. // always set successfully
9. material.CutPattern = fillPattern;
10. material.SurfacePattern = fillPattern;
11. }
12. }
Скачать
Реклама