public RenderNodeAction OnElementBegin(ElementId inID) { m_stackElementId.Push(inID); // Category category = CurrentElement.get_Category(); //category.CategoryType == CategoryType. //bool _b = category != null && (category.get_Id().get_IntegerValue().Equals(-2001320) || category.get_Id().get_IntegerValue().Equals(-2000175) || category.get_Id().get_IntegerValue().Equals(-2000126)); // if () // { //this.ExportSolids(element); // return RenderNodeAction.Skip; // } // if (this.IsElementDecal(element)) //{ // //this.ExportDecal(element); // return RenderNodeAction.Skip; // } // if (CurrentElement.Category == ) // { String _name = CurrentElement.Category.Name + "_0_" + CurrentElement.Name; m_Exporter.BeginMesh(_name); return RenderNodeAction.Proceed; // } // else // return RenderNodeAction.Skip; }
public SpatialFieldUpdater(AddInId id, ElementId sphere, ElementId view) { addinID = id; sphereID = sphere; viewID = view; updaterID = new UpdaterId(addinID, new Guid("FBF2F6B2-4C06-42d4-97C1-D1B4EB593EFF")); }
/// <summary> /// Identifies if the host element can export when exporting parts. /// 1. If host element has non merged parts (>0), it can be export no matter if it has merged parts or not, and return true. /// 2. If host element has merged parts /// - If the merged part is the right category and not export yet, return true. /// - If the merged part is the right category but has been exported by other host, return false. /// - If the merged part is not the right category, should not export and return false. /// </summary> /// <param name="hostElement">The host element having parts.</param> /// <param name="levelId">The level the part would export.</param> /// <Param name="IsSplit">The bool flag identifies if the host element is split by story.</Param> /// <returns>True if the element can export, false otherwise.</returns> public static bool CanExportElementInPartExport(Element hostElement, ElementId levelId, bool IsSplit) { List<ElementId> associatedPartsList = PartUtils.GetAssociatedParts(hostElement.Document, hostElement.Id, false, true).ToList(); foreach (ElementId partId in associatedPartsList) { Part part = hostElement.Document.GetElement(partId) as Part; if (PartUtils.IsMergedPart(part)) { if (part.OriginalCategoryId == hostElement.Category.Id) { if (IsSplit) { if (!ExporterCacheManager.PartExportedCache.HasExported(partId, levelId)) { // has merged split part and not export yet. return true; } } else if (!ExporterCacheManager.PartExportedCache.HasRegistered(partId)) { // has merged part and not export yet. return true; } } } else { return true; } } // has no merged parts or other parts or merged parts have been exported. return false; }
/// <summary> /// Adds the IfcMaterialLayerSet handle to the dictionary. /// </summary> /// <param name="elementId"> /// The element elementId. /// </param> /// <param name="handle"> /// The IfcMaterialLayerSet handle. /// </param> public void Register(ElementId elementId, IFCAnyHandle handle) { if (m_ElementIdToMatLayerSetDictionary.ContainsKey(elementId)) return; m_ElementIdToMatLayerSetDictionary[elementId] = handle; }
/// <summary> /// Register the exported part and its host and level. /// </summary> /// <param name="partId">The exported part.</param> /// <param name="hostOverideLevels">The dictionary of host and level the part has exported.</param> public void Register(ElementId partId, Dictionary<ElementId, ElementId> hostOverideLevels) { if (HasRegistered(partId)) return; m_PartExportedDictionary[partId] = hostOverideLevels; }
/// <summary> /// Adds the IfcPresentationStyleAssignment handle to the dictionary. /// </summary> /// <param name="elementId"> /// The element elementId. /// </param> /// <param name="handle"> /// The IfcPresentationStyleAssignment handle. /// </param> public void Register(ElementId elementId, IFCAnyHandle handle) { if (m_Styles.ContainsKey(elementId.IntegerValue)) throw new Exception("TextStyleCache already contains handle for elementId " + elementId.IntegerValue); m_Styles[elementId.IntegerValue] = handle; }
/// <summary> /// Register the host element and its levels and ranges. /// </summary> /// <param name="hostId">The ElementId of host element.</param> /// <param name="levelRanges">The list of level and IFCRange pair.</param> public void Register(ElementId hostId, List<KeyValuePair<ElementId, IFCRange>> levelRanges) { if (HasRegistered(hostId)) return; m_DummyHostDictionary[hostId] = levelRanges; }
List<XYZ> GetBoundaryCorners( FilledRegion region ) { List<XYZ> result = new List<XYZ>(); ElementId id = new ElementId( region.Id.IntegerValue - 1 ); Sketch sketch = region.Document.GetElement( id ) as Sketch; if( null != sketch ) { CurveArray curves = sketch.Profile.get_Item( 0 ); if( null != curves ) { foreach( Curve cur in curves ) { XYZ corner = cur.GetEndPoint( 0 ); result.Add( corner ); } } } return result; }
/// <summary> /// Adds the list of parts to the dictionary. /// </summary> /// <param name="hostId"> /// The host element elementId. /// </param> /// <param name="partsList"> /// The list of parts. /// </param> public void Register(ElementId hostId, Dictionary<ElementId, List<KeyValuePair<Part, IFCRange>>> levelParts) { if (HasRegistered(hostId)) return; m_HostToPartsDictionary[hostId] = levelParts; }
public MenuUnsize() { ElementName = "menu"; Id = new ElementId(); controls = new Controls(); imageVisible = false; }
public Result OnStartup(UIControlledApplication a) { //Create Ribbon Panel add the UI button on start up RibbonPanel alignViewsPanel = ribbonPanel(a); //Register location updater with Revit. LocationUpdater updater = new LocationUpdater(a.ActiveAddInId); UpdaterRegistry.RegisterUpdater(updater, true); ElementCategoryFilter viewPortFilter = new ElementCategoryFilter(BuiltInCategory.OST_Viewports); ElementCategoryFilter viewFilter = new ElementCategoryFilter(BuiltInCategory.OST_Views); LogicalOrFilter filter = new LogicalOrFilter(viewPortFilter, viewFilter); //Parameter to send to the trigger. ElementClassFilter viewPort = new ElementClassFilter(typeof(Viewport)); ElementId viewPortNumberId = new ElementId(BuiltInParameter.VIEWPORT_DETAIL_NUMBER); //Set trigger UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), viewPort, Element.GetChangeTypeParameter(viewPortNumberId)); UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filter, Element.GetChangeTypeElementAddition()); //add buttons to ribbon addVRCommandButtons(alignViewsPanel); pushButton_Setting(alignViewsPanel); return Result.Succeeded; }
/// <summary> /// Adds the handle to the dictionary. /// </summary> /// <param name="elementId"> /// The element elementId. /// </param> /// <param name="handle"> /// The handle. /// </param> public void Register(ElementId elementId, IFCAnyHandle handle) { if (elementIdToHandleDictionary.ContainsKey(elementId)) return; elementIdToHandleDictionary[elementId] = handle; }
public Button() { ElementName = "button"; Id = new ElementId(); size = ControlSize.normal; imageVisible = false; showLabel = false; }
public SheetModelCollections( ElementId projectInfoId ) { ProjectInfoId = projectInfoId; SheetIds = new List<ElementId>(); ViewsInSheet = new Dictionary<ElementId, List<ViewData>>(); Symbols = new Dictionary<ElementId, GeomData>(); BimelsInViews = new Dictionary<ElementId, List<ObjData>>(); }
public EditBox() { ElementName = "editBox"; Id = new ElementId(); imageVisible = false; maxlength = 15; editBoxSize = maxlength; }
protected IFCMaterialInfo(Color color, int? transparency, int? shininess, int? smoothness, ElementId id) { Color = color; Transparency = transparency; Shininess = shininess; Smoothness = smoothness; ElementId = id; }
public ViewPortInfo(ElementId id, XYZ location, View v, Viewport vp) { this.id = id; this.location = location; this.view = v; this.vport = vp; }
/// <summary> /// True if the ElementId represents a valid phase. /// </summary> /// <returns>True if it is valid, false otherwise.</returns> static public bool Validate(ElementId phaseId) { if (phaseId == ElementId.InvalidElementId) return false; Element checkPhase = IFCCommandOverrideApplication.TheDocument.GetElement(phaseId); return (checkPhase != null && (checkPhase is Phase)); }
public ToggleButton() { ElementName = "toggleButton"; Id = new ElementId(); imageVisible = false; size = ControlSize.normal; showLabel = true; }
/// <summary> /// Finds the next level id, if any, of the level from the dictionary. /// </summary> /// <param name="elementId">The level element elementId.</param> /// <returns>The next level Id. Returns InvalidElementId if there is no entry in the cache.</returns> public ElementId FindNextLevel(ElementId elementId) { KeyValuePair<ElementId, double> info; if (elementIdToLevelHeight.TryGetValue(elementId, out info)) { return info.Key; } return ElementId.InvalidElementId; }
/// <summary> /// Find the levels and ranges of from a host element. /// </summary> /// <param name="hostId">The ElementId of host element.</param> /// <returns>The list of level and IFCRange pair.</returns> public List<KeyValuePair<ElementId, IFCRange>> Find(ElementId hostId) { List<KeyValuePair<ElementId, IFCRange>> levelRange; if (m_DummyHostDictionary.TryGetValue(hostId, out levelRange)) { return levelRange; } return null; }
/// <summary> /// Finds the IfcMaterialLayerSet handle from the dictionary. /// </summary> /// <param name="id"> /// The element id. /// </param> /// <returns> /// The IfcMaterialLayerSet handle. /// </returns> public IFCAnyHandle Find(ElementId id) { IFCAnyHandle handle; if (m_ElementIdToMatLayerSetDictionary.TryGetValue(id, out handle)) { return handle; } return null; }
/// <summary> /// Finds the height of the level from the dictionary. /// </summary> /// <param name="elementId">The level element elementId.</param> /// <returns>The height. Returns -1.0 if there is no entry in the cache, since valid entries must always be non-negative.</returns> public double FindHeight(ElementId elementId) { KeyValuePair<ElementId, double> info; if (elementIdToLevelHeight.TryGetValue(elementId, out info)) { return info.Value; } return -1.0; }
public DropDow() { data = new Items(); ElementName = "dropDown"; Id = new ElementId(); controls = new Controls(); imageVisible = false; dropDownSize = 7; }
/// <summary> /// Finds the IfcPresentationStyleAssignment handle from the dictionary. /// </summary> /// <param name="elementId"> /// The element elementId. /// </param> /// <returns> /// The IfcPresentationStyleAssignment handle. /// </returns> public IFCAnyHandle Find(ElementId elementId) { IFCAnyHandle handle; if (m_Styles.TryGetValue(elementId.IntegerValue, out handle)) { return handle; } return null; }
public ComboBox() { data = new Items(); ElementName = "comboBox"; Id = new ElementId(); imageVisible = false; maxLength = 7; comboBoxSize = maxLength; }
/// <summary> /// Finds the handle from the dictionary. /// </summary> /// <param name="elementId"> /// The element elementId. /// </param> /// <returns> /// The handle. /// </returns> public IFCAnyHandle Find(ElementId elementId) { IFCAnyHandle handle; if (elementIdToHandleDictionary.TryGetValue(elementId, out handle)) { return handle; } return null; }
public ParticleSpring(int ID, ElementId eid, Particle particleA, Particle particleB, double restLength, double springConstant, double damping) { m_ID = ID; m_ElementId = eid; m_particleA = particleA; m_particleB = particleB; m_restLength = restLength; m_springConstant = springConstant; m_Damping = damping; }
/// <summary> /// Adds a new property of a string value to the cache. /// </summary> /// <param name="parameterId">The parameter id. Can be null or InvalidElementId if propertyName != null.</param> /// <param name="propertyName">The property name. Can be null if elementId != InvalidElementId.</param> /// <param name="value">The value.</param> /// <param name="propertyHandle">The property handle.</param> public void Add(ElementId parameterId, string propertyName, string value, IFCAnyHandle propertyHandle) { if ((parameterId != null) && (parameterId != ElementId.InvalidElementId)) { ElementId parameterIdToUse = ParameterUtil.MapParameterId(parameterId); m_PropertiesByIdCache[new KeyValuePair<ElementId, string>(parameterIdToUse, value)] = propertyHandle; } else m_NamedPropertiesCache[new KeyValuePair<string, string>(propertyName, value)] = propertyHandle; }
/// <summary> /// Sets best material id for current export state. /// </summary> /// <param name="geometryObject">The geometry object to get the best material id.</param> /// <param name="element">The element to get its structual material if no material found in its geometry.</param> /// <param name="overrideMaterialId">The material id to override the one gets from geometry object.</param> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <returns>The material id.</returns> public static ElementId SetBestMaterialIdInExporter(GeometryObject geometryObject, Element element, ElementId overrideMaterialId, ExporterIFC exporterIFC) { ElementId materialId = overrideMaterialId != ElementId.InvalidElementId ? overrideMaterialId : GetBestMaterialIdFromGeometryOrParameter(geometryObject, exporterIFC, element); if (materialId != ElementId.InvalidElementId) exporterIFC.SetMaterialIdForCurrentExportState(materialId); return materialId; }
/// <summary> /// Exports a Rebar Coupler, /// </summary> /// <param name="exporterIFC">The exporter.</param> /// <param name="coupler">The RebarCoupler element.</param> /// <param name="productWrapper">The product wrapper.</param> public static void ExportCoupler(ExporterIFC exporterIFC, RebarCoupler coupler, ProductWrapper productWrapper) { if (coupler == null) { return; } FamilySymbol familySymbol = ExporterCacheManager.Document.GetElement(coupler.GetTypeId()) as FamilySymbol; if (familySymbol == null) { return; } ElementId categoryId = CategoryUtil.GetSafeCategoryId(coupler); IFCFile file = exporterIFC.GetFile(); IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle; Options options = GeometryUtil.GetIFCExportGeometryOptions();; string ifcEnumType; IFCExportType exportType = ExporterUtil.GetExportType(exporterIFC, coupler, out ifcEnumType); using (IFCTransaction tr = new IFCTransaction(file)) { FamilyTypeInfo currentTypeInfo = ExporterCacheManager.TypeObjectsCache.Find(coupler.GetTypeId(), false, exportType); bool found = currentTypeInfo.IsValid(); if (!found) { string typeGUID = GUIDUtil.CreateGUID(familySymbol); string typeName = NamingUtil.GetIFCName(familySymbol); string typeObjectType = NamingUtil.CreateIFCObjectName(exporterIFC, familySymbol); string applicableOccurance = NamingUtil.GetObjectTypeOverride(familySymbol, typeObjectType); string typeDescription = NamingUtil.GetDescriptionOverride(familySymbol, null); string typeElemId = NamingUtil.CreateIFCElementId(familySymbol); HashSet <IFCAnyHandle> propertySetsOpt = new HashSet <IFCAnyHandle>(); GeometryElement exportGeometry = familySymbol.get_Geometry(options); BodyData bodyData = null; BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow); bodyData = BodyExporter.ExportBody(exporterIFC, coupler, categoryId, ElementId.InvalidElementId, exportGeometry, bodyExporterOptions, null); List <IFCAnyHandle> repMap = new List <IFCAnyHandle>(); IFCAnyHandle origin = ExporterUtil.CreateAxis2Placement3D(file);; repMap.Add(IFCInstanceExporter.CreateRepresentationMap(file, origin, bodyData.RepresentationHnd)); IFCAnyHandle styleHandle = FamilyExporterUtil.ExportGenericType(exporterIFC, exportType, ifcEnumType, typeGUID, typeName, typeDescription, applicableOccurance, propertySetsOpt, repMap, typeElemId, typeName, coupler, familySymbol); if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle)) { currentTypeInfo.Style = styleHandle; ExporterCacheManager.TypeObjectsCache.Register(coupler.GetTypeId(), false, exportType, currentTypeInfo); } } int nCouplerQuantity = coupler.GetCouplerQuantity(); if (nCouplerQuantity <= 0) { return; } ISet <IFCAnyHandle> createdRebarCouplerHandles = new HashSet <IFCAnyHandle>(); string origInstanceName = NamingUtil.GetNameOverride(coupler, NamingUtil.GetIFCName(coupler)); for (int idx = 0; idx < nCouplerQuantity; idx++) { string instanceGUID = GUIDUtil.CreateSubElementGUID(coupler, idx); string instanceName = NamingUtil.GetNameOverride(coupler, origInstanceName + ": " + idx); string objectType = NamingUtil.CreateIFCObjectName(exporterIFC, coupler); string instanceObjectType = NamingUtil.GetObjectTypeOverride(coupler, objectType); string instanceDescription = NamingUtil.GetDescriptionOverride(coupler, null); string instanceElemId = NamingUtil.CreateIFCElementId(coupler); string instanceTag = NamingUtil.GetTagOverride(coupler, NamingUtil.CreateIFCElementId(coupler)); IFCAnyHandle style = currentTypeInfo.Style; if (IFCAnyHandleUtil.IsNullOrHasNoValue(style)) { return; } IList <IFCAnyHandle> repMapList = GeometryUtil.GetRepresentationMaps(style); if (repMapList == null) { return; } if (repMapList.Count == 0) { return; } IList <IFCAnyHandle> shapeReps = new List <IFCAnyHandle>(); IFCAnyHandle contextOfItems3d = exporterIFC.Get3DContextHandle("Body"); ISet <IFCAnyHandle> representations = new HashSet <IFCAnyHandle>(); representations.Add(ExporterUtil.CreateDefaultMappedItem(file, repMapList[0], XYZ.Zero)); IFCAnyHandle shapeRep = RepresentationUtil.CreateBodyMappedItemRep(exporterIFC, coupler, categoryId, contextOfItems3d, representations); shapeReps.Add(shapeRep); IFCAnyHandle productRepresentation = IFCInstanceExporter.CreateProductDefinitionShape(exporterIFC.GetFile(), null, null, shapeReps); Transform trf = coupler.GetCouplerPositionTransform(idx); using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, coupler, trf, null)) { IFCAnyHandle instanceHandle = null; instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(Common.Enums.IFCEntityType.IfcMechanicalFastener, file, instanceGUID, ownerHistory, instanceName, instanceDescription, instanceObjectType, setter.LocalPlacement, productRepresentation, instanceTag); if (ExporterCacheManager.ExportOptionsCache.ExportAs4) { // In IFC4 NominalDiameter and NominalLength attributes have been deprecated. PredefinedType attribute was added. IFCAnyHandleUtil.SetAttribute(instanceHandle, "PredefinedType", Revit.IFC.Export.Toolkit.IFC4.IFCMechanicalFastenerType.USERDEFINED); } else { IFCAnyHandleUtil.SetAttribute(instanceHandle, "NominalDiameter", familySymbol.get_Parameter(BuiltInParameter.COUPLER_WIDTH).AsDouble()); IFCAnyHandleUtil.SetAttribute(instanceHandle, "NominalLength", familySymbol.get_Parameter(BuiltInParameter.COUPLER_LENGTH).AsDouble()); } createdRebarCouplerHandles.Add(instanceHandle); productWrapper.AddElement(coupler, instanceHandle, setter, null, true); } } string couplerGUID = GUIDUtil.CreateGUID(coupler); if (nCouplerQuantity > 1) { // Create a group to hold all of the created IFC entities, if the coupler aren't already in an assembly. // We want to avoid nested groups of groups of couplers. if (coupler.AssemblyInstanceId == ElementId.InvalidElementId) { string revitObjectType = exporterIFC.GetFamilyName(); string name = NamingUtil.GetNameOverride(coupler, revitObjectType); string description = NamingUtil.GetDescriptionOverride(coupler, null); string objectType = NamingUtil.GetObjectTypeOverride(coupler, revitObjectType); IFCAnyHandle rebarGroup = IFCInstanceExporter.CreateGroup(file, couplerGUID, ownerHistory, name, description, objectType); productWrapper.AddElement(coupler, rebarGroup); IFCInstanceExporter.CreateRelAssignsToGroup(file, GUIDUtil.CreateGUID(), ownerHistory, null, null, createdRebarCouplerHandles, null, rebarGroup); } } else { // We will update the GUID of the one created element to be the element GUID. // This will allow the IfcGUID parameter to be use/set if appropriate. ExporterUtil.SetGlobalId(createdRebarCouplerHandles.ElementAt(0), couplerGUID); } tr.Commit(); } }
/// <summary> /// Creates a SweptSolid, Brep, SolidModel or SurfaceModel product definition shape representation, based on the geometry and IFC version. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="categoryId">The category id.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="bodyExporterOptions">The body exporter options.</param> /// <param name="extraReps">Extra representations (e.g. Axis, Boundary). May be null.</param> /// <param name="extrusionCreationData">The extrusion creation data.</param> /// <param name="bodyData">The body data.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateAppropriateProductDefinitionShape(ExporterIFC exporterIFC, Element element, ElementId categoryId, GeometryElement geometryElement, BodyExporterOptions bodyExporterOptions, IList <IFCAnyHandle> extraReps, IFCExtrusionCreationData extrusionCreationData, out BodyData bodyData) { bodyData = null; SolidMeshGeometryInfo info = null; IList <GeometryObject> geometryList = new List <GeometryObject>(); if (!ExporterCacheManager.ExportOptionsCache.ExportAs2x2) { info = GeometryUtil.GetSplitSolidMeshGeometry(geometryElement, Transform.Identity); IList <Mesh> meshes = info.GetMeshes(); if (meshes.Count == 0) { IList <Solid> solidList = info.GetSolids(); foreach (Solid solid in solidList) { geometryList.Add(solid); } } } if (geometryList.Count == 0) { geometryList.Add(geometryElement); } else { bodyExporterOptions.TryToExportAsExtrusion = true; } bodyData = BodyExporter.ExportBody(exporterIFC, element, categoryId, ElementId.InvalidElementId, geometryList, bodyExporterOptions, extrusionCreationData); IFCAnyHandle bodyRep = bodyData.RepresentationHnd; List <IFCAnyHandle> bodyReps = new List <IFCAnyHandle>(); if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRep)) { if (extrusionCreationData != null) { extrusionCreationData.ClearOpenings(); } } else { bodyReps.Add(bodyRep); } if (extraReps != null) { foreach (IFCAnyHandle hnd in extraReps) { bodyReps.Add(hnd); } } Transform boundingBoxTrf = (bodyData.OffsetTransform != null) ? bodyData.OffsetTransform.Inverse : Transform.Identity; IFCAnyHandle boundingBoxRep = BoundingBoxExporter.ExportBoundingBox(exporterIFC, geometryElement, boundingBoxTrf); if (boundingBoxRep != null) { bodyReps.Add(boundingBoxRep); } if (bodyReps.Count == 0) { return(null); } return(IFCInstanceExporter.CreateProductDefinitionShape(exporterIFC.GetFile(), null, null, bodyReps)); }
/// <summary> /// Creates a Brep representation. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="categoryId">The category id.</param> /// <param name="contextOfItems">The context for which the different subtypes of representation are valid.</param> /// <param name="bodyItems">Set of geometric representation items that are defined for this representation.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateBRepRep(ExporterIFC exporterIFC, Element element, ElementId categoryId, IFCAnyHandle contextOfItems, ISet <IFCAnyHandle> bodyItems) { string identifierOpt = "Body"; // this is by IFC2x2 convention, not temporary string repTypeOpt = ShapeRepresentationType.Brep.ToString(); // this is by IFC2x2 convention, not temporary IFCAnyHandle bodyRepresentation = CreateShapeRepresentation(exporterIFC, element, categoryId, contextOfItems, identifierOpt, repTypeOpt, bodyItems); return(bodyRepresentation); }
CollectEvent(object sender, CollectorEventArgs e) { // cast the sender object to the SnoopCollector we are expecting Collector snoopCollector = sender as Collector; if (snoopCollector == null) { Debug.Assert(false); // why did someone else send us the message? return; } // see if it is a type we are responsible for Color color = e.ObjToSnoop as Color; if (color != null) { Stream(snoopCollector.Data(), color); return; } LayoutRule layoutRule = e.ObjToSnoop as LayoutRule; if (layoutRule != null) { Stream(snoopCollector.Data(), layoutRule); return; } FormatOptions formatOptions = e.ObjToSnoop as FormatOptions; if (formatOptions != null) { Stream(snoopCollector.Data(), formatOptions); return; } CurtainGrid curtainGrid = e.ObjToSnoop as CurtainGrid; if (curtainGrid != null) { Stream(snoopCollector.Data(), curtainGrid); return; } CurtainCell curtainCell = e.ObjToSnoop as CurtainCell; if (curtainCell != null) { Stream(snoopCollector.Data(), curtainCell); return; } RebarHostData rebarHostData = e.ObjToSnoop as RebarHostData; if (rebarHostData != null) { Stream(snoopCollector.Data(), rebarHostData); return; } Leader leader = e.ObjToSnoop as Leader; if (leader != null) { Stream(snoopCollector.Data(), leader); return; } AreaVolumeSettings areaSettings = e.ObjToSnoop as AreaVolumeSettings; if (areaSettings != null) { Stream(snoopCollector.Data(), areaSettings); return; } ViewSheetSetting viewSheetSetting = e.ObjToSnoop as ViewSheetSetting; if (viewSheetSetting != null) { Stream(snoopCollector.Data(), viewSheetSetting); return; } Autodesk.Revit.UI.Events.DialogBoxData dlgBoxData = e.ObjToSnoop as Autodesk.Revit.UI.Events.DialogBoxData; if (dlgBoxData != null) { Stream(snoopCollector.Data(), dlgBoxData); return; } Construction construct = e.ObjToSnoop as Construction; if (construct != null) { Stream(snoopCollector.Data(), construct); return; } FamilyElementVisibility famElemVisib = e.ObjToSnoop as FamilyElementVisibility; if (famElemVisib != null) { Stream(snoopCollector.Data(), famElemVisib); return; } FamilyManager famManager = e.ObjToSnoop as FamilyManager; if (famManager != null) { Stream(snoopCollector.Data(), famManager); return; } FamilyParameter famParam = e.ObjToSnoop as FamilyParameter; if (famParam != null) { Stream(snoopCollector.Data(), famParam); return; } FamilyType famType = e.ObjToSnoop as FamilyType; if (famType != null) { Stream(snoopCollector.Data(), famType); return; } MEPSpaceConstruction mepSpaceConstuct = e.ObjToSnoop as MEPSpaceConstruction; if (mepSpaceConstuct != null) { Stream(snoopCollector.Data(), mepSpaceConstuct); return; } BuildingSiteExportOptions bldSiteExpOptions = e.ObjToSnoop as BuildingSiteExportOptions; if (bldSiteExpOptions != null) { Stream(snoopCollector.Data(), bldSiteExpOptions); return; } DGNExportOptions dgnExpOptions = e.ObjToSnoop as DGNExportOptions; if (dgnExpOptions != null) { Stream(snoopCollector.Data(), dgnExpOptions); return; } DWFExportOptions dwfExpOptions = e.ObjToSnoop as DWFExportOptions; if (dwfExpOptions != null) { Stream(snoopCollector.Data(), dwfExpOptions); return; } DWGExportOptions dwgExpOptions = e.ObjToSnoop as DWGExportOptions; if (dwgExpOptions != null) { Stream(snoopCollector.Data(), dwgExpOptions); return; } DWGImportOptions dwgImpOptions = e.ObjToSnoop as DWGImportOptions; if (dwgImpOptions != null) { Stream(snoopCollector.Data(), dwgImpOptions); return; } FBXExportOptions fbxExpOptions = e.ObjToSnoop as FBXExportOptions; if (fbxExpOptions != null) { Stream(snoopCollector.Data(), fbxExpOptions); return; } TrussMemberInfo trussInfo = e.ObjToSnoop as TrussMemberInfo; if (trussInfo != null) { Stream(snoopCollector.Data(), trussInfo); return; } VertexIndexPair vertIndPair = e.ObjToSnoop as VertexIndexPair; if (vertIndPair != null) { Stream(snoopCollector.Data(), vertIndPair); return; } PointElementReference ptElemRef = e.ObjToSnoop as PointElementReference; if (ptElemRef != null) { Stream(snoopCollector.Data(), ptElemRef); return; } Autodesk.Revit.DB.BoundarySegment boundSeg = e.ObjToSnoop as Autodesk.Revit.DB.BoundarySegment; if (boundSeg != null) { Stream(snoopCollector.Data(), boundSeg); return; } PointLocationOnCurve ptLocOnCurve = e.ObjToSnoop as PointLocationOnCurve; if (ptLocOnCurve != null) { Stream(snoopCollector.Data(), ptLocOnCurve); return; } Entity entity = e.ObjToSnoop as Entity; if (entity != null) { Stream(snoopCollector.Data(), entity); return; } Field field = e.ObjToSnoop as Field; if (field != null) { Stream(snoopCollector.Data(), field); return; } ExtensibleStorageField storeagefield = e.ObjToSnoop as ExtensibleStorageField; if (storeagefield != null) { Stream(snoopCollector.Data(), storeagefield); return; } IList <Autodesk.Revit.DB.BoundarySegment> boundSegs = e.ObjToSnoop as IList <Autodesk.Revit.DB.BoundarySegment>; if (boundSegs != null) { Stream(snoopCollector.Data(), boundSegs); return; } if (e.ObjToSnoop is KeyValuePair <String, String> ) { KeyValuePair <String, String> stringspair = (KeyValuePair <String, String>)e.ObjToSnoop; Stream(snoopCollector.Data(), stringspair); return; } Schema schema = e.ObjToSnoop as Schema; if (schema != null) { Stream(snoopCollector.Data(), schema); return; } ElementId elemId = e.ObjToSnoop as ElementId; if (elemId != null) { Stream(snoopCollector.Data(), elemId); return; } PlanViewRange plvr = e.ObjToSnoop as PlanViewRange; if (plvr != null) { Stream(snoopCollector.Data(), plvr); return; } //TF RebarConstraintsManager rbcm = e.ObjToSnoop as RebarConstraintsManager; if (rbcm != null) { Stream(snoopCollector.Data(), rbcm); return; } RebarConstrainedHandle rbch = e.ObjToSnoop as RebarConstrainedHandle; if (rbch != null) { Stream(snoopCollector.Data(), rbch); return; } RebarConstraint rbc = e.ObjToSnoop as RebarConstraint; if (rbc != null) { Stream(snoopCollector.Data(), rbc); return; } //TFEND if (Utils.IsSupportedType(e.ObjToSnoop) && e.ObjToSnoop != null) { Utils.StreamWithReflection(snoopCollector.Data(), e.ObjToSnoop.GetType(), e.ObjToSnoop); } }
/// <summary> /// Create advanced Brep body representation /// </summary> /// <param name="exporterIFC">the ExporterIFC object</param> /// <param name="element">the Element</param> /// <param name="categoryId">The Category Id</param> /// <param name="contextOfItems">The context for which the different subtypes of representation are valid.</param> /// <param name="bodyItems">Set of geometric representation items that are defined for this representation.</param> /// <param name="originalRepresentation">The original shape representation.</param> /// <returns></returns> public static IFCAnyHandle CreateAdvancedBRepRep(ExporterIFC exporterIFC, Element element, ElementId categoryId, IFCAnyHandle contextOfItems, ISet <IFCAnyHandle> bodyItems, IFCAnyHandle originalRepresentation) { string identifierOpt = "Body"; string repTypeOpt = ShapeRepresentationType.AdvancedBrep.ToString(); IFCAnyHandle bodyRepresentation = CreateOrAppendShapeRepresentation(exporterIFC, element, categoryId, contextOfItems, identifierOpt, repTypeOpt, bodyItems, originalRepresentation); return(bodyRepresentation); }
/// <summary> /// Exports an element as building element proxy. /// </summary> /// <remarks> /// This function is called from the Export function, but can also be called directly if you do not /// want CreateInternalPropertySets to be called. /// </remarks> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="element">The element.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> /// <returns>The handle if created, null otherwise.</returns> public static IFCAnyHandle ExportSimpleGenericElement(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, ProductWrapper productWrapper, IFCExportInfoPair exportType) { if (element == null || geometryElement == null) { return(null); } // Check the intended IFC entity or type name is in the exclude list specified in the UI if (exportType.ExportInstance == IFCEntityType.UnKnown) { exportType.SetValueWithPair(IFCEntityType.IfcBuildingElementProxy, exportType.ValidatedPredefinedType); } if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(exportType.ExportInstance)) { return(null); } // Check for containment override IFCAnyHandle overrideContainerHnd = null; ElementId overrideContainerId = ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainerHnd); IFCFile file = exporterIFC.GetFile(); IFCAnyHandle instanceHandle = null; using (IFCTransaction tr = new IFCTransaction(file)) { using (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, element, null, null, overrideContainerId, overrideContainerHnd)) { using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData()) { ecData.SetLocalPlacement(placementSetter.LocalPlacement); ElementId categoryId = CategoryUtil.GetSafeCategoryId(element); BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow); IFCAnyHandle representation = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC, element, categoryId, geometryElement, bodyExporterOptions, null, ecData, true); if (IFCAnyHandleUtil.IsNullOrHasNoValue(representation)) { ecData.ClearOpenings(); return(null); } string guid = GUIDUtil.CreateGUID(element); IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle; IFCAnyHandle localPlacement = ecData.GetLocalPlacement(); IFCAnyHandle styleHandle = null; instanceHandle = FamilyExporterUtil.ExportGenericInstance(exportType, exporterIFC, element, productWrapper, placementSetter, ecData, guid, ownerHistory, representation, null); if (exportType.ExportType != IFCEntityType.UnKnown) { FamilySymbol familySymbol = (element as FamilyInstance)?.Symbol; if (familySymbol != null) { HashSet <IFCAnyHandle> propertySetsOpt = new HashSet <IFCAnyHandle>(); IList <IFCAnyHandle> repMapListOpt = new List <IFCAnyHandle>(); string typeGuid = FamilyExporterUtil.GetGUIDForFamilySymbol(element as FamilyInstance, familySymbol); styleHandle = FamilyExporterUtil.ExportGenericType(exporterIFC, exportType, exportType.ValidatedPredefinedType, propertySetsOpt, repMapListOpt, element, familySymbol, typeGuid); productWrapper.RegisterHandleWithElementType(familySymbol, exportType, styleHandle, propertySetsOpt); } if (IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle)) { styleHandle = ExporterUtil.CreateGenericTypeFromElement(element, exportType, file, ownerHistory, exportType.ValidatedPredefinedType, productWrapper); } } if (!IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle)) { if (exportType.ExportInstance == IFCEntityType.IfcSpace) { productWrapper.AddSpace(element, instanceHandle, placementSetter.LevelInfo, ecData, true, exportType); } else { productWrapper.AddElement(element, instanceHandle, placementSetter.LevelInfo, ecData, true, exportType); } if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle)) { ExporterCacheManager.TypeRelationsCache.Add(styleHandle, instanceHandle); } } } tr.Commit(); } } return(instanceHandle); }
private static bool ExportGenericElementAsMappedItem(ExporterIFC exporterIFC, Element element, GeometryElement geomElem, IFCExportInfoPair exportType, ProductWrapper wrapper) { GeometryInstance geometryInstance = GetTheGeometryInstance(geomElem); if (geometryInstance == null) { return(false); } GeometryElement exportGeometry = geometryInstance.GetSymbolGeometry(); if (exportGeometry == null) { return(false); } ElementId symbolId = geometryInstance.GetSymbolGeometryId()?.SymbolId ?? ElementId.InvalidElementId; ElementType elementType = element.Document.GetElement(symbolId) as ElementType; if (elementType == null) { return(false); } Transform originalTrf = geometryInstance.Transform; // Can't handle mirrored transforms yet. if (originalTrf.HasReflection) { return(false); } ElementId categoryId = CategoryUtil.GetSafeCategoryId(element); IFCFile file = exporterIFC.GetFile(); IList <Transform> repMapTrfList = new List <Transform>(); BodyData bodyData = null; FamilyTypeInfo typeInfo = new FamilyTypeInfo(); IFCExtrusionCreationData extraParams = typeInfo.extraParams; Transform offsetTransform = Transform.Identity; // We will create a new mapped type if we haven't already created the type. FamilyTypeInfo currentTypeInfo = ExporterCacheManager.FamilySymbolToTypeInfoCache.Find(symbolId, false, exportType); bool found = currentTypeInfo.IsValid(); if (!found) { IList <IFCAnyHandle> representations3D = new List <IFCAnyHandle>(); IFCAnyHandle dummyPlacement = ExporterUtil.CreateLocalPlacement(file, null, null); extraParams.SetLocalPlacement(dummyPlacement); using (TransformSetter trfSetter = TransformSetter.Create()) { BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(false, ExportOptionsCache.ExportTessellationLevel.ExtraLow); bodyData = BodyExporter.ExportBody(exporterIFC, element, categoryId, ExporterUtil.GetSingleMaterial(element), exportGeometry, bodyExporterOptions, extraParams); typeInfo.MaterialIdList = bodyData.MaterialIds; offsetTransform = bodyData.OffsetTransform; // This code does not handle openings yet. // The intention for this is FabricationParts and DirectShapes which do not // currently have opening. // If they can have openings in the future, we can add this. IFCAnyHandle bodyRepHnd = bodyData.RepresentationHnd; if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRepHnd) || extraParams.GetOpenings().Count > 0) { return(false); } representations3D.Add(bodyRepHnd); repMapTrfList.Add(null); } typeInfo.StyleTransform = ExporterIFCUtils.GetUnscaledTransform(exporterIFC, extraParams.GetLocalPlacement()); IFCAnyHandle typeStyle = FamilyInstanceExporter.CreateTypeEntityHandle(exporterIFC, ref typeInfo, null, representations3D, repMapTrfList, null, element, elementType, elementType, false, false, exportType, out HashSet <IFCAnyHandle> propertySets); if (!IFCAnyHandleUtil.IsNullOrHasNoValue(typeStyle)) { wrapper.RegisterHandleWithElementType(elementType, exportType, typeStyle, propertySets); typeInfo.Style = typeStyle; CategoryUtil.TryToCreateMaterialAssocation(exporterIFC, bodyData, elementType, element, exportGeometry, typeStyle, typeInfo); // Create other generic classification from ClassificationCode(s) ClassificationUtil.CreateClassification(exporterIFC, file, elementType, typeStyle); ClassificationUtil.CreateUniformatClassification(exporterIFC, file, elementType, typeStyle); } } if (found && !typeInfo.IsValid()) { typeInfo = currentTypeInfo; } // we'll pretend we succeeded, but we'll do nothing. if (!typeInfo.IsValid()) { return(false); } extraParams = typeInfo.extraParams; // We expect no openings, so always add to map. ExporterCacheManager.FamilySymbolToTypeInfoCache.Register(symbolId, false, exportType, typeInfo); XYZ scaledMapOrigin = XYZ.Zero; Transform scaledTrf = originalTrf.Multiply(typeInfo.StyleTransform); // create instance. IList <IFCAnyHandle> shapeReps = FamilyInstanceExporter.CreateShapeRepresentations(exporterIFC, file, element, categoryId, typeInfo, scaledMapOrigin); if (shapeReps == null) { return(false); } Transform boundingBoxTrf = (offsetTransform != null) ? offsetTransform.Inverse : Transform.Identity; boundingBoxTrf = boundingBoxTrf.Multiply(scaledTrf.Inverse); IFCAnyHandle boundingBoxRep = BoundingBoxExporter.ExportBoundingBox(exporterIFC, geomElem, boundingBoxTrf); if (boundingBoxRep != null) { shapeReps.Add(boundingBoxRep); } IFCAnyHandle repHnd = (shapeReps.Count > 0) ? IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps) : null; using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element, scaledTrf, null)) { IFCAnyHandle instanceHandle = null; IFCAnyHandle localPlacement = setter.LocalPlacement; bool materialAlreadyAssociated = false; // We won't create the instance if: // (1) we are exporting to CV2.0/RV, (2) we have no 2D, 3D, or bounding box geometry, and (3) we aren't exporting parts. if (!(repHnd == null && (ExporterCacheManager.ExportOptionsCache.ExportAsCoordinationView2 || ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView))) { string instanceGUID = GUIDUtil.CreateGUID(element); bool isChildInContainer = element.AssemblyInstanceId != ElementId.InvalidElementId; if (IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle)) { bool isBuildingElementProxy = ((exportType.ExportInstance == IFCEntityType.IfcBuildingElementProxy) || (exportType.ExportType == IFCEntityType.IfcBuildingElementProxyType)); ElementId roomId = setter.UpdateRoomRelativeCoordinates(element, out IFCAnyHandle localPlacementToUse); bool containedInSpace = (roomId != ElementId.InvalidElementId) && (exportType.ExportInstance != IFCEntityType.IfcSystemFurnitureElement); IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle; if (!isBuildingElementProxy) { instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(exportType, exporterIFC, element, instanceGUID, ownerHistory, localPlacementToUse, repHnd); } else { instanceHandle = IFCInstanceExporter.CreateBuildingElementProxy(exporterIFC, element, instanceGUID, ownerHistory, localPlacementToUse, repHnd, exportType.ValidatedPredefinedType); } bool associateToLevel = !containedInSpace && !isChildInContainer; wrapper.AddElement(element, instanceHandle, setter, extraParams, associateToLevel, exportType); if (containedInSpace) { ExporterCacheManager.SpaceInfoCache.RelateToSpace(roomId, instanceHandle); } } if (!IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle)) { if (ElementFilteringUtil.IsMEPType(exportType) || ElementFilteringUtil.ProxyForMEPType(element, exportType)) { ExporterCacheManager.MEPCache.Register(element, instanceHandle); } ExporterCacheManager.HandleToElementCache.Register(instanceHandle, element.Id); if (!materialAlreadyAssociated) { // Create material association for the instance only if the the istance geometry is different from the type // or the type does not have any material association IFCAnyHandle constituentSetHnd = ExporterCacheManager.MaterialSetCache.FindConstituentSetHnd(symbolId); if (IFCAnyHandleUtil.IsNullOrHasNoValue(constituentSetHnd) && bodyData != null && bodyData.RepresentationItemInfo != null && bodyData.RepresentationItemInfo.Count > 0) { CategoryUtil.CreateMaterialAssociationWithShapeAspect(exporterIFC, element, instanceHandle, bodyData.RepresentationItemInfo); } else { // Create material association in case if bodyData is null CategoryUtil.CreateMaterialAssociation(exporterIFC, instanceHandle, typeInfo.MaterialIdList); } } if (!IFCAnyHandleUtil.IsNullOrHasNoValue(typeInfo.Style)) { ExporterCacheManager.TypeRelationsCache.Add(typeInfo.Style, instanceHandle); } } } } return(true); }
/// <summary> /// Exports materials for host object. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="hostObject">The host object.</param> /// <param name="elemHnds">The host IFC handles.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> /// <param name="levelId">The level id.</param> /// <param name="direction">The IFCLayerSetDirection.</param> /// <param name="containsBRepGeometry">True if the geometry contains BRep geoemtry. If so, we will export an IfcMaterialList</param> /// <returns>True if exported successfully, false otherwise.</returns> public static bool ExportHostObjectMaterials(ExporterIFC exporterIFC, HostObject hostObject, IList <IFCAnyHandle> elemHnds, GeometryElement geometryElement, ProductWrapper productWrapper, ElementId levelId, Toolkit.IFCLayerSetDirection direction, bool containsBRepGeometry) { if (hostObject == null) { return(true); //nothing to do } if (elemHnds == null || (elemHnds.Count == 0)) { return(true); //nothing to do } IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { //if (productWrapper != null) // productWrapper.ClearFinishMaterials(); double scaledOffset = 0.0, scaledWallWidth = 0.0, wallHeight = 0.0; Wall wall = hostObject as Wall; if (wall != null) { scaledWallWidth = UnitUtil.ScaleLength(wall.Width); scaledOffset = -scaledWallWidth / 2.0; BoundingBoxXYZ boundingBox = wall.get_BoundingBox(null); if (boundingBox != null) { wallHeight = boundingBox.Max.Z - boundingBox.Min.Z; } } List <ElementId> matIds; IFCAnyHandle primaryMaterialHnd; IFCAnyHandle materialLayerSet = ExporterUtil.CollectMaterialLayerSet(exporterIFC, hostObject, productWrapper, out matIds, out primaryMaterialHnd); if (containsBRepGeometry && matIds.Count > 0) { foreach (IFCAnyHandle elemHnd in elemHnds) { CategoryUtil.CreateMaterialAssociation(exporterIFC, elemHnd, matIds); } } if (!IFCAnyHandleUtil.IsNullOrHasNoValue(materialLayerSet)) { // IfcMaterialLayerSetUsage is not supported for IfcWall, only IfcWallStandardCase. IFCAnyHandle layerSetUsage = null; for (int ii = 0; ii < elemHnds.Count; ii++) { IFCAnyHandle elemHnd = elemHnds[ii]; if (IFCAnyHandleUtil.IsNullOrHasNoValue(elemHnd)) { continue; } SpaceBoundingElementUtil.RegisterSpaceBoundingElementHandle(exporterIFC, elemHnd, hostObject.Id, levelId); if (containsBRepGeometry) { continue; } HashSet <IFCAnyHandle> relDecomposesSet = IFCAnyHandleUtil.GetRelDecomposes(elemHnd); IList <IFCAnyHandle> subElemHnds = null; if (relDecomposesSet != null && relDecomposesSet.Count == 1) { IFCAnyHandle relAggregates = relDecomposesSet.First(); if (IFCAnyHandleUtil.IsTypeOf(relAggregates, IFCEntityType.IfcRelAggregates)) { subElemHnds = IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(relAggregates, "RelatedObjects"); } } bool hasSubElems = (subElemHnds != null && subElemHnds.Count != 0); bool isRoof = IFCAnyHandleUtil.IsTypeOf(elemHnd, IFCEntityType.IfcRoof); bool isDisallowedWallType = (IFCAnyHandleUtil.IsTypeOf(elemHnd, IFCEntityType.IfcWall) && !ExporterCacheManager.ExportOptionsCache.ExportAs4); // Create IfcMaterialLayerSetUsage unless we have sub-elements, are exporting a Roof, or are exporting a pre-IFC4 IfcWall. if (!hasSubElems && !isRoof && !isDisallowedWallType) { if (layerSetUsage == null) { bool flipDirSense = true; if (wall != null) { // if we have flipped the center curve on export, we need to take that into account here. // We flip the center curve on export if it is an arc and it has a negative Z direction. LocationCurve locCurve = wall.Location as LocationCurve; if (locCurve != null) { Curve curve = locCurve.Curve; Transform lcs = Transform.Identity; bool curveFlipped = GeometryUtil.MustFlipCurve(lcs, curve); flipDirSense = !(wall.Flipped ^ curveFlipped); } } else if (hostObject is CeilingAndFloor) { flipDirSense = false; } double offsetFromReferenceLine = flipDirSense ? -scaledOffset : scaledOffset; IFCDirectionSense sense = flipDirSense ? IFCDirectionSense.Negative : IFCDirectionSense.Positive; layerSetUsage = IFCInstanceExporter.CreateMaterialLayerSetUsage(file, materialLayerSet, direction, sense, offsetFromReferenceLine); } ExporterCacheManager.MaterialLayerRelationsCache.Add(layerSetUsage, elemHnd); } else { if (hasSubElems) { foreach (IFCAnyHandle subElemHnd in subElemHnds) { if (!IFCAnyHandleUtil.IsNullOrHasNoValue(subElemHnd)) { ExporterCacheManager.MaterialLayerRelationsCache.Add(materialLayerSet, subElemHnd); } } } else if (!isRoof) { ExporterCacheManager.MaterialLayerRelationsCache.Add(materialLayerSet, elemHnd); } else if (primaryMaterialHnd != null) { ExporterCacheManager.MaterialLayerRelationsCache.Add(primaryMaterialHnd, elemHnd); } } } } tr.Commit(); return(true); } }
/// <summary> /// Create a schedule for a given property set. /// </summary> /// <param name="doc">The document.</param> /// <param name="element">The element being created.</param> /// <param name="parameterGroupMap">The parameters of the element. Cached for performance.</param> /// <param name="parametersCreated">The created parameters.</param> protected void CreateScheduleForPropertySet(Document doc, Element element, IFCParameterSetByGroup parameterGroupMap, ISet <string> parametersCreated) { if (parametersCreated.Count == 0) { return; } Category category = element.Category; if (category == null) { return; } ElementId categoryId = category.Id; bool elementIsType = (element is ElementType); Tuple <ElementId, bool, string> scheduleKey = new Tuple <ElementId, bool, string>(categoryId, elementIsType, Name); ISet <string> viewScheduleNames = Importer.TheCache.ViewScheduleNames; IDictionary <Tuple <ElementId, bool, string>, ElementId> viewSchedules = Importer.TheCache.ViewSchedules; ElementId viewScheduleId; if (!viewSchedules.TryGetValue(scheduleKey, out viewScheduleId)) { string scheduleName = scheduleKey.Item3; string scheduleTypeName = elementIsType ? " " + Resources.IFCTypeSchedule : string.Empty; int index = 1; while (viewScheduleNames.Contains(scheduleName)) { string indexString = (index > 1) ? " " + index.ToString() : string.Empty; scheduleName += " (" + category.Name + scheduleTypeName + indexString + ")"; index++; if (index > 1000) { Importer.TheLog.LogWarning(Id, "Too many property sets with the name " + scheduleKey.Item3 + ", no longer creating schedules with that name.", true); return; } } // Not all categories allow creating schedules. Skip these. ViewSchedule viewSchedule = null; try { viewSchedule = ViewSchedule.CreateSchedule(doc, scheduleKey.Item1); } catch { // Only try to create the schedule once per key. viewSchedules[scheduleKey] = ElementId.InvalidElementId; return; } if (viewSchedule != null) { viewSchedule.Name = scheduleName; viewSchedules[scheduleKey] = viewSchedule.Id; viewScheduleNames.Add(scheduleName); ElementId ifcGUIDId = new ElementId(elementIsType ? BuiltInParameter.IFC_TYPE_GUID : BuiltInParameter.IFC_GUID); string propertySetListName = elementIsType ? Resources.IFCTypeSchedule + " IfcPropertySetList" : "IfcPropertySetList"; IList <SchedulableField> schedulableFields = viewSchedule.Definition.GetSchedulableFields(); bool filtered = false; foreach (SchedulableField sf in schedulableFields) { string fieldName = sf.GetName(doc); if (parametersCreated.Contains(fieldName) || sf.ParameterId == ifcGUIDId) { viewSchedule.Definition.AddField(sf); } else if (!filtered && fieldName == propertySetListName) { // We want to filter the schedule for specifically those elements that have this property set assigned. ScheduleField scheduleField = viewSchedule.Definition.AddField(sf); scheduleField.IsHidden = true; ScheduleFilter filter = new ScheduleFilter(scheduleField.FieldId, ScheduleFilterType.Contains, "\"" + Name + "\""); viewSchedule.Definition.AddFilter(filter); filtered = true; } } } } return; }
/// <summary> /// Import an IFC file into a given document for Reference only. /// </summary> /// <param name="document">The host document for the import.</param> /// <param name="fullFileName">The full file name of the document.</param> /// <param name="options">The list of configurable options for this import.</param> public void ReferenceIFC(Document document, string fullFileName, IDictionary <String, String> options) { // An early check, based on the options set - if we are allowed to use an up-to-date existing file on disk, use it. m_ImportLog = IFCImportLog.CreateLog(fullFileName, "log.html"); Document originalDocument = document; Document ifcDocument = null; if (TheOptions.Action == IFCImportAction.Link) { string linkedFileName = IFCImportFile.GetRevitFileName(fullFileName); ifcDocument = LoadOrCreateLinkDocument(originalDocument, linkedFileName); if (ifcDocument == null) { return; } } else { ifcDocument = originalDocument; } bool useCachedRevitFile = DocumentUpToDate(ifcDocument, fullFileName); // In the case where the document is already opened as a link, but it has been updated on disk, // give the user a warning and use the cached value. if (!useCachedRevitFile && ifcDocument.IsLinked) { useCachedRevitFile = true; Importer.AddDelayedLinkError(BuiltInFailures.ImportFailures.IFCCantUpdateLinkedFile); } if (!useCachedRevitFile) { m_ImportCache = IFCImportCache.Create(ifcDocument, fullFileName); // Limit creating the cache to Link, but may either remove limiting or make it more restrict (reload only) later. if (TheOptions.Action == IFCImportAction.Link) { TheCache.CreateExistingElementMaps(ifcDocument); } // TheFile will contain the same value as the return value for this function. IFCImportFile.Create(fullFileName, m_ImportOptions, ifcDocument); } if (useCachedRevitFile || IFCImportFile.TheFile != null) { IFCImportFile theFile = IFCImportFile.TheFile; if (theFile != null) { if (theFile.IFCProject != null) { IFCObjectDefinition.CreateElement(ifcDocument, theFile.IFCProject); } // Also process any other entities to create. foreach (IFCObjectDefinition objDef in IFCImportFile.TheFile.OtherEntitiesToCreate) { IFCObjectDefinition.CreateElement(ifcDocument, objDef); } theFile.EndImport(ifcDocument, fullFileName); } if (TheOptions.Action == IFCImportAction.Link) { // If we have an original Revit link file name, don't create a new RevitLinkType - // we will use the existing one. bool useExistingType = (TheOptions.RevitLinkFileName != null); ElementId revitLinkTypeId = IFCImportFile.LinkInFile(fullFileName, ifcDocument, originalDocument, useExistingType, !useCachedRevitFile); } } if (m_ImportCache != null) { m_ImportCache.Reset(ifcDocument); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02e6: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Unknown result type (might be due to invalid IL or missing references) //IL_0301: Unknown result type (might be due to invalid IL or missing references) //IL_031d: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_033b: Unknown result type (might be due to invalid IL or missing references) //IL_033d: Unknown result type (might be due to invalid IL or missing references) //IL_0357: Unknown result type (might be due to invalid IL or missing references) //IL_0359: Unknown result type (might be due to invalid IL or missing references) //IL_035e: Unknown result type (might be due to invalid IL or missing references) //IL_03cd: Unknown result type (might be due to invalid IL or missing references) //IL_03d2: Unknown result type (might be due to invalid IL or missing references) //IL_03d5: Unknown result type (might be due to invalid IL or missing references) //IL_03d9: Unknown result type (might be due to invalid IL or missing references) //IL_03de: Unknown result type (might be due to invalid IL or missing references) //IL_03e0: Unknown result type (might be due to invalid IL or missing references) //IL_03e5: Unknown result type (might be due to invalid IL or missing references) //IL_03ef: Unknown result type (might be due to invalid IL or missing references) //IL_03fc: Unknown result type (might be due to invalid IL or missing references) //IL_0401: Unknown result type (might be due to invalid IL or missing references) //IL_0406: Unknown result type (might be due to invalid IL or missing references) //IL_0427: Unknown result type (might be due to invalid IL or missing references) //IL_0431: Unknown result type (might be due to invalid IL or missing references) //IL_0434: Unknown result type (might be due to invalid IL or missing references) //IL_0490: Unknown result type (might be due to invalid IL or missing references) //IL_0495: Unknown result type (might be due to invalid IL or missing references) //IL_0499: Unknown result type (might be due to invalid IL or missing references) //IL_049e: Unknown result type (might be due to invalid IL or missing references) //IL_04a2: Unknown result type (might be due to invalid IL or missing references) //IL_04a7: Unknown result type (might be due to invalid IL or missing references) //IL_04b1: Unknown result type (might be due to invalid IL or missing references) //IL_04c1: Unknown result type (might be due to invalid IL or missing references) //IL_04d1: Unknown result type (might be due to invalid IL or missing references) //IL_04f2: Unknown result type (might be due to invalid IL or missing references) //IL_04f3: Unknown result type (might be due to invalid IL or missing references) //IL_0505: Unknown result type (might be due to invalid IL or missing references) //IL_0509: Unknown result type (might be due to invalid IL or missing references) GlobalVar.G_commandData = commandData; UIApplication application = commandData.get_Application(); Document document = application.get_ActiveUIDocument().get_Document(); UIDocument activeUIDocument = application.get_ActiveUIDocument(); Application application2 = commandData.get_Application().get_Application(); View activeView = document.get_ActiveView(); GlobalVar.TypeORInstance = "Family Type"; Selection selection = application.get_ActiveUIDocument().get_Selection(); ICollection <ElementId> elementIds = selection.GetElementIds(); ICollection <ElementId> collection = new List <ElementId>(); List <Element> list = new List <Element>(); foreach (ElementId item in elementIds) { try { Element element = document.GetElement(item); ElementId typeId = element.GetTypeId(); Element element2 = document.GetElement(typeId); collection.Add(typeId); list.Add(element2); } catch { } } if (list.Count > 0) { DataSet dataSet = new DataSet(); DataSet dataSet2 = new DataSet(); List <ElementId> list2 = new List <ElementId>(); foreach (Element item2 in list) { try { list2.Add(item2.get_Category().get_Id()); } catch { } } List <ElementId> list3 = ((IEnumerable <ElementId>)list2).Distinct <ElementId>().ToList <ElementId>(); foreach (ElementId item3 in list3) { FilteredElementCollector val = new FilteredElementCollector(document, collection).OfCategoryId(item3); IList <Element> eleList = val.ToElements(); DataTable table = Method.ElementParameter2Table(commandData, eleList); DataTable table2 = Method.ParameterIsRead(commandData, eleList, document); dataSet.Tables.Add(table); dataSet2.Tables.Add(table2); } ParameterEventHandler parameterEventHandler = new ParameterEventHandler(); ElementOverrideEventHandler elementOverrideEventHandler = new ElementOverrideEventHandler(); ResetElementOverrideEventHandler resetElementOverrideEventHandler = new ResetElementOverrideEventHandler(); ExternalEvent g_exEvent = ExternalEvent.Create(parameterEventHandler); ExternalEvent g_exEvent2 = ExternalEvent.Create(elementOverrideEventHandler); ExternalEvent g_exEvent3 = ExternalEvent.Create(resetElementOverrideEventHandler); GlobalVar.G_handler = parameterEventHandler; GlobalVar.G_exEvent = g_exEvent; GlobalVar.G_handler1 = elementOverrideEventHandler; GlobalVar.G_exEvent1 = g_exEvent2; GlobalVar.G_handler3 = resetElementOverrideEventHandler; GlobalVar.G_exEvent3 = g_exEvent3; GlobalVar.MyDataSet = dataSet; GlobalVar.Is_Read_Only = dataSet2; HotGear_Parameter_Explorer hotGear_Parameter_Explorer = new HotGear_Parameter_Explorer(); hotGear_Parameter_Explorer.InitializeComponent(commandData, document); hotGear_Parameter_Explorer.Show(); } else { List <string> list4 = new List <string>(); foreach (Document document2 in application2.get_Documents()) { list4.Add(document2.get_Title()); } GlobalVar.G_Doc_Selection = list4; CategorySelection categorySelection = new CategorySelection(); categorySelection.InitializeComponent(commandData); categorySelection.ShowDialog(); List <Element> g_Ele = GlobalVar.G_Ele; List <string> g_Cat_Selection = GlobalVar.G_Cat_Selection; Document g_Sel_Doc = GlobalVar.G_Sel_Doc; ICollection <ElementId> g_Eleid = GlobalVar.G_Eleid; if (g_Cat_Selection == null) { return(0); } List <ElementId> list5 = new List <ElementId>(); foreach (Element item4 in g_Ele) { foreach (string item5 in g_Cat_Selection) { if (item4.get_Category().get_Name() == item5) { list5.Add(item4.get_Category().get_Id()); } } } DataSet dataSet3 = new DataSet(); DataSet dataSet4 = new DataSet(); List <ElementId> list6 = ((IEnumerable <ElementId>)list5).Distinct <ElementId>().ToList <ElementId>(); foreach (ElementId item6 in list6) { FilteredElementCollector val3 = new FilteredElementCollector(g_Sel_Doc, g_Eleid).OfCategoryId(item6); IList <Element> list7 = new List <Element>(); foreach (Element item7 in val3) { list7.Add(item7); } DataTable table3 = Method.ElementParameter2Table(commandData, list7); DataTable table4 = Method.ParameterIsRead(commandData, list7, g_Sel_Doc); dataSet3.Tables.Add(table3); dataSet4.Tables.Add(table4); } ParameterEventHandler parameterEventHandler2 = new ParameterEventHandler(); ElementOverrideEventHandler elementOverrideEventHandler2 = new ElementOverrideEventHandler(); ResetElementOverrideEventHandler resetElementOverrideEventHandler2 = new ResetElementOverrideEventHandler(); ExternalEvent g_exEvent4 = ExternalEvent.Create(parameterEventHandler2); ExternalEvent g_exEvent5 = ExternalEvent.Create(elementOverrideEventHandler2); ExternalEvent g_exEvent6 = ExternalEvent.Create(resetElementOverrideEventHandler2); GlobalVar.G_handler = parameterEventHandler2; GlobalVar.G_exEvent = g_exEvent4; GlobalVar.G_handler1 = elementOverrideEventHandler2; GlobalVar.G_exEvent1 = g_exEvent5; GlobalVar.G_handler3 = resetElementOverrideEventHandler2; GlobalVar.G_exEvent3 = g_exEvent6; GlobalVar.MyDataSet = dataSet3; GlobalVar.Is_Read_Only = dataSet4; HotGear_Parameter_Explorer hotGear_Parameter_Explorer2 = new HotGear_Parameter_Explorer(); hotGear_Parameter_Explorer2.InitializeComponent(commandData, g_Sel_Doc); hotGear_Parameter_Explorer2.Show(); } return(0); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; //// Select all pipes in the entire model. //List<Pipe> pipes = new List<Pipe>( // new FilteredElementCollector( doc ) // .OfClass( typeof( Pipe ) ) // .ToElements() // .Cast<Pipe>() ); //int n = pipes.Count; //// If there are less than two, //// there is nothing we can do. //if( 2 > n ) //{ // message = _prompt; // return Result.Failed; //} //// If there are exactly two, pick those. //if( 2 < n ) //{ // // Else, check for a pre-selection. // pipes.Clear(); // Selection sel = uidoc.Selection; // //n = sel.Elements.Size; // 2014 // ICollection<ElementId> ids // = sel.GetElementIds(); // 2015 // n = ids.Count; // 2015 // Debug.Print( "{0} pre-selected elements.", // n ); // // If two or more model pipes were pre- // // selected, use the first two encountered. // if( 1 < n ) // { // //foreach( Element e in sel.Elements ) // 2014 // foreach( ElementId id in ids ) // 2015 // { // Pipe c = doc.GetElement( id ) as Pipe; // if( null != c ) // { // pipes.Add( c ); // if( 2 == pipes.Count ) // { // Debug.Print( "Found two model pipes, " // + "ignoring everything else." ); // break; // } // } // } // } // // Else, prompt for an // // interactive post-selection. // if( 2 != pipes.Count ) // { // pipes.Clear(); // try // { // Reference r = sel.PickObject( // ObjectType.Element, // new PipeElementSelectionFilter(), // "Please pick first pipe." ); // pipes.Add( doc.GetElement( r.ElementId ) // as Pipe ); // } // catch( Autodesk.Revit.Exceptions // .OperationCanceledException ) // { // return Result.Cancelled; // } // try // { // Reference r = sel.PickObject( // ObjectType.Element, // new PipeElementSelectionFilter(), // "Please pick second pipe." ); // pipes.Add( doc.GetElement( r.ElementId ) // as Pipe ); // } // catch( Autodesk.Revit.Exceptions // .OperationCanceledException ) // { // return Result.Cancelled; // } // } //} JtPairPicker <Pipe> picker = new JtPairPicker <Pipe>(uidoc); Result rc = picker.Pick(); if (Result.Failed == rc) { message = _prompt; } if (Result.Succeeded != rc) { return(rc); } IList <Pipe> pipes = picker.Selected; // Check for same pipe system type. ElementId systemTypeId = pipes[0].MEPSystem.GetTypeId(); Debug.Assert(pipes[1].MEPSystem.GetTypeId() .IntegerValue.Equals( systemTypeId.IntegerValue), "expected two similar pipes"); // Check for same pipe level. ElementId levelId = pipes[0].LevelId; Debug.Assert( pipes[1].LevelId.IntegerValue.Equals( levelId.IntegerValue), "expected two pipes on same level"); // Extract data from the two selected pipes. double wall_thickness = GetWallThickness(pipes[0]); Debug.Print("{0} has wall thickness {1}", Util.ElementDescription(pipes[0]), Util.RealString(wall_thickness)); Curve c0 = pipes[0].GetCurve(); Curve c1 = pipes[1].GetCurve(); if (!(c0 is Line) || !(c1 is Line)) { message = _prompt + " Expected straight pipes."; return(Result.Failed); } XYZ p00 = c0.GetEndPoint(0); XYZ p01 = c0.GetEndPoint(1); XYZ p10 = c1.GetEndPoint(0); XYZ p11 = c1.GetEndPoint(1); XYZ v0 = p01 - p00; XYZ v1 = p11 - p10; if (!Util.IsParallel(v0, v1)) { message = _prompt + " Expected parallel pipes."; return(Result.Failed); } // Select the two pipe endpoints // that are farthest apart. XYZ p0 = p00.DistanceTo(p10) > p01.DistanceTo(p10) ? p00 : p01; XYZ p1 = p10.DistanceTo(p0) > p11.DistanceTo(p0) ? p10 : p11; XYZ pm = 0.5 * (p0 + p1); XYZ v = p1 - p0; if (Util.IsParallel(v, v0)) { message = "The selected pipes are colinear."; return(Result.Failed); } // Normal vector of the plane defined by the // two parallel and offset pipes, which is // the plane hosting the rolling offset XYZ z = v.CrossProduct(v1); // Vector perpendicular to v0 and v0 and // z, i.e. vector pointing from the first pipe // to the second in the cross sectional view. XYZ w = z.CrossProduct(v1).Normalize(); // Offset distance perpendicular to pipe direction double distanceAcross = Math.Abs( v.DotProduct(w)); // Distance between endpoints parallel // to pipe direction double distanceAlong = Math.Abs( v.DotProduct(v1.Normalize())); Debug.Assert(Util.IsEqual(v.GetLength(), Math.Sqrt(distanceAcross * distanceAcross + distanceAlong * distanceAlong)), "expected Pythagorean equality here"); // The required offset pipe angle. double angle = 45 * Math.PI / 180.0; // The angle on the other side. double angle2 = 0.5 * Math.PI - angle; double length = distanceAcross * Math.Tan(angle2); double halfLength = 0.5 * length; // How long should the pipe stubs become? double remainingPipeLength = 0.5 * (distanceAlong - length); if (0 > v1.DotProduct(v)) { v1.Negate(); } v1 = v1.Normalize(); XYZ q0 = p0 + remainingPipeLength * v1; XYZ q1 = p1 - remainingPipeLength * v1; using (Transaction tx = new Transaction(doc)) { // Determine pipe diameter for creating // matching pipes and fittings Pipe pipe = pipes[0]; double diameter = pipe .get_Parameter(bipDiameter) // "Diameter" .AsDouble(); // Pipe type for calls to doc.Create.NewPipe PipeType pipe_type_standard = new FilteredElementCollector(doc) .OfClass(typeof(PipeType)) .Cast <PipeType>() .Where <PipeType>(e => e.Name.Equals("Standard")) .FirstOrDefault <PipeType>(); Debug.Assert( pipe_type_standard.Id.IntegerValue.Equals( pipe.PipeType.Id.IntegerValue), "expected all pipes in this simple " + "model to use the same pipe type"); tx.Start("Rolling Offset"); if (_place_model_line) { // Trim or extend existing pipes (pipes[0].Location as LocationCurve).Curve = Line.CreateBound(p0, q0); (pipes[1].Location as LocationCurve).Curve = Line.CreateBound(p1, q1); // Add a model line for the rolling offset pipe Creator creator = new Creator(doc); Line line = Line.CreateBound(q0, q1); creator.CreateModelCurve(line); pipe = null; } else if (_place_fittings) { // Set active work plane to the rolling // offset plane... removed again, since // this has no effect at all on the // fitting placement or rotation. // //Plane plane = new Plane( z, q0 ); // //SketchPlane sp = SketchPlane.Create( // doc, plane ); // //uidoc.ActiveView.SketchPlane = sp; //uidoc.ActiveView.ShowActiveWorkPlane(); FamilySymbol symbol = new FilteredElementCollector(doc) .OfClass(typeof(FamilySymbol)) .OfCategory(BuiltInCategory.OST_PipeFitting) .Cast <FamilySymbol>() .Where <FamilySymbol>(e => e.Family.Name.Contains("Elbow - Generic")) .FirstOrDefault <FamilySymbol>(); // Set up first 45 degree elbow fitting FamilyInstance fitting0 = doc.Create .NewFamilyInstance(q0, symbol, StructuralType.NonStructural); fitting0.LookupParameter("Angle").Set( 45.0 * Math.PI / 180.0); //fitting0.get_Parameter( bipDiameter ) // does not exist // .Set( diameter ); fitting0.LookupParameter("Nominal Radius") .Set(0.5 * diameter); Line axis = Line.CreateBound(p0, q0); angle = z.AngleTo(XYZ.BasisZ); ElementTransformUtils.RotateElement( doc, fitting0.Id, axis, Math.PI - angle); Connector con0 = Util.GetConnectorClosestTo( fitting0, p0); // Trim or extend existing pipe (pipes[0].Location as LocationCurve).Curve = Line.CreateBound(p0, con0.Origin); // Connect pipe to fitting Util.Connect(con0.Origin, pipe, fitting0); // Set up second 45 degree elbow fitting FamilyInstance fitting1 = doc.Create .NewFamilyInstance(q1, symbol, StructuralType.NonStructural); //fitting1.get_Parameter( "Angle" ).Set( 45.0 * Math.PI / 180.0 ); // 2014 //fitting1.get_Parameter( "Nominal Radius" ).Set( 0.5 * diameter ); // 2014 fitting1.LookupParameter("Angle").Set(45.0 * Math.PI / 180.0); // 2015 fitting1.LookupParameter("Nominal Radius").Set(0.5 * diameter); // 2015 axis = Line.CreateBound( q1, q1 + XYZ.BasisZ); ElementTransformUtils.RotateElement( doc, fitting1.Id, axis, Math.PI); axis = Line.CreateBound(q1, p1); ElementTransformUtils.RotateElement( doc, fitting1.Id, axis, Math.PI - angle); Connector con1 = Util.GetConnectorClosestTo( fitting1, p1); (pipes[1].Location as LocationCurve).Curve = Line.CreateBound(con1.Origin, p1); Util.Connect(con1.Origin, fitting1, pipes[1]); con0 = Util.GetConnectorClosestTo( fitting0, pm); con1 = Util.GetConnectorClosestTo( fitting1, pm); // Connecting one fitting to the other does // not insert a pipe in between. If the // system is edited later, however, the two // fittings snap together. // //con0.ConnectTo( con1 ); // Create rolling offset pipe segment //pipe = doc.Create.NewPipe( con0.Origin, // 2014 // con1.Origin, pipe_type_standard ); pipe = Pipe.Create(doc, pipe_type_standard.Id, levelId, con0, con1); // 2015 pipe.get_Parameter(bipDiameter) .Set(diameter); // Connect rolling offset pipe segment // with elbow fittings at each end Util.Connect(con0.Origin, fitting0, pipe); Util.Connect(con1.Origin, pipe, fitting1); } else { if (_use_static_pipe_create) { // Element id arguments to Pipe.Create. ElementId idSystem; ElementId idType; ElementId idLevel; // All these values are invalid for idSystem: ElementId idSystem1 = pipe.MEPSystem.Id; ElementId idSystem2 = ElementId.InvalidElementId; ElementId idSystem3 = PipingSystem.Create( doc, pipe.MEPSystem.GetTypeId(), "Tbc") .Id; // This throws an argument exception saying // The systemTypeId is not valid piping system type. // Parameter name: systemTypeId //pipe = Pipe.Create( doc, idSystem, // idType, idLevel, q0, q1 ); // Retrieve pipe system type, e.g. // hydronic supply. PipingSystemType pipingSystemType = new FilteredElementCollector(doc) .OfClass(typeof(PipingSystemType)) .OfType <PipingSystemType>() .FirstOrDefault(st => st.SystemClassification == MEPSystemClassification .SupplyHydronic); if (null == pipingSystemType) { message = "Could not find hydronic supply piping system type"; return(Result.Failed); } idSystem = pipingSystemType.Id; Debug.Assert(pipe.get_Parameter( BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM) .AsElementId().IntegerValue.Equals( idSystem.IntegerValue), "expected same piping system element id"); // Retrieve the PipeType. PipeType pipeType = new FilteredElementCollector(doc) .OfClass(typeof(PipeType)) .OfType <PipeType>() .FirstOrDefault(); if (null == pipeType) { message = "Could not find pipe type"; return(Result.Failed); } idType = pipeType.Id; Debug.Assert(pipe.get_Parameter( BuiltInParameter.ELEM_TYPE_PARAM) .AsElementId().IntegerValue.Equals( idType.IntegerValue), "expected same pipe type element id"); Debug.Assert(pipe.PipeType.Id.IntegerValue .Equals(idType.IntegerValue), "expected same pipe type element id"); // Retrieve the reference level. // pipe.LevelId is not the correct source! idLevel = pipe.get_Parameter( BuiltInParameter.RBS_START_LEVEL_PARAM) .AsElementId(); // Create the rolling offset pipe. pipe = Pipe.Create(doc, idSystem, idType, idLevel, q0, q1); } else { //pipe = doc.Create.NewPipe( q0, q1, pipe_type_standard ); // 2014 pipe = Pipe.Create(doc, systemTypeId, pipe_type_standard.Id, levelId, q0, q1); // 2015 } pipe.get_Parameter(bipDiameter) .Set(diameter); // Connect rolling offset pipe segment // directly with the neighbouring original // pipes // //Util.Connect( q0, pipes[0], pipe ); //Util.Connect( q1, pipe, pipes[1] ); // NewElbowFitting performs the following: // - select appropriate fitting family and type // - place and orient a family instance // - set its parameters appropriately // - connect it with its neighbours Connector con0 = Util.GetConnectorClosestTo( pipes[0], q0); Connector con = Util.GetConnectorClosestTo( pipe, q0); doc.Create.NewElbowFitting(con0, con); Connector con1 = Util.GetConnectorClosestTo( pipes[1], q1); con = Util.GetConnectorClosestTo( pipe, q1); doc.Create.NewElbowFitting(con, con1); } tx.Commit(); } return(Result.Succeeded); }
/// <summary> /// Creates a shape representation and register it to shape representation layer. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="categoryId">The category id.</param> /// <param name="contextOfItems">The context for which the different subtypes of representation are valid.</param> /// <param name="identifier">The identifier for the representation.</param> /// <param name="representationType">The type handle for the representation.</param> /// <param name="items">Collection of geometric representation items that are defined for this representation.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateShapeRepresentation(ExporterIFC exporterIFC, Element element, ElementId categoryId, IFCAnyHandle contextOfItems, string identifier, string representationType, ISet <IFCAnyHandle> items) { IFCAnyHandle newShapeRepresentation = CreateBaseShapeRepresentation(exporterIFC, contextOfItems, identifier, representationType, items); if (IFCAnyHandleUtil.IsNullOrHasNoValue(newShapeRepresentation)) { return(newShapeRepresentation); } // Search for old "IFCCadLayer" or new "IfcPresentationLayer". string ifcCADLayer = null; if ((ParameterUtil.GetStringValueFromElementOrSymbol(element, "IFCCadLayer", out ifcCADLayer) == null) || string.IsNullOrWhiteSpace(ifcCADLayer)) { if ((ParameterUtil.GetStringValueFromElementOrSymbol(element, "IfcPresentationLayer", out ifcCADLayer) == null) || string.IsNullOrWhiteSpace(ifcCADLayer)) { ifcCADLayer = ExporterStateManager.GetCurrentCADLayerOverride(); } } // We are using the DWG export layer table to correctly map category to DWG layer for the // IfcPresentationLayerAsssignment, if it is not overridden. if (!string.IsNullOrWhiteSpace(ifcCADLayer)) { ExporterCacheManager.PresentationLayerSetCache.AddRepresentationToLayer(ifcCADLayer, newShapeRepresentation); } else { exporterIFC.RegisterShapeForPresentationLayer(element, categoryId, newShapeRepresentation); } return(newShapeRepresentation); }
/// <summary> /// Creates a shape representation and register it to shape representation layer. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="categoryId">The category id.</param> /// <param name="contextOfItems">The context for which the different subtypes of representation are valid.</param> /// <param name="identifierOpt">The identifier for the representation.</param> /// <param name="representationTypeOpt">The type handle for the representation.</param> /// <param name="items">List of geometric representation items that are defined for this representation.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateShapeRepresentation(ExporterIFC exporterIFC, Element element, ElementId categoryId, IFCAnyHandle contextOfItems, string identifierOpt, string representationTypeOpt, IList <IFCAnyHandle> items) { HashSet <IFCAnyHandle> itemSet = new HashSet <IFCAnyHandle>(); foreach (IFCAnyHandle axisItem in items) { itemSet.Add(axisItem); } return(CreateShapeRepresentation(exporterIFC, element, categoryId, contextOfItems, identifierOpt, representationTypeOpt, itemSet)); }
/// <summary> /// Creates a SweptSolid, Brep, or Surface product definition shape representation, depending on the geoemtry and export version. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="categoryId">The category id.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="bodyExporterOptions">The body exporter options.</param> /// <param name="extraReps">Extra representations (e.g. Axis, Boundary). May be null.</param> /// <param name="extrusionCreationData">The extrusion creation data.</param> /// <param name="allowOffsetTransform">Allows local coordinate system to be placed close to geometry.</param> /// <returns>The handle.</returns> /// <remarks>allowOffsetTransform should only be set to true if no other associated geometry is going to be exported. Otherwise, /// there could be an offset between this geometry and the other, non-transformed, geometry.</remarks> public static IFCAnyHandle CreateAppropriateProductDefinitionShape(ExporterIFC exporterIFC, Element element, ElementId categoryId, GeometryElement geometryElement, BodyExporterOptions bodyExporterOptions, IList <IFCAnyHandle> extraReps, IFCExtrusionCreationData extrusionCreationData, bool allowOffsetTransform) { BodyData bodyData; BodyExporterOptions newBodyExporterOptions = new BodyExporterOptions(bodyExporterOptions); newBodyExporterOptions.AllowOffsetTransform = allowOffsetTransform; return(CreateAppropriateProductDefinitionShape(exporterIFC, element, categoryId, geometryElement, newBodyExporterOptions, extraReps, extrusionCreationData, out bodyData)); }
public static bool IsFinishingInAnotherGroup(ElementId id) { var element = Document.GetElement(id); return(element.GroupId != null); }
/// <summary> /// Creates an annotation representation. /// </summary> /// <param name="exporterIFC">The exporter.</param> /// <param name="element">The element.</param> /// <param name="categoryId">The category id.</param> /// <param name="contextOfItems">The context for which the different subtypes of representation are valid.</param> /// <param name="bodyItems">Set of geometric representation items that are defined for this representation.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateAnnotationSetRep(ExporterIFC exporterIFC, Element element, ElementId categoryId, IFCAnyHandle contextOfItems, HashSet <IFCAnyHandle> bodyItems) { string identifierOpt = "Annotation"; string repTypeOpt = ShapeRepresentationType.Annotation2D.ToString(); // this is by IFC2x3 convention IFCAnyHandle bodyRepresentation = CreateShapeRepresentation(exporterIFC, element, categoryId, contextOfItems, identifierOpt, repTypeOpt, bodyItems); return(bodyRepresentation); }
/// <summary> /// Creates a shape representation or appends existing ones to original representation. /// </summary> /// <remarks> /// This function has two modes. /// If originalShapeRepresentation has no value, then this function will create a new ShapeRepresentation handle. /// If originalShapeRepresentation has a value, then it is expected to be an aggregation of representations, and the new representation /// will be appended to the end of the list. /// </remarks> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="categoryId">The category id.</param> /// <param name="contextOfItems">The context for which the different subtypes of representation are valid.</param> /// <param name="identifierOpt">The identifier for the representation.</param> /// <param name="representationTypeOpt">The type handle for the representation.</param> /// <param name="items">Collection of geometric representation items that are defined for this representation.</param> /// <param name="originalShapeRepresentation">The original shape representation.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateOrAppendShapeRepresentation(ExporterIFC exporterIFC, Element element, ElementId categoryId, IFCAnyHandle contextOfItems, string identifierOpt, string representationTypeOpt, ISet <IFCAnyHandle> items, IFCAnyHandle originalShapeRepresentation) { if (!IFCAnyHandleUtil.IsNullOrHasNoValue(originalShapeRepresentation)) { GeometryUtil.AddItemsToShape(originalShapeRepresentation, items); return(originalShapeRepresentation); } return(CreateShapeRepresentation(exporterIFC, element, categoryId, contextOfItems, identifierOpt, representationTypeOpt, items)); }
public bool VisualizeData() { bool result = false; try { string viewIdValue = RegistryKeyManager.GetRegistryKeyValue("RevitOutgoingViewId"); ElementId viewId = new ElementId(int.Parse(viewIdValue)); Autodesk.Revit.DB.View view = m_doc.GetElement(viewId) as Autodesk.Revit.DB.View; if (null != view) { SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view); if (null == sfm) { sfm = SpatialFieldManager.CreateSpatialFieldManager(view, 1); } AnalysisResultSchema resultSchema = new AnalysisResultSchema(analysisType.ToString(), "Imported from DIVA"); int resultIndex = -1; //check order DataContainer tempContainer = dataDictionary[0]; XYZ node = new XYZ(tempContainer.Node.XValue, tempContainer.Node.YValue, tempContainer.Node.ZValue); IntersectionResult intersection = displayingFaces[0].Project(node); if (null == intersection) { displayingFaces.Reverse(); } //reverse the order of faces foreach (int keyIndex in dataDictionary.Keys) { DataContainer container = dataDictionary[keyIndex]; Face face = displayingFaces[keyIndex]; List <double> dblList = new List <double>(); dblList.Add(container.ResultValue); XYZ vectorZ = new XYZ(0, 0, -1); Transform transform = Transform.CreateTranslation(vectorZ); int index = sfm.AddSpatialFieldPrimitive(face, transform); IList <UV> uvPts = new List <UV>(); IList <ValueAtPoint> valList = new List <ValueAtPoint>(); XYZ nodePoint = new XYZ(container.Node.XValue, container.Node.YValue, container.Node.ZValue); IntersectionResult intersect = face.Project(nodePoint); if (null != intersect) { UV nodeUV = intersect.UVPoint; uvPts.Add(nodeUV); valList.Add(new ValueAtPoint(dblList)); FieldDomainPointsByUV domainPoints = new FieldDomainPointsByUV(uvPts); FieldValues values = new FieldValues(valList); FieldValues vals = new FieldValues(valList); if (resultIndex == -1) { resultIndex = sfm.RegisterResult(resultSchema); } else { sfm.SetResultSchema(resultIndex, resultSchema); } sfm.UpdateSpatialFieldPrimitive(index, domainPoints, values, resultIndex); } result = true; } } } catch (Exception ex) { MessageBox.Show("Failed to visualize the result data.\n" + ex.Message, "Analysis Data Manager - Visualize Data", MessageBoxButtons.OK, MessageBoxIcon.Warning); result = false; } return(result); }
Stream(ArrayList data, ElementId elemId) { data.Add(new Snoop.Data.ClassSeparator(typeof(Schema))); Utils.StreamWithReflection(data, typeof(ElementId), elemId); }
/// <summary> /// Create tessellated body representation /// </summary> /// <param name="exporterIFC">the ExporterIFC object</param> /// <param name="element">the Element</param> /// <param name="categoryId">The Category Id</param> /// <param name="contextOfItems">The context for which the different subtypes of representation are valid.</param> /// <param name="bodyItems">Set of geometric representation items that are defined for this representation.</param> /// <param name="originalRepresentation">The original shape representation.</param> /// <returns></returns> public static IFCAnyHandle CreateTessellatedRep(ExporterIFC exporterIFC, Element element, ElementId categoryId, IFCAnyHandle contextOfItems, ISet <IFCAnyHandle> bodyItems, IFCAnyHandle originalRepresentation) { // Currently set to "Body" as shown also in the IFC documentation example. But there is also "Body-Fallback" for tessellated geometry. string identifierOpt = "Body"; string repTypeOpt = ShapeRepresentationType.Tessellation.ToString(); IFCAnyHandle bodyRepresentation = CreateOrAppendShapeRepresentation(exporterIFC, element, categoryId, contextOfItems, identifierOpt, repTypeOpt, bodyItems, originalRepresentation); return(bodyRepresentation); }
/// <summary> /// Creates a plan mapped item representation. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="categoryId">The category id.</param> /// <param name="contextOfItems">The context for which the different subtypes of representation are valid.</param> /// <param name="bodyItems">Set of geometric representation items that are defined for this representation.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreatePlanMappedItemRep(ExporterIFC exporterIFC, Element element, ElementId categoryId, IFCAnyHandle contextOfItems, HashSet <IFCAnyHandle> bodyItems) { string identifierOpt = "FootPrint"; // this is by IFC2x2+ convention string repTypeOpt = ShapeRepresentationType.MappedRepresentation.ToString(); // this is by IFC2x2+ convention IFCAnyHandle bodyRepresentation = CreateShapeRepresentation(exporterIFC, element, categoryId, contextOfItems, identifierOpt, repTypeOpt, bodyItems); return(bodyRepresentation); }
/// <summary> /// Creates an IfcFacetedBrep handle. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="shell">The closed shell handle.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateFacetedBRep(ExporterIFC exporterIFC, Document document, IFCAnyHandle shell, ElementId overrideMaterialId) { IFCFile file = exporterIFC.GetFile(); IFCAnyHandle brep = IFCInstanceExporter.CreateFacetedBrep(file, shell); BodyExporter.CreateSurfaceStyleForRepItem(exporterIFC, document, brep, overrideMaterialId); return(brep); }
/// <summary> /// Creates a Brep representation. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="categoryId">The category id.</param> /// <param name="contextOfItems">The context for which the different subtypes of representation are valid.</param> /// <param name="bodyItems">Set of geometric representation items that are defined for this representation.</param> /// <param name="exportAsFacetationOrMesh"> /// If this is true, the identifier for the representation is "Facetation" as required by IfcSite for IFC2x2, IFC2x3, or "Mesh" for GSA. /// If this is false, the identifier for the representation is "Body" as required by IfcBuildingElement, or IfcSite for IFC2x3 v2. /// </param> /// <param name="originalShapeRepresentation">The original shape representation.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateSurfaceRep(ExporterIFC exporterIFC, Element element, ElementId categoryId, IFCAnyHandle contextOfItems, ISet <IFCAnyHandle> bodyItems, bool exportAsFacetationOrMesh, IFCAnyHandle originalRepresentation) { string identifierOpt = null; if (exportAsFacetationOrMesh) { if (ExporterCacheManager.ExportOptionsCache.ExportAsCOBIE) { identifierOpt = ShapeRepresentationType.Mesh.ToString(); // IFC GSA convention } else { identifierOpt = ShapeRepresentationType.Facetation.ToString(); // IFC2x2+ convention } } else { identifierOpt = "Body"; // IFC2x2+ convention for IfcBuildingElement, IFC2x3 v2 convention for IfcSite } string repTypeOpt = ShapeRepresentationType.SurfaceModel.ToString(); // IFC2x2+ convention IFCAnyHandle bodyRepresentation = CreateOrAppendShapeRepresentation(exporterIFC, element, categoryId, contextOfItems, identifierOpt, repTypeOpt, bodyItems, originalRepresentation); return(bodyRepresentation); }
void SelectAndPlaceTakeOffFitting(Document doc) { ElementId mainDuctId = ElementId.InvalidElementId; // Get DuctType - we need this for its // RoutingPreferenceManager. This is how we assign // our tap object to be used. This is the settings // for the duct object we attach our tap to. Duct duct = doc.GetElement(mainDuctId) as Duct; DuctType ductType = duct.DuctType; RoutingPreferenceManager routePrefManager = ductType.RoutingPreferenceManager; // Set Junction Prefernce to Tap. routePrefManager.PreferredJunctionType = PreferredJunctionType.Tap; // For simplicity sake, I remove all previous rules // for taps so I can just add what I want here. // This will probably vary. int initRuleCount = routePrefManager.GetNumberOfRules( RoutingPreferenceRuleGroupType.Junctions); for (int i = 0; i != initRuleCount; ++i) { routePrefManager.RemoveRule( RoutingPreferenceRuleGroupType.Junctions, 0); } // Get FamilySymbol for Tap I want to use. FamilySymbol tapSym = null; doc.LoadFamilySymbol("C:/FamilyLocation/MyTap.rfa", "MyTap", out tapSym); // Symbol needs to be activated before use. if ((!tapSym.IsActive) && (tapSym != null)) { tapSym.Activate(); doc.Regenerate(); } // Create Rule that utilizes the Tap. Use the argument // MEPPartId = ElementId for the desired FamilySymbol. RoutingPreferenceRule newRule = new RoutingPreferenceRule(tapSym.Id, "MyTap"); routePrefManager.AddRule( RoutingPreferenceRuleGroupType.Junctions, newRule); // To create a solid tap, we need to use the Revit // doc.Create.NewTakeoffFitting routine. For this, // we need a connector. If we don't have one, we // just create a temporary object with a connector // where we want it. Connector tmpConn = CreateTemporaryConnectorForTap(); // Create our tap. FamilyInstance tapInst = doc.Create.NewTakeoffFitting(tmpConn, duct); }
/// <summary> /// Creates a Solid model representation. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="categoryId">The category id.</param> /// <param name="contextOfItems">The context for which the different subtypes of representation are valid.</param> /// <param name="bodyItems">Set of geometric representation items that are defined for this representation.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateSolidModelRep(ExporterIFC exporterIFC, Element element, ElementId categoryId, IFCAnyHandle contextOfItems, ISet <IFCAnyHandle> bodyItems) { string identifierOpt = "Body"; string repTypeOpt = ShapeRepresentationType.SolidModel.ToString(); IFCAnyHandle bodyRepresentation = CreateShapeRepresentation(exporterIFC, element, categoryId, contextOfItems, identifierOpt, repTypeOpt, bodyItems); return(bodyRepresentation); }
/// <summary> /// Creates a boundary representation. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="categoryId">The category id.</param> /// <param name="contextOfItems">The context for which the different subtypes of representation are valid.</param> /// <param name="bodyItems">Collection of geometric representation items that are defined for this representation.</param> /// <param name="originalShapeRepresentation">The original shape representation.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateBoundaryRep(ExporterIFC exporterIFC, Element element, ElementId categoryId, IFCAnyHandle contextOfItems, ISet <IFCAnyHandle> bodyItems, IFCAnyHandle originalRepresentation) { string identifierOpt = "FootPrint"; // this is by IFC2x3 convention, not temporary string repTypeOpt = ShapeRepresentationType.Curve2D.ToString(); // this is by IFC2x2 convention, not temporary IFCAnyHandle bodyRepresentation = CreateOrAppendShapeRepresentation(exporterIFC, element, categoryId, contextOfItems, identifierOpt, repTypeOpt, bodyItems, originalRepresentation); return(bodyRepresentation); }
/// <summary> /// Creates a extruded product definition shape representation. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="element">The base element.</param> /// <param name="categoryId">The category of the element.</param> /// <param name="curveLoops">The curve loops defining the extruded surface.</param> /// <param name="plane">The extrusion base plane.</param> /// <param name="extrDirVec">The extrusion direction.</param> /// <param name="extrusionSize">The scaled extrusion length.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateExtrudedProductDefShape(ExporterIFC exporterIFC, Element element, ElementId categoryId, IList <CurveLoop> curveLoops, Plane plane, XYZ extrDirVec, double extrusionSize) { IFCFile file = exporterIFC.GetFile(); IFCAnyHandle extrusionHnd = ExtrusionExporter.CreateExtrudedSolidFromCurveLoop(exporterIFC, null, curveLoops, plane, extrDirVec, extrusionSize, false); if (IFCAnyHandleUtil.IsNullOrHasNoValue(extrusionHnd)) { return(null); } ISet <IFCAnyHandle> bodyItems = new HashSet <IFCAnyHandle>(); bodyItems.Add(extrusionHnd); IFCAnyHandle contextOfItems = exporterIFC.Get3DContextHandle("Body"); IFCAnyHandle shapeRepHnd = CreateSweptSolidRep(exporterIFC, element, categoryId, contextOfItems, bodyItems, null); IList <IFCAnyHandle> shapeReps = new List <IFCAnyHandle>(); shapeReps.Add(shapeRepHnd); return(IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps)); }
public Result Execute( ExternalCommandData commandData, ref String message, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; FilteredElementCollector a; Parameter p; int n; #region Using the obsolete TitleBlocks property #if BEFORE_REVIT_2015 // The TitleBlocks property was declared deprecated // in the Revit 2014 API, and removed in Revit 2015. // Using the obsolete deprecated TitleBlocks property FamilySymbolSet titleBlocks = doc.TitleBlocks; n = titleBlocks.Size; Debug.Print( "{0} title block element type{1} listed " + "in doc.TitleBlocks collection{2}", n, (1 == n ? "" : "s"), (0 == n ? "." : ":")); string s; foreach (FamilySymbol tb in titleBlocks) { // these are the family symbols, // i.e. the title block element types, // i.e. not instances, i.e. not sheets, // and they obviously do not have any sheet // number, width or height, so 's' ends up empty: s = GetParameterValueString(tb, BuiltInParameter.SHEET_NUMBER) + GetParameterValueString(tb, BuiltInParameter.SHEET_WIDTH) + GetParameterValueString(tb, BuiltInParameter.SHEET_HEIGHT); Debug.Print( "Title block element type {0} {1}" + s, tb.Name, tb.Id.IntegerValue); } #endif // BEFORE_REVIT_2015 #endregion // Using the obsolete TitleBlocks property // Using this filter returns the same elements // as the doc.TitleBlocks collection: a = new FilteredElementCollector(doc) .OfCategory(BuiltInCategory.OST_TitleBlocks) .OfClass(typeof(FamilySymbol)); n = a.ToElementIds().Count; Debug.Print("{0} title block element type{1} " + "retrieved by filtered element collector{2}", n, (1 == n ? "" : "s"), (0 == n ? "." : ":")); foreach (FamilySymbol symbol in a) { Debug.Print( "Title block element type {0} {1}", symbol.Name, symbol.Id.IntegerValue); } // Retrieve the title block instances: a = new FilteredElementCollector(doc) .OfCategory(BuiltInCategory.OST_TitleBlocks) .OfClass(typeof(FamilyInstance)); Debug.Print("Title block instances:"); foreach (FamilyInstance e in a) { p = e.get_Parameter( BuiltInParameter.SHEET_NUMBER); Debug.Assert(null != p, "expected valid sheet number"); string sheet_number = p.AsString(); p = e.get_Parameter( BuiltInParameter.SHEET_WIDTH); Debug.Assert(null != p, "expected valid sheet width"); string swidth = p.AsValueString(); double width = p.AsDouble(); p = e.get_Parameter( BuiltInParameter.SHEET_HEIGHT); Debug.Assert(null != p, "expected valid sheet height"); string sheight = p.AsValueString(); double height = p.AsDouble(); ElementId typeId = e.GetTypeId(); Element type = doc.GetElement(typeId); Debug.Print( "Sheet number {0} size is {1} x {2} " + "({3} x {4}), id {5}, type {6} {7}", sheet_number, swidth, sheight, Util.RealString(width), Util.RealString(height), e.Id.IntegerValue, type.Name, typeId.IntegerValue); } // Retrieve the view sheet instances: a = new FilteredElementCollector(doc) .OfClass(typeof(ViewSheet)); Debug.Print("View sheet instances:"); foreach (ViewSheet vs in a) { string number = vs.SheetNumber; Debug.Print( "View sheet name {0} number {1} id {2}", vs.Name, vs.SheetNumber, vs.Id.IntegerValue); } return(Result.Succeeded); }
/// <summary> /// Creates a geometric set representation. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="categoryId">The category id.</param> /// <param name="type">The representation type.</param> /// <param name="contextOfItems">The context for which the different subtypes of representation are valid.</param> /// <param name="bodyItems">Set of geometric representation items that are defined for this representation.</param> /// <returns>The handle.</returns> public static IFCAnyHandle CreateGeometricSetRep(ExporterIFC exporterIFC, Element element, ElementId categoryId, string type, IFCAnyHandle contextOfItems, HashSet <IFCAnyHandle> bodyItems) { string identifierOpt = type; string repTypeOpt = ShapeRepresentationType.GeometricSet.ToString(); // this is by IFC2x2 convention, not temporary IFCAnyHandle bodyRepresentation = CreateShapeRepresentation(exporterIFC, element, categoryId, contextOfItems, identifierOpt, repTypeOpt, bodyItems); return(bodyRepresentation); }