本文整理汇总了C#中Document.get_Element方法的典型用法代码示例。如果您正苦于以下问题:C# Document.get_Element方法的具体用法?C# Document.get_Element怎么用?C# Document.get_Element使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.get_Element方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateInitialParameters
// Setup routine: updates parameters of the window to the appropriate values on load
internal void UpdateInitialParameters(Document doc)
{
Transaction t = new Transaction(doc, "Update parameters");
t.Start();
SchemaBuilder builder = new SchemaBuilder(m_schemaId); //(new Guid("{4DE4BE80-0857-4785-A7DF-8A8918851CB2}"));
builder.AddSimpleField("Position", typeof(XYZ)).SetUnitType(UnitType.UT_Length);
builder.AddSimpleField("Orientation", typeof(XYZ)).SetUnitType(UnitType.UT_Length);
builder.SetSchemaName("WallPositionData");
builder.SetDocumentation("Two points in a Window element that assist in placing a section view.");
builder.SetVendorId("adsk");
builder.SetApplicationGUID(doc.Application.ActiveAddInId.GetGUID());
m_schema = builder.Finish();
t.Commit();
t.Start();
Field fieldPosition = m_schema.GetField("Position");
Field fieldOrientation = m_schema.GetField("Orientation");
FamilyInstance window = doc.get_Element(m_windowId) as FamilyInstance;
Entity storageEntity = new Entity(m_schema);
LocationPoint lp = window.Location as LocationPoint;
XYZ location = lp.Point;
storageEntity.Set<XYZ>(fieldPosition, location, DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES);
XYZ orientation = window.FacingOrientation;
storageEntity.Set<XYZ>(fieldOrientation, orientation, DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES);
window.SetEntity(storageEntity);
t.Commit();
}
示例2: GetBoundaryElement
/// <summary>
/// Get element from LinkElementId.
/// </summary>
/// <param name="document">
/// The Revit document.
/// </param>
/// <param name="linkElementId">
/// The link element id.
/// </param>
/// <returns>
/// The element.
/// </returns>
static Element GetBoundaryElement(Document document, LinkElementId linkElementId)
{
ElementId elemId = linkElementId.LinkInstanceId;
if (elemId == ElementId.InvalidElementId)
{
elemId = linkElementId.HostElementId;
}
return document.get_Element(elemId);
}
示例3: Register
// Registers itself with Revit
internal void Register(Document doc)
{
// create a window filter for the updater's scope
// we are only interested in two elements, one window and one section
// (for the sake of simplicity, we hard-coded the elements' unique Ids)
String windowUniqueId = "7f04899c-797b-4ad1-a9da-c6de1243ff83-00025ff6";
String sectionUniqueId = "4ca42fe1-e3e2-4bee-ab19-7d6e95cdf1bc-000261e8";
Element window = doc.get_Element(windowUniqueId);
if (window == null)
throw new Exception("Window was not found in the document.");
Element section = doc.get_Element(sectionUniqueId);
if (section == null)
throw new Exception("Section was not found in the document.");
// Setup collection of ids for the updater
List<ElementId> idsToWatch = new List<ElementId>();
m_windowId = window.Id;
idsToWatch.Add(m_windowId);
m_sectionId = section.Id;
UpdateInitialParameters(doc);
// Register and set a trigger for the section updater when the window changes
UpdaterRegistry.RegisterUpdater(this, doc);
UpdaterRegistry.AddTrigger(m_updaterId, doc, idsToWatch, Element.GetChangeTypeGeometry());
}
示例4: DumpViewsInfo
/// <summary>
/// Dump information of views: ViewType, Id and ViewName.
/// The information will be dumped to both PrintLog.txt and PrintEventsLog.txt.
/// </summary>
/// <param name="Document">Current active document.</param>
/// <param name="viewIds">Views to be dumped to log files.</param>
/// <param name="prefix">Prefix mark for each line dumped to log files.</param>
private static void DumpViewsInfo(Document activeDoc, IList<ElementId> viewIds, String prefix)
{
int index = 0;
foreach (ElementId id in viewIds)
{
View curView = activeDoc.get_Element(id) as View;
if (null != curView)
{
DumpViewInfo(curView, String.Format("{0}#{1}", prefix, index++));
}
}
}
示例5: ExportSpatialElement2ndLevel
/// <summary>
/// Export spatial elements, including rooms, areas and spaces. 2nd level space boundaries.
/// </summary>
/// <param name="ifcExporter">
/// The Exporter object.
/// </param>
/// <param name="exporterIFC">
/// The ExporterIFC object.
/// </param>
/// <param name="document">
/// The Revit document.
/// </param>
/// <param name="filterView">
/// The view not exported.
/// </param>
/// <param name="spaceExported">
/// The output boolean value indicates if exported successfully.
/// </param>
public static void ExportSpatialElement2ndLevel(BIM.IFC.Exporter.Exporter ifcExporter, ExporterIFC exporterIFC, Document document, View filterView)
{
using (SubTransaction st = new SubTransaction(document))
{
st.Start();
bool createEnergyAnalysisDetailModelFailed = false;
EnergyAnalysisDetailModel model = null;
try
{
IFCFile file = exporterIFC.GetFile();
using (IFCTransaction tr = new IFCTransaction(file))
{
EnergyAnalysisDetailModelOptions options = new EnergyAnalysisDetailModelOptions();
options.Tier = EnergyAnalysisDetailModelTier.SecondLevelBoundaries; //2nd level space boundaries
options.SimplifyCurtainSystems = true;
try
{
model = EnergyAnalysisDetailModel.Create(document, options);
}
catch (Exception)
{
createEnergyAnalysisDetailModelFailed = true;
throw;
}
IList<EnergyAnalysisSpace> spaces = model.GetAnalyticalSpaces();
foreach (EnergyAnalysisSpace space in spaces)
{
SpatialElement spatialElement = document.get_Element(space.SpatialElementId) as SpatialElement;
if (spatialElement == null)
continue;
//quick reject
bool isArea = spatialElement is Area;
if (isArea)
{
if (!IsAreaGrossInterior(exporterIFC, spatialElement))
continue;
}
//current view only
if (filterView != null && !ElementFilteringUtil.IsElementVisible(filterView, spatialElement))
continue;
//
if (!ElementFilteringUtil.ShouldCategoryBeExported(exporterIFC, spatialElement))
continue;
Options geomOptions = new Options();
View ownerView = spatialElement.Document.get_Element(spatialElement.OwnerViewId) as View;
if (ownerView != null)
geomOptions.View = ownerView;
GeometryElement geomElem = spatialElement.get_Geometry(geomOptions);
try
{
exporterIFC.PushExportState(spatialElement, geomElem);
using (IFCProductWrapper productWrapper = IFCProductWrapper.Create(exporterIFC, true))
{
ElementId levelId = spatialElement.Level != null ? spatialElement.Level.Id : ElementId.InvalidElementId;
using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, spatialElement, null, null, levelId))
{
try
{
CreateIFCSpace(exporterIFC, spatialElement, productWrapper, setter);
}
catch (System.Exception)
{
continue;
}
//get boundary information from surfaces
IList<EnergyAnalysisSurface> surfaces = space.GetAnalyticalSurfaces();
foreach (EnergyAnalysisSurface surface in surfaces)
{
Element boundingElement = GetBoundaryElement(document, surface.OriginatingElementId);
if (boundingElement == null)
continue;
//.........这里部分代码省略.........
示例6: GetParameterInformation
//this function will get parameter information
String GetParameterInformation(ParameterSet paras, Document document, string defName)
{
foreach (Parameter para in paras)
{
if (para.Definition.Name != defName)
continue;
// Use different method to get parameter data according to the storage type
switch (para.StorageType)
{
case StorageType.Double:
//covert the number into Metric
return para.AsValueString();
case StorageType.ElementId:
//find out the name of the element
Autodesk.Revit.DB.ElementId id = para.AsElementId();
if (id.IntegerValue >= 0)
{
return document.get_Element(id).Name;
}
else
{
return id.IntegerValue.ToString();
}
case StorageType.Integer:
if (ParameterType.YesNo == para.Definition.ParameterType)
{
if (para.AsInteger() == 0)
{
return "False";
}
else
{
return "True";
}
}
else
{
return para.AsInteger().ToString();
}
case StorageType.String:
if (para.AsString() == "null")
return "";
else
return para.AsString();
default:
return "Unexposed parameter.";
}
}
return "";
}
示例7: CreateMaterialAssociation
/// <summary>
/// Creates an association between a material handle and an instance handle.
/// </summary>
/// <param name="document">
/// The Revit document.
/// </param>
/// <param name="exporterIFC">
/// The ExporterIFC object.
/// </param>
/// <param name="instanceHandle">
/// The IFC instance handle.
/// </param>
/// <param name="materialId">
/// The material id.
/// </param>
public static void CreateMaterialAssociation(Document doc, ExporterIFC exporterIFC, IFCAnyHandle instanceHandle, ElementId materialId)
{
// Create material association if any.
if (materialId != ElementId.InvalidElementId)
{
IFCAnyHandle materialNameHnd = exporterIFC.FindMaterialHandle(materialId);
if (!materialNameHnd.HasValue)
{
Material material = doc.get_Element(materialId) as Material;
if (material != null)
{
IFCLabel materialName = IFCLabel.Create(material.Name);
materialNameHnd = exporterIFC.GetFile().CreateMaterial(materialName);
exporterIFC.RegisterMaterialHandle(materialId, materialNameHnd);
}
}
if (materialNameHnd.HasValue)
{
exporterIFC.RegisterMaterialRelation(materialNameHnd, instanceHandle);
}
}
}
示例8: SetSharedParameterValues
private static void SetSharedParameterValues(Document doc)
{
// Start the second transaction to set the shared parameter
Transaction transParam = new Transaction(doc);
transParam.Start("Wall Opening Param");
// open or create the shared parameter
if (!SharedParameterFunctions.
OpenOrCreateWallSharedParameter(doc))
{
transParam.RollBack();
return; //something went wrong...
}
foreach (KeyValuePair<int, double[]> wallDicEntry
in wallsOpeningArea)
{
Wall wall = doc.get_Element(
new ElementId(wallDicEntry.Key)) as Wall;
double openingArea = wallDicEntry.Value[0];
double totalOpeningArea = wallDicEntry.Value[1];
// check if the wall is valid
if (wall == null)
{
TaskDialog.Show("Error accessing wall",
string.Format("The plug-in could not locate wall {0}. " +
"Operation cancelled.", wallDicEntry.Key));
transParam.RollBack();
return;
}
// Store the opening area as Shared Parameter
Parameter openingAreaParam =
wall.get_Parameter(
SharedParameterFunctions.PARAMETER_SMALL_OPEN_NAME);
if (openingAreaParam == null)
{
TaskDialog.Show("Error accessing wall parameter",
string.Format("The plug-in could not locate parameter " +
"{0} of wall {1}. Operation cancelled.",
SharedParameterFunctions.PARAMETER_SMALL_OPEN_NAME,
wallDicEntry.Key));
transParam.RollBack();
return;
}
openingAreaParam.Set(openingArea);
// Store the opening area as Shared Parameter
Parameter totalOpeningAreaParam =
wall.get_Parameter(
SharedParameterFunctions.PARAMETER_TOTAL_OPEN_NAME);
if (totalOpeningAreaParam == null)
{
TaskDialog.Show("Error accessing wall parameter",
string.Format("The plug-in could not locate parameter " +
"{0} of wall {1}. Operation cancelled.",
SharedParameterFunctions.PARAMETER_TOTAL_OPEN_NAME,
wallDicEntry.Key));
transParam.RollBack();
return;
}
totalOpeningAreaParam.Set(totalOpeningArea + openingArea);
}
// Commit transaction to store the shared parameter
transParam.Commit();
}
示例9: AddChangeInfoRow
/// <summary>
/// This method is used to retrieve the changed element and add row to data table.
/// </summary>
/// <param name="id"></param>
/// <param name="doc"></param>
/// <param name="changeType"></param>
private void AddChangeInfoRow(ElementId id, Document doc, string changeType)
{
// retrieve the changed element
Element elem = doc.get_Element(id);
DataRow newRow = m_ChangesInfoTable.NewRow();
// set the relative information of this event into the table.
if (elem == null)
{
// this branch is for deleted element due to the deleted element cannot be retrieve from the document.
newRow["ChangeType"] = changeType;
newRow["Id"] = id.IntegerValue.ToString();
newRow["Name"] = "";
newRow["Category"] = "";
newRow["Document"] = "";
}
else
{
newRow["ChangeType"] = changeType;
newRow["Id"] = id.IntegerValue.ToString();
newRow["Name"] = elem.Name;
newRow["Category"] = elem.Category.Name;
newRow["Document"] = doc.Title;
}
m_ChangesInfoTable.Rows.Add(newRow);
}
示例10: Execute
/// <summary>
/// The top level command.
/// </summary>
/// <param name="revit">An object that is passed to the external application
/// which contains data related to the command,
/// such as the application object and active view.</param>
/// <param name="message">A message that can be set by the external application
/// which will be displayed if a failure or cancellation is returned by
/// the external command.</param>
/// <param name="elements">A set of elements to which the external application
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
/// <returns>Return the status of the external command.
/// A result of Succeeded means that the API external method functioned as expected.
/// Cancelled can be used to signify that the user cancelled the external operation
/// at some point. Failure should be returned if the application is unable to proceed with
/// the operation.</returns>
public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
{
m_app = revit.Application.Application;
m_doc = revit.Application.ActiveUIDocument.Document;
// Find a 3D view to use for the ray tracing operation
FilteredElementCollector collector = new FilteredElementCollector(m_doc);
Func<View3D, bool> isNotTemplate = v3 => !(v3.IsTemplate);
m_view3D = collector.OfClass(typeof(View3D)).Cast<View3D>().First<View3D>(isNotTemplate);
Autodesk.Revit.UI.Selection.Selection selection = revit.Application.ActiveUIDocument.Selection;
// If skylight is selected, process it.
m_skylight = null;
if (selection.Elements.Size == 1)
{
foreach (Element e in selection.Elements)
{
if (e is FamilyInstance)
{
FamilyInstance instance = e as FamilyInstance;
bool isWindow = (instance.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows);
bool isHostedByRoof = (instance.Host.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Roofs);
if (isWindow && isHostedByRoof)
m_skylight = instance;
}
}
}
if (m_skylight == null)
{
message = "This tool requires exactly one skylight to be selected.";
return Result.Cancelled;
}
// Find the floor to use for the measurement (hardcoded)
ElementId id = new ElementId(150314);
m_floor = m_doc.get_Element(id) as Floor;
// Calculate the height
Line line = CalculateLineAboveFloor();
// Create a model curve to show the distance
Plane plane = m_app.Create.NewPlane(new XYZ(1, 0, 0), line.get_EndPoint(0));
SketchPlane sketchPlane = m_doc.Create.NewSketchPlane(plane);
ModelCurve curve = m_doc.Create.NewModelCurve(line, sketchPlane);
// Show a message with the length value
TaskDialog.Show("Distance", "Distance to floor: " + String.Format("{0:f2}", line.Length));
return Result.Succeeded;
}
示例11: SyncPhaseGraphics
//sync the PhaseGraphics with one overload taking an already expanded elemnt to save time
private static void SyncPhaseGraphics(Document doc, ElementId ElemId)
{
Element e = doc.get_Element(ElemId);
SyncPhaseGraphics(doc, e);
}
示例12: writeValueByStorageType
private void writeValueByStorageType(Parameter p, TextWriter writer, Document doc)
{
if (null != p)
{
switch (p.StorageType)
{
case StorageType.Double:
{
writer.Write(p.AsDouble());
break;
}
case StorageType.Integer:
{
writer.Write(p.AsInteger());
break;
}
case StorageType.String:
{
writer.Write(p.AsString());
break;
}
case StorageType.ElementId:
{
Element elem = doc.get_Element(p.AsElementId());
if (null == elem)
writer.Write("NULL ELEMENT FOUND");
else
writer.Write(elem.Name);
break;
}
default:
writer.Write("N/A");
break;
}
}
}