private static void AdjustExtrusion(XbimModel model, IfcExtrudedAreaSolid body, HndzStructuralElement genericProducthndz, IfcProduct genericProductIfc) { IfcCartesianPoint axisOrigin = model.Instances.New <IfcCartesianPoint>(); axisOrigin.SetXYZ(0, 0, 0); IfcCartesianPoint elementStartPoint = model.Instances.New <IfcCartesianPoint>(); elementStartPoint.SetXYZ(genericProducthndz.ExtrusionLine.baseNode.Point.X, genericProducthndz.ExtrusionLine.baseNode.Point.Y, genericProducthndz.ExtrusionLine.baseNode.Point.Z); //insert at arbitrary position//****************Need Revision body.Depth = genericProducthndz.ExtrusionLine.RhinoLine.Length; body.ExtrudedDirection = model.Instances.New <IfcDirection>(); body.ExtrudedDirection.SetXYZ(0, 0, 1); //parameters to insert the geometry in the model body.Position = model.Instances.New <IfcAxis2Placement3D>(); body.Position.Location = axisOrigin; //body.Position.RefDirection = model.Instances.New<IfcDirection>(); //body.Position.RefDirection.SetXYZ(1, 0, 0); //Create a Definition shape to hold the geometry IfcShapeRepresentation shape = model.Instances.New <IfcShapeRepresentation>(); shape.ContextOfItems = model.IfcProject.ModelContext(); shape.RepresentationType = "SweptSolid"; shape.RepresentationIdentifier = "Body"; shape.Items.Add(body); //Create a Product Definition and add the model geometry to the wall IfcProductDefinitionShape rep = model.Instances.New <IfcProductDefinitionShape>(); rep.Representations.Add(shape); genericProductIfc.Representation = rep; //now place the wall into the model #region ProfileVectorDir. Vector3d perpendicularVector = new Vector3d(genericProducthndz.Profile.OrientationInPlane.X, genericProducthndz.Profile.OrientationInPlane.Y, 0); Plane extrusionPlane; bool aa = genericProducthndz.ExtrusionLine.RhinoLine.TryGetPlane(out extrusionPlane); if (aa) { perpendicularVector = extrusionPlane.ZAxis; } // Vector3d elementDirection = genericProducthndz.ExtrusionLine.RhinoLine.Direction; //Plane profilePlane = new Plane(genericProducthndz.ExtrusionLine.baseNode.Point, elementDirection); // Vector3d profileXdirection = profilePlane.XAxis; #endregion IfcLocalPlacement lp = model.Instances.New <IfcLocalPlacement>(); IfcAxis2Placement3D ax3D = model.Instances.New <IfcAxis2Placement3D>(); ax3D.Location = elementStartPoint; ax3D.RefDirection = model.Instances.New <IfcDirection>(); ax3D.RefDirection.SetXYZ(perpendicularVector.X, perpendicularVector.Y, perpendicularVector.Z); //Y-Axis //ax3D.RefDirection.SetXYZ(0, 1, 0); //Y-Axis ax3D.Axis = model.Instances.New <IfcDirection>(); ax3D.Axis.SetXYZ(genericProducthndz.ExtrusionLine.RhinoLine.Direction.X, genericProducthndz.ExtrusionLine.RhinoLine.Direction.Y, genericProducthndz.ExtrusionLine.RhinoLine.Direction.Z); //Z-Axis //XbimVector3D X_Dir = new XbimVector3D(extrusionPlane.XAxis.X, extrusionPlane.XAxis.Y, extrusionPlane.XAxis.Z); //XbimVector3D Y_Dir = new XbimVector3D(extrusionPlane.YAxis.X, extrusionPlane.YAxis.Y, extrusionPlane.YAxis.Z); //XbimVector3D Z_Dir = new XbimVector3D(extrusionPlane.ZAxis.X, extrusionPlane.ZAxis.Y, extrusionPlane.ZAxis.Z); //ax3D.P.Insert(0,X_Dir); //ax3D.P.Insert(1,Y_Dir); //ax3D.P.Insert(2,Z_Dir); lp.RelativePlacement = ax3D; genericProductIfc.ObjectPlacement = lp; // Where Clause: The IfcWallStandard relies on the provision of an IfcMaterialLayerSetUsage IfcMaterialLayerSetUsage ifcMaterialLayerSetUsage = model.Instances.New <IfcMaterialLayerSetUsage>(); IfcMaterialLayerSet ifcMaterialLayerSet = model.Instances.New <IfcMaterialLayerSet>(); IfcMaterialLayer ifcMaterialLayer = model.Instances.New <IfcMaterialLayer>(); ifcMaterialLayer.LayerThickness = 10; ifcMaterialLayerSet.MaterialLayers.Add(ifcMaterialLayer); ifcMaterialLayerSetUsage.ForLayerSet = ifcMaterialLayerSet; ifcMaterialLayerSetUsage.LayerSetDirection = IfcLayerSetDirectionEnum.AXIS2; ifcMaterialLayerSetUsage.DirectionSense = IfcDirectionSenseEnum.NEGATIVE; ifcMaterialLayerSetUsage.OffsetFromReferenceLine = 150; // Add material to wall IfcMaterial material = model.Instances.New <IfcMaterial>(); material.Name = "STEEL"; IfcRelAssociatesMaterial ifcRelAssociatesMaterial = model.Instances.New <IfcRelAssociatesMaterial>(); ifcRelAssociatesMaterial.RelatingMaterial = material; ifcRelAssociatesMaterial.RelatedObjects.Add(genericProductIfc); ifcRelAssociatesMaterial.RelatingMaterial = ifcMaterialLayerSetUsage; // IfcPresentationLayerAssignment is required for CAD presentation in IfcWall or IfcWallStandardCase IfcPresentationLayerAssignment ifcPresentationLayerAssignment = model.Instances.New <IfcPresentationLayerAssignment>(); ifcPresentationLayerAssignment.Name = "HANDZteel Assignment"; ifcPresentationLayerAssignment.AssignedItems.Add(shape); // linear segment as IfcPolyline with two points is required for IfcWall IfcPolyline ifcPolyline = model.Instances.New <IfcPolyline>(); IfcCartesianPoint startPoint = model.Instances.New <IfcCartesianPoint>(); startPoint.SetXY(genericProducthndz.ExtrusionLine.baseNode.Point.X, genericProducthndz.ExtrusionLine.baseNode.Point.Y); IfcCartesianPoint endPoint = model.Instances.New <IfcCartesianPoint>(); endPoint.SetXY(genericProducthndz.ExtrusionLine.EndNode.Point.X, genericProducthndz.ExtrusionLine.EndNode.Point.Y); ifcPolyline.Points.Add(startPoint); ifcPolyline.Points.Add(endPoint); IfcShapeRepresentation shape2D = model.Instances.New <IfcShapeRepresentation>(); shape2D.ContextOfItems = model.IfcProject.ModelContext(); shape2D.RepresentationIdentifier = "Axis"; shape2D.RepresentationType = "Curve2D"; shape2D.Items.Add(ifcPolyline); rep.Representations.Add(shape2D); }
/// <summary> /// This creates a wall and it's geometry, many geometric representations are possible and extruded rectangular footprint is chosen as this is commonly used for standard case walls /// </summary> /// <param name="model"></param> /// <param name="length">Length of the rectangular footprint</param> /// <param name="width">Width of the rectangular footprint (width of the wall)</param> /// <param name="height">Height to extrude the wall, extrusion is vertical</param> /// <returns></returns> private IfcWallStandardCase CreateWall(XbimModel model, double length, double width, double height) { // //begin a transaction using (XbimReadWriteTransaction txn = model.BeginTransaction("Create Wall")) { IfcWallStandardCase wall = model.Instances.New <IfcWallStandardCase>(); wall.Name = "A Standard rectangular wall"; // required parameters for IfcWall wall.OwnerHistory.OwningUser = model.DefaultOwningUser; wall.OwnerHistory.OwningApplication = model.DefaultOwningApplication; //represent wall as a rectangular profile IfcRectangleProfileDef rectProf = model.Instances.New <IfcRectangleProfileDef>(); rectProf.ProfileType = IfcProfileTypeEnum.AREA; rectProf.XDim = width; rectProf.YDim = length; IfcCartesianPoint insertPoint = model.Instances.New <IfcCartesianPoint>(); insertPoint.SetXY(0, 400); //insert at arbitrary position rectProf.Position = model.Instances.New <IfcAxis2Placement2D>(); rectProf.Position.Location = insertPoint; //model as a swept area solid IfcExtrudedAreaSolid body = model.Instances.New <IfcExtrudedAreaSolid>(); body.Depth = height; body.SweptArea = rectProf; body.ExtrudedDirection = model.Instances.New <IfcDirection>(); body.ExtrudedDirection.SetXYZ(0, 0, 1); //parameters to insert the geometry in the model IfcCartesianPoint origin = model.Instances.New <IfcCartesianPoint>(); origin.SetXYZ(0, 0, 0); body.Position = model.Instances.New <IfcAxis2Placement3D>(); body.Position.Location = origin; //Create a Definition shape to hold the geometry IfcShapeRepresentation shape = model.Instances.New <IfcShapeRepresentation>(); shape.ContextOfItems = model.IfcProject.ModelContext(); shape.RepresentationType = "SweptSolid"; shape.RepresentationIdentifier = "Body"; shape.Items.Add_Reversible(body); //Create a Product Definition and add the model geometry to the wall IfcProductDefinitionShape rep = model.Instances.New <IfcProductDefinitionShape>(); rep.Representations.Add_Reversible(shape); wall.Representation = rep; //now place the wall into the model IfcLocalPlacement lp = model.Instances.New <IfcLocalPlacement>(); IfcAxis2Placement3D ax3d = model.Instances.New <IfcAxis2Placement3D>(); ax3d.Location = origin; ax3d.RefDirection = model.Instances.New <IfcDirection>(); ax3d.RefDirection.SetXYZ(0, 1, 0); ax3d.Axis = model.Instances.New <IfcDirection>(); ax3d.Axis.SetXYZ(0, 0, 1); lp.RelativePlacement = ax3d; wall.ObjectPlacement = lp; // Where Clause: The IfcWallStandard relies on the provision of an IfcMaterialLayerSetUsage IfcMaterialLayerSetUsage ifcMaterialLayerSetUsage = model.Instances.New <IfcMaterialLayerSetUsage>(); IfcMaterialLayerSet ifcMaterialLayerSet = model.Instances.New <IfcMaterialLayerSet>(); IfcMaterialLayer ifcMaterialLayer = model.Instances.New <IfcMaterialLayer>(); ifcMaterialLayer.LayerThickness = 10; ifcMaterialLayerSet.MaterialLayers.Add_Reversible(ifcMaterialLayer); ifcMaterialLayerSetUsage.ForLayerSet = ifcMaterialLayerSet; ifcMaterialLayerSetUsage.LayerSetDirection = IfcLayerSetDirectionEnum.AXIS2; ifcMaterialLayerSetUsage.DirectionSense = IfcDirectionSenseEnum.NEGATIVE; ifcMaterialLayerSetUsage.OffsetFromReferenceLine = 150; // Add material to wall IfcMaterial material = model.Instances.New <IfcMaterial>(); material.Name = "some material"; IfcRelAssociatesMaterial ifcRelAssociatesMaterial = model.Instances.New <IfcRelAssociatesMaterial>(); ifcRelAssociatesMaterial.RelatingMaterial = material; ifcRelAssociatesMaterial.RelatedObjects.Add_Reversible(wall); ifcRelAssociatesMaterial.RelatingMaterial = ifcMaterialLayerSetUsage; // IfcPresentationLayerAssignment is required for CAD presentation in IfcWall or IfcWallStandardCase IfcPresentationLayerAssignment ifcPresentationLayerAssignment = model.Instances.New <IfcPresentationLayerAssignment>(); ifcPresentationLayerAssignment.Name = "some ifcPresentationLayerAssignment"; ifcPresentationLayerAssignment.AssignedItems.Add(shape); // linear segment as IfcPolyline with two points is required for IfcWall IfcPolyline ifcPolyline = model.Instances.New <IfcPolyline>(); IfcCartesianPoint startPoint = model.Instances.New <IfcCartesianPoint>(); startPoint.SetXY(0, 0); IfcCartesianPoint endPoint = model.Instances.New <IfcCartesianPoint>(); endPoint.SetXY(4000, 0); ifcPolyline.Points.Add_Reversible(startPoint); ifcPolyline.Points.Add_Reversible(endPoint); IfcShapeRepresentation shape2d = model.Instances.New <IfcShapeRepresentation>(); shape2d.ContextOfItems = model.IfcProject.ModelContext(); shape2d.RepresentationIdentifier = "Axis"; shape2d.RepresentationType = "Curve2D"; shape2d.Items.Add_Reversible(ifcPolyline); rep.Representations.Add_Reversible(shape2d); //validate write any errors to the console and commit if ok, otherwise abort if (model.Validate(txn.Modified(), Console.Out) == 0) { txn.Commit(); return(wall); } } return(null); }