本文整理汇总了C#中Document.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Delete方法的具体用法?C# Document.Delete怎么用?C# Document.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.Delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: deleteLinePatterns
public void deleteLinePatterns(Document doc)
{
var collector = new FilteredElementCollector(doc)
.OfClass(typeof(LinePatternElement)).Where(i => i.Name.StartsWith("IMPORT")).ToList();
List<ElementId> ids = new List<ElementId>();
for (int i = 0; i < collector.Count(); i++)
{
ids.Add(collector[i].Id);
}
using (Transaction t = new Transaction(doc, "Remove Pattern"))
{
t.Start();
try
{
doc.Delete(ids);
}
catch (Exception)
{
t.RollBack();
return;
}
t.Commit();
}
}
示例2: RevitQR
public RevitQR(Document doc, SheetInfo info, string url)
{
// Erase all QRTAG Images from the Sheet
FilteredElementCollector fec = new FilteredElementCollector(doc).OwnedByView(info.sheetId).OfCategory(BuiltInCategory.OST_RasterImages);
foreach (Element element in fec.ToElements()) { if (element.Name.EndsWith("QRTAG")) doc.Delete(element.Id); }
this.URL = url;
foreach (ViewPortInfo vport in info.ViewPorts)
{
// Assemble URL
data = String.Format("{0}/viewer/{1}", new object[] { URL, vport.docQRid });
// Create an image Tag
ImageTag(doc, info, vport);
}
}
示例3: Execute
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
try
{
uiApp = commandData.Application;
uiDoc = uiApp.ActiveUIDocument;
app = uiApp.Application;
doc = uiDoc.Document;
FilteredElementCollector refPlaneCollector = new FilteredElementCollector(doc);
IList<Element> refPlanes = refPlaneCollector.OfClass(typeof(ReferencePlane)).ToElements();
ElementId nameParamterId = new ElementId(BuiltInParameter.DATUM_TEXT);
ParameterValueProvider pvp = new ParameterValueProvider(nameParamterId);
FilterStringRuleEvaluator evaluator = new FilterStringEquals();
FilterRule rule = new FilterStringRule(pvp, evaluator, "", false);
ElementFilter filter = new ElementParameterFilter(rule);
FilteredElementCollector unnamedRefPlaneCollector = new FilteredElementCollector(doc);
unnamedRefPlaneCollector.OfClass(typeof(ReferencePlane));
unnamedRefPlaneCollector.WherePasses(filter);
IList<Element> unnamedRefPlanes = unnamedRefPlaneCollector.ToElements();
Transaction transaction = new Transaction(doc);
transaction.Start("Purging unnamed reference planes");
foreach (Element refPlane in unnamedRefPlanes)
doc.Delete(refPlane.Id);
transaction.Commit();
TaskDialog.Show("Purge Unnamed Ref Planes",
String.Format("{0} reference planes found.\n{1} unnamed reference planes deleted.",
refPlanes.Count.ToString(), unnamedRefPlanes.Count.ToString()));
return Result.Succeeded;
}
catch (Exception e)
{
TaskDialog.Show("Revit Quick Tools", e.Message);
return Result.Failed;
}
}
示例4: UpdateFileHeader
/// <summary>
/// Update the file Header (from the UI) into the document
/// </summary>
/// <param name="document">The document storing the saved File Header.</param>
/// <param name="fileHeaderItem">The File Header item to save.</param>
public void UpdateFileHeader(Document document, IFCFileHeaderItem fileHeaderItem)
{
if (m_schema == null)
{
m_schema = Schema.Lookup(s_schemaId);
}
if (m_schema != null)
{
IList<DataStorage> oldSavedFileHeader = GetFileHeaderInStorage(document, m_schema);
if (oldSavedFileHeader.Count > 0)
{
Transaction deleteTransaction = new Transaction(document, "Delete old IFC File Header");
deleteTransaction.Start();
List<ElementId> dataStorageToDelete = new List<ElementId>();
foreach (DataStorage dataStorage in oldSavedFileHeader)
{
dataStorageToDelete.Add(dataStorage.Id);
}
document.Delete(dataStorageToDelete);
deleteTransaction.Commit();
}
}
// Update the address using the new information
if (m_schema == null)
{
m_schema = Schema.Lookup(s_schemaId);
}
if (m_schema != null)
{
Transaction transaction = new Transaction(document, "Update saved IFC File Header");
transaction.Start();
DataStorage fileHeaderStorage = DataStorage.Create(document);
Entity mapEntity = new Entity(m_schema);
IDictionary<string, string> mapData = new Dictionary<string, string>();
if (fileHeaderItem.FileDescription != null) mapData.Add(s_FileDescription, fileHeaderItem.FileDescription.ToString());
if (fileHeaderItem.SourceFileName != null) mapData.Add(s_SourceFileName, fileHeaderItem.SourceFileName.ToString());
if (fileHeaderItem.AuthorName != null) mapData.Add(s_AuthorName, fileHeaderItem.AuthorName.ToString());
if (fileHeaderItem.AuthorEmail != null) mapData.Add(s_AuthorEmail, fileHeaderItem.AuthorEmail.ToString());
if (fileHeaderItem.Organization != null) mapData.Add(s_Organization, fileHeaderItem.Organization.ToString());
if (fileHeaderItem.Authorization != null) mapData.Add(s_Authorization, fileHeaderItem.Authorization.ToString());
if (fileHeaderItem.ApplicationName != null) mapData.Add(s_ApplicationName, fileHeaderItem.ApplicationName.ToString());
if (fileHeaderItem.VersionNumber != null) mapData.Add(s_VersionNumber, fileHeaderItem.VersionNumber.ToString());
if (fileHeaderItem.FileSchema != null) mapData.Add(s_FileSchema, fileHeaderItem.FileSchema.ToString());
mapEntity.Set<IDictionary<string, String>>(s_FileHeaderMapField, mapData);
fileHeaderStorage.SetEntity(mapEntity);
transaction.Commit();
}
}
示例5: ExportSpatialElement2ndLevel
//.........这里部分代码省略.........
try
{
model = EnergyAnalysisDetailModel.Create(document, options);
}
catch (System.Exception)
{
return exportedSpaceIds;
}
IList<EnergyAnalysisSpace> spaces = model.GetAnalyticalSpaces();
foreach (EnergyAnalysisSpace space in spaces)
{
SpatialElement spatialElement = document.GetElement(space.CADObjectUniqueId) as SpatialElement;
if (spatialElement == null)
continue;
//current view only
if (!ElementFilteringUtil.IsElementVisible(spatialElement))
continue;
if (!ElementFilteringUtil.ShouldElementBeExported(exporterIFC, spatialElement, false))
continue;
if (ElementFilteringUtil.IsRoomInInvalidPhase(spatialElement))
continue;
Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions();
View ownerView = spatialElement.Document.GetElement(spatialElement.OwnerViewId) as View;
if (ownerView != null)
geomOptions.View = ownerView;
GeometryElement geomElem = spatialElement.get_Geometry(geomOptions);
try
{
exporterIFC.PushExportState(spatialElement, geomElem);
using (ProductWrapper productWrapper = ProductWrapper.Create(exporterIFC, true))
{
using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, spatialElement))
{
// We won't use the SpatialElementGeometryResults, as these are 1st level boundaries, not 2nd level.
SpatialElementGeometryResults results = null;
if (!CreateIFCSpace(exporterIFC, spatialElement, productWrapper, setter, out results))
continue;
exportedSpaceIds.Add(spatialElement.Id);
XYZ offset = GetSpaceBoundaryOffset(setter);
//get boundary information from surfaces
IList<EnergyAnalysisSurface> surfaces = space.GetAnalyticalSurfaces();
foreach (EnergyAnalysisSurface surface in surfaces)
{
Element boundingElement = GetBoundaryElement(document, surface.CADLinkUniqueId, surface.CADObjectUniqueId);
IList<EnergyAnalysisOpening> openings = surface.GetAnalyticalOpenings();
IFCAnyHandle connectionGeometry = CreateConnectionSurfaceGeometry(exporterIFC, surface, openings, offset);
CreateIFCSpaceBoundary(file, exporterIFC, spatialElement, boundingElement, setter.LevelId, connectionGeometry);
// try to add doors and windows for host objects if appropriate.
if (boundingElement is HostObject)
{
foreach (EnergyAnalysisOpening opening in openings)
{
Element openingBoundingElem = GetBoundaryElement(document, opening.CADLinkUniqueId, opening.CADObjectUniqueId);
IFCAnyHandle openingConnectionGeom = CreateConnectionSurfaceGeometry(exporterIFC, opening, offset);
CreateIFCSpaceBoundary(file, exporterIFC, spatialElement, openingBoundingElem, setter.LevelId, openingConnectionGeom);
}
}
}
CreateZoneInfos(exporterIFC, file, spatialElement, productWrapper);
CreateSpaceOccupantInfo(exporterIFC, file, spatialElement, productWrapper);
ExporterUtil.ExportRelatedProperties(exporterIFC, spatialElement, productWrapper);
}
}
}
catch (Exception ex)
{
ifcExporter.HandleUnexpectedException(ex, exporterIFC, spatialElement);
}
finally
{
exporterIFC.PopExportState();
}
}
transaction.Commit();
}
}
finally
{
if (model != null)
document.Delete(model.Id);
}
st.RollBack();
return exportedSpaceIds;
}
}
示例6: RemoveDwfLinkUsingExternalFileUtils
/// <summary>
/// Remove DWF links from model and return
/// the total number of deleted elements.
/// </summary>
int RemoveDwfLinkUsingExternalFileUtils(
Document doc)
{
List<ElementId> idsToDelete
= new List<ElementId>();
ICollection<ElementId> ids = ExternalFileUtils
.GetAllExternalFileReferences( doc );
foreach( ElementId id in ids )
{
Element e = doc.GetElement( id );
Debug.Print( Util.ElementDescription( e ) );
ExternalFileReference xr = ExternalFileUtils
.GetExternalFileReference( doc, id );
ExternalFileReferenceType xrType
= xr.ExternalFileReferenceType;
if( xrType == ExternalFileReferenceType.DWFMarkup )
{
ModelPath xrPath = xr.GetPath();
string path = ModelPathUtils
.ConvertModelPathToUserVisiblePath( xrPath );
if( path.EndsWith( ".dwf" )
|| path.EndsWith( ".dwfx" ) )
{
idsToDelete.Add( id );
}
}
}
int n = idsToDelete.Count;
ICollection<ElementId> idsDeleted = null;
if( 0 < n )
{
using( Transaction t = new Transaction( doc ) )
{
t.Start( "Delete DWFx Links" );
idsDeleted = doc.Delete( idsToDelete );
t.Commit();
}
}
int m = ( null == idsDeleted )
? 0
: idsDeleted.Count;
Debug.Print( string.Format(
"Selected {0} DWF external file reference{1}, "
+ "{2} element{3} successfully deleted.",
n, Util.PluralSuffix( n ), m, Util.PluralSuffix( m ) ) );
return m;
}
示例7: RemoveDwfLinkUsingDelete
/// <summary>
/// Useless non-functional attempt to remove all
/// DWF links from the model and return
/// the total number of deleted elements.
/// This does not work! Instead, use
/// RemoveDwfLinkUsingExternalFileUtils.
/// </summary>
int RemoveDwfLinkUsingDelete( Document doc )
{
int nDeleted = 0;
FilteredElementCollector col
= new FilteredElementCollector( doc )
.WhereElementIsNotElementType();
List<ElementId> ids = new List<ElementId>();
int pinned = 0;
foreach( Element e in col )
{
if( ElementCategoryContainsDwf( e ) )
{
Debug.Print( Util.ElementDescription( e ) );
pinned += ( e.Pinned ? 1 : 0 );
ids.Add( e.Id );
}
}
ICollection<ElementId> idsDeleted = null;
Transaction t;
int n = ids.Count;
int unpinned = 0;
if( 0 < n )
{
if( 0 < pinned )
{
using( t = new Transaction( doc ) )
{
t.Start(
"Unpin non-ElementType '.dwf' elements" );
unpinned = Unpin( ids, doc );
t.Commit();
}
}
using( t = new Transaction( doc ) )
{
t.Start(
"Delete non-ElementType '.dwf' elements" );
idsDeleted = doc.Delete( ids );
t.Commit();
}
}
int m = ( null == idsDeleted )
? 0
: idsDeleted.Count;
Debug.Print( string.Format(
"Selected {0} non-ElementType element{1}, "
+ "{2} pinned, {3} unpinned, "
+ "{4} successfully deleted.",
n, Util.PluralSuffix( n ), pinned, unpinned, m ) );
nDeleted += m;
col = new FilteredElementCollector( doc )
.WhereElementIsElementType();
ids.Clear();
pinned = 0;
foreach( Element e in col )
{
if( ElementCategoryContainsDwf( e ) )
{
Debug.Print( Util.ElementDescription( e ) );
pinned += ( e.Pinned ? 1 : 0 );
ids.Add( e.Id );
}
}
n = ids.Count;
if( 0 < n )
{
if( 0 < pinned )
{
using( t = new Transaction( doc ) )
{
t.Start(
"Unpin element type '.dwf' elements" );
//.........这里部分代码省略.........
示例8: IFCClassificationMgr
/// <summary>
/// the IFC Classification Manager
/// </summary>
/// <param name="document">The document.</param>
public IFCClassificationMgr(Document document)
{
if (Schema == null)
{
SchemaBuilder classificationBuilder = new SchemaBuilder(s_schemaId);
classificationBuilder.SetSchemaName("IFCClassification");
classificationBuilder.AddSimpleField(s_ClassificationName, typeof(string));
classificationBuilder.AddSimpleField(s_ClassificationSource, typeof(string));
classificationBuilder.AddSimpleField(s_ClassificationEdition, typeof(string));
classificationBuilder.AddSimpleField(s_ClassificationEditionDate_Day, typeof(Int32));
classificationBuilder.AddSimpleField(s_ClassificationEditionDate_Month, typeof(Int32));
classificationBuilder.AddSimpleField(s_ClassificationEditionDate_Year, typeof(Int32));
classificationBuilder.AddSimpleField(s_ClassificationLocation, typeof(string));
classificationBuilder.AddSimpleField(s_ClassificationFieldName, typeof(string));
m_schema = classificationBuilder.Finish();
}
// Potentially delete obsolete schema.
if (SchemaV1 != null)
{
IList<IFCClassification> classifications;
bool hasOldClassifications = GetSavedClassifications(document, SchemaV1, out classifications);
if (hasOldClassifications)
{
Transaction transaction = new Transaction(document, "Upgrade saved IFC classification");
transaction.Start();
IList<DataStorage> oldSchemaData = GetClassificationInStorage(document, SchemaV1);
IList<ElementId> oldDataToDelete = new List<ElementId>();
foreach (DataStorage oldData in oldSchemaData)
{
Entity savedClassification = oldData.GetEntity(SchemaV1);
DataStorage classificationStorage = DataStorage.Create(document);
Entity entIFCClassification = new Entity(Schema);
string classificationName = savedClassification.Get<string>(s_ClassificationName);
if (classificationName != null) entIFCClassification.Set<string>(s_ClassificationName, classificationName);
string classificationSource = savedClassification.Get<string>(s_ClassificationSource);
if (classificationSource != null) entIFCClassification.Set<string>(s_ClassificationSource, classificationSource);
string classificationEdition = savedClassification.Get<string>(s_ClassificationEdition);
if (classificationEdition != null) entIFCClassification.Set<string>(s_ClassificationEdition, classificationEdition);
Int32 classificationEditionDateDay = savedClassification.Get<Int32>(s_ClassificationEditionDate_Day);
Int32 classificationEditionDateMonth = savedClassification.Get<Int32>(s_ClassificationEditionDate_Month);
Int32 classificationEditionDateYear = savedClassification.Get<Int32>(s_ClassificationEditionDate_Year);
entIFCClassification.Set<Int32>(s_ClassificationEditionDate_Day, classificationEditionDateDay);
entIFCClassification.Set<Int32>(s_ClassificationEditionDate_Month, classificationEditionDateMonth);
entIFCClassification.Set<Int32>(s_ClassificationEditionDate_Year, classificationEditionDateYear);
string classificationLocation = savedClassification.Get<string>(s_ClassificationLocation);
if (classificationLocation != null) entIFCClassification.Set<string>(s_ClassificationLocation, classificationLocation);
classificationStorage.SetEntity(entIFCClassification);
oldDataToDelete.Add(oldData.Id);
}
if (oldDataToDelete.Count > 0)
document.Delete(oldDataToDelete);
transaction.Commit();
}
}
}
示例9: CreateObjects
//.........这里部分代码省略.........
XYZ faceVector;
if (obj.FaceOrientation != null)
{
faceVector = new XYZ(obj.FaceOrientation.X, obj.FaceOrientation.Y, obj.FaceOrientation.Z);
}
else
{
faceVector = XYZ.BasisZ;
}
Face face = FindFace(origin, normVector, doc);
if (face != null)
{
fi = doc.Create.NewFamilyInstance(face, origin, faceVector, symbol);
}
}
else
{
// typical hosted family. Can be wall, floor, roof or ceiling.
ElementId host = FindHost(origin, hostBehavior, doc);
if (host != null)
{
fi = doc.Create.NewFamilyInstance(origin, symbol, doc.GetElement(host), lvl, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
}
}
// Assign the parameters
SetParameters(fi, obj.Parameters, doc);
// Assign the GH InstanceGuid
AssignGuid(fi, uniqueId, instanceSchema, runId, nickName);
}
// delete the host finder
ElementId hostFinderFamily = hostFinder.Symbol.Family.Id;
doc.Delete(hostFinder.Id);
doc.Delete(hostFinderFamily);
hostFinder = null;
}
}
catch (Exception ex)
{
TaskDialog.Show("Error", ex.Message);
}
t.Commit();
}
}
else
{
TaskDialog.Show("Error", "Could not find the desired family type");
}
}
#endregion
#region Adaptive Components
else if (ro.AdaptivePoints != null && ro.AdaptivePoints.Count > 0)
{
// Find the FamilySymbol
FamilySymbol symbol = FindFamilySymbol(ro.FamilyName, ro.TypeName, doc);
if (symbol != null)
{
using (Transaction t = new Transaction(doc, "Lyrebird Create Objects"))
{
t.Start();
try
{
// Create the Schema for the instances to store the GH Component InstanceGUID and the path
示例10: UpdateClassification
/// <summary>
/// Update the IFC Classification (from the UI) into the document.
/// </summary>
/// <param name="document">The document storing the saved Classification.</param>
/// <param name="fileHeaderItem">The Classification item to save.</param>
public static void UpdateClassification(Document document, IFCClassification classification)
{
// TO DO: To handle individual item and not the whole since in the future we may support multiple classification systems!!!
Schema schema = GetSchema();
if (schema != null)
{
IList<DataStorage> oldSavedClassification = GetClassificationInStorage(document, schema);
if (oldSavedClassification.Count > 0)
{
Transaction deleteTransaction = new Transaction(document, "Delete old IFC Classification");
deleteTransaction.Start();
List<ElementId> dataStorageToDelete = new List<ElementId>();
foreach (DataStorage dataStorage in oldSavedClassification)
{
dataStorageToDelete.Add(dataStorage.Id);
}
document.Delete(dataStorageToDelete);
deleteTransaction.Commit();
}
}
// Update the address using the new information
if (schema != null)
{
Transaction transaction = new Transaction(document, "Update saved IFC classification");
transaction.Start();
DataStorage classificationStorage = DataStorage.Create(document);
Entity entIFCClassification = new Entity(schema);
if (classification.ClassificationName != null) entIFCClassification.Set<string>(s_ClassificationName, classification.ClassificationName.ToString());
if (classification.ClassificationSource != null) entIFCClassification.Set<string>(s_ClassificationSource, classification.ClassificationSource.ToString());
if (classification.ClassificationEdition != null) entIFCClassification.Set<string>(s_ClassificationEdition, classification.ClassificationEdition.ToString());
if (classification.ClassificationEditionDate != null)
{
entIFCClassification.Set<Int32>(s_ClassificationEditionDate_Day, classification.ClassificationEditionDate.Day);
entIFCClassification.Set<Int32>(s_ClassificationEditionDate_Month, classification.ClassificationEditionDate.Month);
entIFCClassification.Set<Int32>(s_ClassificationEditionDate_Year, classification.ClassificationEditionDate.Year);
}
if (classification.ClassificationLocation != null) entIFCClassification.Set<string>(s_ClassificationLocation, classification.ClassificationLocation.ToString());
if (classification.ClassificationFieldName != null) entIFCClassification.Set<string>(s_ClassificationFieldName, classification.ClassificationFieldName.ToString());
classificationStorage.SetEntity(entIFCClassification);
transaction.Commit();
}
}
示例11: EndImport
/// <summary>
/// Perform end of import/link cleanup.
/// </summary>
/// <param name="doc">The document.</param>
/// <param name="fileName">The full path of the original IFC file.</param>
public void EndImport(Document doc, string fileName)
{
// Remove an unupdated Elements as a result of a reload operation.
try
{
// We are working around a limitation in deleting unused DirectShapeTypes.
IList<ElementId> otherElementsToDelete = new List<ElementId>();
IList<ElementId> typesToDelete = new List<ElementId>();
foreach (ElementId elementId in Importer.TheCache.GUIDToElementMap.Values)
{
if (DontDeleteSpecialElement(elementId))
continue;
Element element = doc.GetElement(elementId);
if (element == null)
continue;
if (element is DirectShapeType)
typesToDelete.Add(elementId);
else
otherElementsToDelete.Add(elementId);
}
foreach (ElementId elementId in Importer.TheCache.GridNameToElementMap.Values)
{
Element element = doc.GetElement(elementId);
if (element == null)
continue;
otherElementsToDelete.Add(elementId);
}
// Don't expect this to fail.
try
{
if (otherElementsToDelete.Count > 0)
doc.Delete(otherElementsToDelete);
}
catch (Exception ex)
{
TheLog.LogError(-1, ex.Message, false);
}
// Delete the temporary element we used for validation purposes.
IFCGeometryUtil.DeleteSolidValidator();
// This might fail.
if (typesToDelete.Count > 0)
doc.Delete(typesToDelete);
UpdateDocumentFileMetrics(doc, fileName);
}
catch // (Exception ex)
{
// Catch, but don't report, since this is an internal limitation in the API.
//TheLog.LogError(-1, ex.Message, false);
}
if (m_Transaction != null)
m_Transaction.Commit();
}
示例12: UpdateSavedConfigurations
/// <summary>
/// Updates the setups to save into the document.
/// </summary>
/// <param name="document">The document storing the saved configuration.</param>
public void UpdateSavedConfigurations(Document document)
{
// delete the old schema and the DataStorage.
if (m_schema == null)
{
m_schema = Schema.Lookup(s_schemaId);
}
if (m_schema != null)
{
IList<DataStorage> oldSavedConfigurations = GetSavedConfigurations(document, m_schema);
if (oldSavedConfigurations.Count > 0)
{
Transaction deleteTransaction = new Transaction(document, "Delete old IFC export setups");
deleteTransaction.Start();
List<ElementId> dataStorageToDelete = new List<ElementId>();
foreach (DataStorage dataStorage in oldSavedConfigurations)
{
dataStorageToDelete.Add(dataStorage.Id);
}
document.Delete(dataStorageToDelete);
deleteTransaction.Commit();
}
}
// update the configurations to new map schema.
if (m_mapSchema == null)
{
m_mapSchema = Schema.Lookup(s_mapSchemaId);
}
// Are there any setups to save or resave?
List<IFCExportConfiguration> setupsToSave = new List<IFCExportConfiguration>();
foreach (IFCExportConfiguration configuration in m_configurations.Values)
{
if (configuration.IsBuiltIn)
continue;
// Store in-session settings in the cached in-session configuration
if (configuration.IsInSession)
{
IFCExportConfiguration.SetInSession(configuration);
continue;
}
setupsToSave.Add(configuration);
}
// If there are no setups to save, and if the schema is not present (which means there are no
// previously existing setups which might have been deleted) we can skip the rest of this method.
if (setupsToSave.Count <= 0 && m_mapSchema == null)
return;
if (m_mapSchema == null)
{
SchemaBuilder builder = new SchemaBuilder(s_mapSchemaId);
builder.SetSchemaName("IFCExportConfigurationMap");
builder.AddMapField(s_configMapField, typeof(String), typeof(String));
m_mapSchema = builder.Finish();
}
// Overwrite all saved configs with the new list
Transaction transaction = new Transaction(document, "Update IFC export setups");
transaction.Start();
IList<DataStorage> savedConfigurations = GetSavedConfigurations(document, m_mapSchema);
int savedConfigurationCount = savedConfigurations.Count<DataStorage>();
int savedConfigurationIndex = 0;
foreach (IFCExportConfiguration configuration in setupsToSave)
{
DataStorage configStorage;
if (savedConfigurationIndex >= savedConfigurationCount)
{
configStorage = DataStorage.Create(document);
}
else
{
configStorage = savedConfigurations[savedConfigurationIndex];
savedConfigurationIndex ++;
}
Entity mapEntity = new Entity(m_mapSchema);
IDictionary<string, string> mapData = new Dictionary<string, string>();
mapData.Add(s_setupName, configuration.Name);
mapData.Add(s_setupDescription, configuration.Description);
mapData.Add(s_setupVersion, configuration.IFCVersion.ToString());
mapData.Add(s_setupFileFormat, configuration.IFCFileType.ToString());
mapData.Add(s_setupSpaceBoundaries, configuration.SpaceBoundaries.ToString());
mapData.Add(s_setupQTO, configuration.ExportBaseQuantities.ToString());
mapData.Add(s_setupCurrentView, configuration.VisibleElementsOfCurrentView.ToString());
mapData.Add(s_splitWallsAndColumns, configuration.SplitWallsAndColumns.ToString());
mapData.Add(s_setupExport2D, configuration.Export2DElements.ToString());
mapData.Add(s_setupExportRevitProps, configuration.ExportInternalRevitPropertySets.ToString());
mapData.Add(s_setupExportIFCCommonProperty, configuration.ExportIFCCommonPropertySets.ToString());
mapData.Add(s_setupUse2DForRoomVolume, configuration.Use2DRoomBoundaryForVolume.ToString());
mapData.Add(s_setupUseFamilyAndTypeName, configuration.UseFamilyAndTypeNameForReference.ToString());
mapData.Add(s_setupExportPartsAsBuildingElements, configuration.ExportPartsAsBuildingElements.ToString());
mapData.Add(s_setupExportSurfaceStyles, configuration.ExportSurfaceStyles.ToString());
//.........这里部分代码省略.........
示例13: Create
/// <summary>
/// Creates an IFCImportFile from a file on the disk.
/// </summary>
/// <param name="ifcFilePath">The path of the file.</param>
/// <param name="options">The IFC import options.</param>
/// <param name="doc">The optional document argument. If importing into Revit, not supplying a document may reduce functionality later.</param>
/// <returns>The IFCImportFile.</returns>
public static IFCImportFile Create(string ifcFilePath, IFCImportOptions options, Document doc)
{
m_sIFCImportFile = new IFCImportFile();
bool success = TheFile.Process(ifcFilePath, options, doc);
if (success)
{
// Store the original levels in the template file for Open IFC. On export, we will delete these levels if we created any.
// Note that we always have to preserve one level, regardless of what the ActiveView is.
// TODO: Only for open, not import.
if (doc != null)
{
IFCBuildingStorey.ExistingLevelIdToReuse = ElementId.InvalidElementId;
View activeView = doc.ActiveView;
if (activeView != null)
{
Level genLevel = activeView.GenLevel;
if (genLevel != null)
IFCBuildingStorey.ExistingLevelIdToReuse = genLevel.Id;
}
FilteredElementCollector levelCollector = new FilteredElementCollector(doc);
ICollection<Element> levels = levelCollector.OfClass(typeof(Level)).ToElements();
ICollection<ElementId> levelIdsToDelete = new HashSet<ElementId>();
foreach (Element level in levels)
{
if (IFCBuildingStorey.ExistingLevelIdToReuse == ElementId.InvalidElementId)
IFCBuildingStorey.ExistingLevelIdToReuse = level.Id;
else if (level.Id != IFCBuildingStorey.ExistingLevelIdToReuse)
levelIdsToDelete.Add(level.Id);
}
doc.Delete(levelIdsToDelete);
// Collect material names, to avoid reusing.
FilteredElementCollector materialCollector = new FilteredElementCollector(doc);
ICollection<Element> materials = materialCollector.OfClass(typeof(Material)).ToElements();
foreach (Element materialAsElem in materials)
{
Material material = materialAsElem as Material;
IFCMaterialInfo info = IFCMaterialInfo.Create(material.Color, material.Transparency, material.Shininess,
material.Smoothness, material.Id);
Importer.TheCache.CreatedMaterials.Add(material.Name, info);
}
}
}
else
{
// Close up the log file, set m_sIFCImportFile to null.
TheFile.Close();
}
return m_sIFCImportFile;
}
示例14: Flatten
Result Flatten(
Document doc,
ElementId viewId)
{
FilteredElementCollector col
= new FilteredElementCollector( doc, viewId )
.WhereElementIsNotElementType();
Options geometryOptions = new Options();
using( Transaction tx = new Transaction( doc ) )
{
if( tx.Start( "Convert elements to DirectShapes" )
== TransactionStatus.Started )
{
foreach( Element e in col )
{
GeometryElement gelt = e.get_Geometry(
geometryOptions );
if( null != gelt )
{
string appDataGUID = e.Id.ToString();
// Currently create direct shape
// replacement element in the original
// document – no API to properly transfer
// graphic styles to a new document.
// A possible enhancement: make a copy
// of the current project and operate
// on the copy.
//DirectShape ds = DirectShape.CreateElement(
// doc, e.Category.Id,
// _direct_shape_appGUID,
// appDataGUID ); // 2016
DirectShape ds = DirectShape.CreateElement(
doc, e.Category.Id ); //2017
ds.ApplicationId = _direct_shape_appGUID; // 2017
ds.ApplicationDataId = appDataGUID; // 2017
try
{
ds.SetShape(
new List<GeometryObject>( gelt ) );
// Delete original element
doc.Delete( e.Id );
}
catch( Autodesk.Revit.Exceptions
.ArgumentException ex )
{
Debug.Print(
"Failed to replace {0}; exception {1} {2}",
Util.ElementDescription( e ),
ex.GetType().FullName,
ex.Message );
}
}
}
tx.Commit();
}
}
return Result.Succeeded;
}
示例15: OpeningElementOpenings
private static void OpeningElementOpenings(
Document doc, double minOpeningValue)
{
FilteredElementCollector openingCollector =
new FilteredElementCollector(doc);
openingCollector.OfClass(typeof(Opening));
// Get the IList for the collector - we cannot delete
// elements using a collector iterator
IList<Element> openings =
openingCollector.ToList<Element>();
foreach (Opening open in openings)
{
// Open the host wall
Wall wall = open.Host as Wall;
if (wall == null) continue; //safety
// Get the original area to compare
double previousArea = wall.get_Parameter(
BuiltInParameter.HOST_AREA_COMPUTED).AsDouble();
// Delete the wall opening
doc.Delete(open);
doc.Regenerate();
// Get the new area to compare
double newArea = wall.get_Parameter(
BuiltInParameter.HOST_AREA_COMPUTED).AsDouble();
// So the instance opening equals:
double instanceAreaOnTheWall =
(newArea - previousArea);
if (instanceAreaOnTheWall <= minOpeningValue)
AddWallArea(wall.Id, instanceAreaOnTheWall, 0.0);
else
AddWallArea(wall.Id, 0.0, instanceAreaOnTheWall);
}
}