/// <summary> /// Create a DirectShape, and set its options accordingly. /// </summary> /// <param name="doc">The document.</param> /// <param name="categoryId">The category of the DirectShape.</param> /// <param name="dataGUID">The GUID of the data creating the DirectShape.</param> /// <param name="geomObjs">The list of geometries to add to the DirectShape.</param> /// <param name="id">The id of the IFCEntity object creating the DirectShape.</param> /// <returns>The DirectShape.</returns> static public DirectShape CreateElement(Document doc, ElementId categoryId, string dataGUID, IList <GeometryObject> geomObjs, int id, IFCEntityType entityType) { string appGUID = Importer.ImportAppGUID(); DirectShape directShape = DirectShape.CreateElement(doc, GetDSValidCategoryId(doc, categoryId, id)); directShape.ApplicationId = appGUID; directShape.ApplicationDataId = dataGUID; // Note: we use the standard options for the DirectShape that is created. This includes but is not limited to: // Referenceable: true. // Room Bounding: if applicable, user settable. if (IFCImportFile.TheFile.Options.UseStreamlinedOptions) { // Disable referencing for performance purposes. DirectShapeOptions options = directShape.GetOptions(); options.ReferencingOption = DirectShapeReferencingOption.NotReferenceable; directShape.SetOptions(options); } // This is used in some places to create something not related to an IFCEntity if (!Importer.TheProcessor.CreateOrUpdateElement(id, dataGUID, entityType.ToString(), categoryId.IntegerValue, geomObjs)) { if (geomObjs != null) { directShape?.SetShape(geomObjs); } } return(directShape); }
/// <summary> /// Create a DirectShape, and set its options accordingly. /// </summary> /// <param name="doc">The document.</param> /// <param name="categoryId">The category of the DirectShape.</param> /// <param name="dataGUID">The GUID of the data creating the DirectShape.</param> /// <param name="geomObjs">The list of geometries to add to the DirectShape.</param> /// <param name="id">The id of the IFCEntity object creating the DirectShape.</param> /// <returns>The DirectShape.</returns> static public DirectShape CreateElement(Document doc, ElementId categoryId, string dataGUID, IList <GeometryObject> geomObjs, int id) { string appGUID = Importer.ImportAppGUID(); DirectShape directShape = DirectShape.CreateElement(doc, GetDSValidCategoryId(doc, categoryId, id)); directShape.ApplicationId = appGUID; directShape.ApplicationDataId = dataGUID; // Note: we use the standard options for the DirectShape that is created. This includes but is not limited to: // Referenceable: true. // Room Bounding: if applicable, user settable. if (IFCImportFile.TheFile.Options.UseStreamlinedOptions) { // Disable referencing for performance purposes. DirectShapeOptions options = directShape.GetOptions(); options.ReferencingOption = DirectShapeReferencingOption.NotReferenceable; directShape.SetOptions(options); } if (directShape != null && geomObjs != null) { directShape.SetShape(geomObjs); } return(directShape); }
public static bool CreateAreaSolid(Document doc, AreaProperties ap, out MassProperties createdMass) { bool created = false; createdMass = null; try { string appGuid = doc.Application.ActiveAddInId.GetGUID().ToString(); if (null != ap.Linked3dMass) { //delete existing mass first MassProperties existingMass = ap.Linked3dMass; doc.Delete(new ElementId(existingMass.MassId)); } IList <GeometryObject> areaGeometries = new List <GeometryObject>(); if (ap.AreaProfile.Count > 0) { XYZ extrusionDir = new XYZ(0, 0, 1); Solid areaSolid = GeometryCreationUtilities.CreateExtrusionGeometry(ap.AreaProfile, extrusionDir, ap.UserHeight); if (null != areaSolid) { areaGeometries.Add(areaSolid); } } #if RELEASE2015 || RELEASE2016 DirectShape createdShape = DirectShape.CreateElement(doc, new ElementId(massCategory), appGuid, ap.AreaId.ToString()); #else DirectShape createdShape = DirectShape.CreateElement(doc, new ElementId(massCategory)); createdShape.ApplicationId = appGuid; createdShape.ApplicationDataId = ap.AreaId.ToString(); #endif #if RELEASE2016 DirectShapeOptions options = createdShape.GetOptions(); options.ReferencingOption = DirectShapeReferencingOption.Referenceable; createdShape.SetOptions(options); #endif createdShape.SetShape(areaGeometries); createdShape.SetName(ap.AreaName); Element massElement = doc.GetElement(createdShape.Id); if (null != massElement) { createdMass = new MassProperties(massElement); createdMass.SetHostInfo(ap.AreaUniqueId, SourceType.Areas, ap.AreaCenterPoint, ap.UserHeight); bool stored = MassDataStorageUtil.SetLinkedHostInfo(massElement, SourceType.Areas.ToString(), ap.AreaUniqueId, ap.AreaCenterPoint, ap.UserHeight); created = true; } } catch (Exception ex) { MessageBox.Show("Failed to create area solid.\n" + ex.Message, "Create Area Solid", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(created); }
public void ProcessMultipleSAT() { List <ElementId> importIds = new List <ElementId>(); // create and set new SAT options SATImportOptions satOptions = new SATImportOptions(); satOptions.Placement = ImportPlacement.Origin; satOptions.ColorMode = ImportColorMode.BlackAndWhite; satOptions.Unit = ImportUnit.Millimeter; using (Transaction trans = new Transaction(m_doc, "UpdateSAT")) { trans.Start(); List <GeometryObject> geoObjList = new List <GeometryObject>(); DirectShape ds = null; ElementId currentId; try { currentId = m_doc.Import(@"B:\Rhino\OpenNURBS\v5_example_file.sat", satOptions, m_doc.ActiveView); importIds.Add(currentId); } catch (Exception) { currentId = ElementId.InvalidElementId; } // extract geometry from import instance ImportInstance ii = m_doc.GetElement(currentId) as ImportInstance; Options gOptions = new Options(); gOptions.ComputeReferences = true; GeometryElement geoElement = ii.get_Geometry(gOptions); // get solids from geometry element List <GeometryObject> tempGeoList = FindElementGeometry(geoElement); foreach (GeometryObject go in tempGeoList) { geoObjList.Add(go); } ds = DirectShape.CreateElement(m_doc, new ElementId((int)BuiltInCategory.OST_GenericModel)); ds.SetShape(geoObjList); // set the Direct Shape options DirectShapeOptions dsOptions = ds.GetOptions(); dsOptions.ReferencingOption = DirectShapeReferencingOption.Referenceable; ds.SetOptions(dsOptions); trans.Commit(); trans.Start("Delete Elements"); // clean up imported solids m_doc.Delete(importIds); trans.Commit(); } }
public static bool CreateFloorFace(Document doc, FloorProperties fp, out MassProperties createdMass) { bool created = false; createdMass = null; try { string appGuid = doc.Application.ActiveAddInId.GetGUID().ToString(); if (null != fp.Linked2dMass) { //delete existing mass first MassProperties existingMass = fp.Linked2dMass; doc.Delete(new ElementId(existingMass.MassId)); } IList <GeometryObject> floorGeometries = GetGeometryObjectsFromFace(fp.TopFace); #if RELEASE2015 || RELEASE2016 DirectShape createdShape = DirectShape.CreateElement(doc, new ElementId(massCategory), appGuid, fp.FloorId.ToString()); #else DirectShape createdShape = DirectShape.CreateElement(doc, new ElementId(massCategory)); createdShape.ApplicationId = appGuid; createdShape.ApplicationDataId = fp.FloorId.ToString(); #endif #if RELEASE2016 DirectShapeOptions options = createdShape.GetOptions(); options.ReferencingOption = DirectShapeReferencingOption.Referenceable; createdShape.SetOptions(options); #endif createdShape.SetShape(floorGeometries); createdShape.SetName(fp.FloorName); Element massElement = doc.GetElement(createdShape.Id); if (null != massElement) { createdMass = new MassProperties(massElement); createdMass.MassElementType = MassType.MASS2D; createdMass.SetHostInfo(fp.FloorUniqueId, SourceType.Floors, fp.FloorSolidCentroid, 0); bool stored = MassDataStorageUtil.SetLinkedHostInfo(massElement, SourceType.Floors.ToString(), fp.FloorUniqueId, fp.FloorSolidCentroid, 0); created = true; } } catch (Exception ex) { MessageBox.Show("Failed to create room solid.\n" + ex.Message, "Create Room Solid", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(created); }
public static DirectShape CreateDirectShape(Document doc, IList <GeometryObject> resultList) { DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel)); ds.ApplicationId = "Application id"; ds.ApplicationDataId = "Geometry object id"; ds.Name = "Load area"; DirectShapeOptions dso = ds.GetOptions(); dso.ReferencingOption = DirectShapeReferencingOption.Referenceable; ds.SetOptions(dso); ds.SetShape(resultList); doc.Regenerate(); return(ds); }
private static void CreateDirectShape(Document doc, IList <GeometryObject> geometry) { DirectShapeLibrary directShapeLibrary = DirectShapeLibrary.GetDirectShapeLibrary(doc); DirectShapeType directShapeType = DirectShapeType.Create(doc, "NavisWorksShape", new ElementId(BuiltInCategory.OST_GenericModel)); directShapeType.SetShape(geometry); directShapeLibrary.AddDefinitionType("NavisWorksShape", directShapeType.Id); DirectShape ds = DirectShape.CreateElementInstance(doc, directShapeType.Id, directShapeType.Category.Id, "NavisWorksShape", Transform.Identity); ds.SetTypeId(directShapeType.Id); ds.ApplicationId = Assembly.GetExecutingAssembly().GetType().GUID.ToString(); ds.ApplicationDataId = Guid.NewGuid().ToString(); DirectShapeOptions dsOptions = ds.GetOptions(); dsOptions.ReferencingOption = DirectShapeReferencingOption.Referenceable; ds.SetOptions(dsOptions); ds.SetShape(geometry); }
/// <summary> /// Creates a Direct Shape object. /// </summary> /// <param name="doc">Document</param> /// <param name="element">Element to convert.</param> /// <returns></returns> private static DirectShapeInfo CreateDirectShape(Document doc, Element element) { DirectShapeInfo shapeInfo = null; var isFamilyInstance = false; try { if (element.GetType() == typeof(FamilyInstance)) { isFamilyInstance = true; } if (element.GroupId != ElementId.InvalidElementId) { var group = doc.GetElement(element.GroupId) as Group; group?.UngroupMembers(); } if (isFamilyInstance) { var subComponents = ((FamilyInstance)element).GetSubComponentIds(); foreach (var subId in subComponents) { var subComponent = doc.GetElement(subId); if (subComponent != null) { CreateDirectShape(doc, subComponent); //TODO: same as above. It's worth creating them, but they are not returned. } } } var geoOptions = new Options(); var geoElement = element.get_Geometry(geoOptions); if (null != geoElement) { try { DirectShape directShape = null; #if RELEASE2015 || RELEASE2016 var shapeTypeId = ElementId.InvalidElementId; var appDataGUID = element.Id.IntegerValue.ToString(); #endif var shapeGeometries = FindElementGeometry(geoElement); if (shapeGeometries.Count > 0) { #if RELEASE2015 || RELEASE2016 directShape = DirectShape.CreateElement(doc, element.Category.Id, appDataGUID, appDataGUID); #else directShape = DirectShape.CreateElement(doc, element.Category.Id); #endif directShape.SetShape(shapeGeometries); } if (null != directShape) { directShape.SetName(element.Name); #if RELEASE2016 || RELEASE2017 || RELEASE2018 || RELEASE2019 var dsOptions = directShape.GetOptions(); dsOptions.ReferencingOption = DirectShapeReferencingOption.Referenceable; directShape.SetOptions(dsOptions); #endif shapeInfo = new DirectShapeInfo(directShape.Id, element.Id); } } catch (Exception ex) { Log.AppendLog(LogMessageType.EXCEPTION, "Cannot Set Geometry of DirectShape-" + ex.Message + element.Id); } } } catch (Exception ex) { Log.AppendLog(LogMessageType.EXCEPTION, "Cannot Create DirectShape-" + ex.Message + element.Id); } return(shapeInfo); }