Example #1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            var            r  = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
            FamilyInstance fi = doc.GetElement(r) as FamilyInstance;

            if (fi == null)
            {
                TaskDialog.Show("Tip", "选择的不是 族实例");
                return(Result.Cancelled);
            }

            var instanceGeomElem = GeometryTestUtils.GetInstanceGeometry(fi);

            if (instanceGeomElem != null)
            {
                // 类型几何 对应模型坐标系
                var symbolGeom = instanceGeomElem.GetSymbolGeometry();
                // 实例几何 对应族坐标系
                var instanceGeom = instanceGeomElem.GetInstanceGeometry();

                // 族坐标系 到 模型坐标系 的转换
                var transform = instanceGeomElem.Transform;

                // 未被切割过的几何 对应模型坐标系
                var geom = fi.GetOriginalGeometry(new Options());
            }


            return(Result.Succeeded);
        }
Example #2
0
        OriginalInstanceGeometry(string label, FamilyInstance val, Autodesk.Revit.ApplicationServices.Application app)
            : base(label)
        {
            m_val = val;
            m_app = app;

            m_hasGeometry = false;

            if (m_val != null && m_app != null)
            {
                Autodesk.Revit.DB.Options geomOp = m_app.Create.NewGeometryOptions();
                geomOp.DetailLevel = ViewDetailLevel.Undefined;
                if (m_val.GetOriginalGeometry(geomOp) != null)
                {
                    m_hasGeometry = true;
                }
            }
        }
Example #3
0
        static private int GetFamilyInstanceHashCode(FamilyInstance instance)
        {
            if (instance == null)
            {
                return(-1);
            }

            GeometryElement geometryElement = instance.GetOriginalGeometry(new Options()
            {
                DetailLevel = (ViewDetailLevel)ExportEventHandler.Settings.DetailLevel
            });

            if (geometryElement == null)
            {
                return(-1);
            }

            return(geometryElement.GetHashCode());
        }
Example #4
0
        private void CalculateDoorWindowInformation(ExporterIFC exporterIFC, FamilyInstance famInst,
                                                    ElementId overrideLevelId, Transform trf)
        {
            IFCFile file = exporterIFC.GetFile();

            if (ExportingDoor)
            {
                string doorOperationType = null;

                Element doorType = famInst.Document.GetElement(famInst.GetTypeId());
                if (doorType != null)
                {
                    // Look at the "Operation" override first, then the built-in parameter.
                    ParameterUtil.GetStringValueFromElementOrSymbol(doorType, "Operation", out doorOperationType);
                    if (!string.IsNullOrWhiteSpace(doorOperationType))
                    {
                        ParameterUtil.GetStringValueFromElement(doorType, BuiltInParameter.DOOR_OPERATION_TYPE, out doorOperationType);
                    }
                }

                DoorOperationTypeString = "NOTDEFINED";
                if (!string.IsNullOrWhiteSpace(doorOperationType))
                {
                    Type enumType = null;
                    if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                    {
                        enumType = typeof(Toolkit.IFC4.IFCDoorStyleOperation);
                    }
                    else
                    {
                        enumType = typeof(Toolkit.IFCDoorStyleOperation);
                    }

                    foreach (Enum ifcDoorStyleOperation in Enum.GetValues(enumType))
                    {
                        string enumAsString = ifcDoorStyleOperation.ToString();
                        if (NamingUtil.IsEqualIgnoringCaseSpacesAndUnderscores(enumAsString, doorOperationType))
                        {
                            DoorOperationTypeString = enumAsString;
                            break;
                        }
                    }
                }

                if (DoorOperationTypeString == "NOTDEFINED")
                {
                    // We are going to try to guess the hinge placement.
                    DoorOperationTypeString = CalculateDoorOperationStyle(famInst);
                }

                if (FlippedX ^ FlippedY)
                {
                    DoorOperationTypeString = ReverseDoorStyleOperation(DoorOperationTypeString);
                }

                if (String.Compare(DoorOperationTypeString, "USERDEFINED", true) == 0)
                {
                    string userDefinedOperationType;
                    ParameterUtil.GetStringValueFromElementOrSymbol(doorType, "UserDefinedOperationType", out userDefinedOperationType);
                    if (!string.IsNullOrEmpty(userDefinedOperationType))
                    {
                        UserDefinedOperationType = userDefinedOperationType;
                    }
                    else
                    {
                        DoorOperationTypeString = "NOTDEFINED";   //re-set to NotDefined if operation type is set to UserDefined but the userDefinedOperationType parameter is empty!
                    }
                }
            }

            if (HasRealWallHost)
            {
                // do hingeside calculation
                Wall wall = HostObject as Wall;
                PosHingeSide = true;

                BoundingBoxXYZ  famBBox     = null;
                Options         options     = GeometryUtil.GetIFCExportGeometryOptions();
                GeometryElement geomElement = famInst.GetOriginalGeometry(options);
                if (geomElement != null)
                {
                    famBBox = geomElement.GetBoundingBox();
                }

                if (famBBox != null)
                {
                    XYZ bboxCtr = trf.OfPoint((famBBox.Min + famBBox.Max) / 2.0);

                    Curve curve = WallExporter.GetWallAxis(wall);

                    XYZ wallZDir = WallExporter.GetWallHeightDirection(wall);

                    // famInst.HostParameter will fail if FamilyPlacementType is WorkPlaneBased, regardless of whether or not the reported host is a Wall.
                    // In this case, just use the start parameter of the curve.
                    bool   hasHostParameter = famInst.Symbol.Family.FamilyPlacementType != FamilyPlacementType.WorkPlaneBased;
                    double param            = hasHostParameter ? famInst.HostParameter : curve.GetEndParameter(0);

                    Transform wallTrf  = curve.ComputeDerivatives(param, false);
                    XYZ       wallOrig = wallTrf.Origin;
                    XYZ       wallXDir = wallTrf.BasisX;
                    XYZ       wallYDir = wallZDir.CrossProduct(wallXDir);

                    double eps = MathUtil.Eps();

                    bboxCtr     -= wallOrig;
                    PosHingeSide = (bboxCtr.DotProduct(wallYDir) > -eps);

                    XYZ famInstYDir = trf.BasisY;
                    FlippedSymbol = (PosHingeSide != (wallYDir.DotProduct(famInstYDir) > -eps));
                }
            }
        }
Example #5
0
        protected void AddObjectsToTree(FamilyInstance elem, TreeNodeCollection curNodes)
        {
            Autodesk.Revit.DB.Options geomOp = m_app.Create.NewGeometryOptions();
             geomOp.ComputeReferences = false; // Not allowed for GetOriginalGeometry()!
             TreeNode tmpNode;

             // add geometry with the View set to null.
             TreeNode rootNode1 = new TreeNode("View = null");
             curNodes.Add(rootNode1);

             tmpNode = new TreeNode("Detail Level = Undefined");
             geomOp.DetailLevel = ViewDetailLevel.Undefined;
             tmpNode.Tag = elem.GetOriginalGeometry(geomOp);
             rootNode1.Nodes.Add(tmpNode);

             tmpNode = new TreeNode("Detail Level = Coarse");
             geomOp.DetailLevel = ViewDetailLevel.Coarse;
             tmpNode.Tag = elem.GetOriginalGeometry(geomOp);
             rootNode1.Nodes.Add(tmpNode);

             tmpNode = new TreeNode("Detail Level = Medium");
             geomOp.DetailLevel = ViewDetailLevel.Medium;
             tmpNode.Tag = elem.GetOriginalGeometry(geomOp);
             rootNode1.Nodes.Add(tmpNode);

             tmpNode = new TreeNode("Detail Level = Fine");
             geomOp.DetailLevel = ViewDetailLevel.Fine;
             tmpNode.Tag = elem.GetOriginalGeometry(geomOp);
             rootNode1.Nodes.Add(tmpNode);

             // SOFiSTiK FS
             // add model geometry including geometry objects not set as Visible.
             {
            Autodesk.Revit.DB.Options opts = m_app.Create.NewGeometryOptions();
            opts.ComputeReferences = false; // Not allowed for GetOriginalGeometry()!;
            opts.IncludeNonVisibleObjects = true;

            TreeNode rootNode = new TreeNode("View = null - Including geometry objects not set as Visible");
            curNodes.Add(rootNode);

            tmpNode = new TreeNode("Detail Level = Undefined");
            opts.DetailLevel = ViewDetailLevel.Undefined;
            tmpNode.Tag = elem.GetOriginalGeometry(opts);
            rootNode.Nodes.Add(tmpNode);

            tmpNode = new TreeNode("Detail Level = Coarse");
            opts.DetailLevel = ViewDetailLevel.Coarse;
            tmpNode.Tag = elem.GetOriginalGeometry(opts);
            rootNode.Nodes.Add(tmpNode);

            tmpNode = new TreeNode("Detail Level = Medium");
            opts.DetailLevel = ViewDetailLevel.Medium;
            tmpNode.Tag = elem.GetOriginalGeometry(opts);
            rootNode.Nodes.Add(tmpNode);

            tmpNode = new TreeNode("Detail Level = Fine");
            opts.DetailLevel = ViewDetailLevel.Fine;
            tmpNode.Tag = elem.GetOriginalGeometry(opts);
            rootNode.Nodes.Add(tmpNode);
             }

             // now add geometry with the View set to the current view
             if (elem.Document.ActiveView != null)
             {
            Options geomOp2 = m_app.Create.NewGeometryOptions();
            geomOp2.ComputeReferences = false; // Not allowed for GetOriginalGeometry()!;
            geomOp2.View = elem.Document.ActiveView;

            TreeNode rootNode2 = new TreeNode("View = Document.ActiveView");
            rootNode2.Tag = elem.GetOriginalGeometry(geomOp2);
            curNodes.Add(rootNode2);

            // SOFiSTiK FS
            // add model geometry including geometry objects not set as Visible.
            {
               Autodesk.Revit.DB.Options opts = m_app.Create.NewGeometryOptions();
               opts.ComputeReferences = false; // Not allowed for GetOriginalGeometry()!;
               opts.IncludeNonVisibleObjects = true;
               opts.View = elem.Document.ActiveView;

               TreeNode rootNode = new TreeNode("View = Document.ActiveView - Including geometry objects not set as Visible");
               curNodes.Add(rootNode);

               rootNode.Tag = elem.GetOriginalGeometry(opts);
            }
             }
        }
        private void CalculateDoorWindowInformation(ExporterIFC exporterIFC, FamilyInstance famInst, 
            ElementId overrideLevelId, Transform trf)
        {
            IFCFile file = exporterIFC.GetFile();

            if (ExportingDoor)
            {
                string doorOperationType = null;

                Element doorType = famInst.Document.GetElement(famInst.GetTypeId());
                if (doorType != null)
                    ParameterUtil.GetStringValueFromElement(doorType, BuiltInParameter.DOOR_OPERATION_TYPE, out doorOperationType);

                DoorOperationTypeString = "NOTDEFINED";
                if (!string.IsNullOrWhiteSpace(doorOperationType))
                {
                    Type enumType = null;
                    if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                        enumType = typeof(Toolkit.IFC4.IFCDoorStyleOperation);
                    else
                        enumType = typeof(Toolkit.IFCDoorStyleOperation);

                    foreach (Enum ifcDoorStyleOperation in Enum.GetValues(enumType))
                    {
                        string enumAsString = ifcDoorStyleOperation.ToString();
                        if (NamingUtil.IsEqualIgnoringCaseSpacesAndUnderscores(enumAsString, doorOperationType))
                        {
                            DoorOperationTypeString = enumAsString;
                            break;
                        }
                    }
                }

                if (DoorOperationTypeString == "NOTDEFINED")
                {
                    // We are going to try to guess the hinge placement.
                    DoorOperationTypeString = CalculateDoorOperationStyle(famInst);
                }
                
                if (FlippedX ^ FlippedY)
                    DoorOperationTypeString = ReverseDoorStyleOperation(DoorOperationTypeString);

                if (String.Compare(DoorOperationTypeString, "USERDEFINED", true) == 0)
                {
                    string userDefinedOperationType;
                    ParameterUtil.GetStringValueFromElementOrSymbol(doorType, "UserDefinedOperationType", out userDefinedOperationType);
                    if (!string.IsNullOrEmpty(userDefinedOperationType))
                        UserDefinedOperationType = userDefinedOperationType;
                    else
                        DoorOperationTypeString = "NOTDEFINED";         //re-set to NotDefined if operation type is set to UserDefined but the userDefinedOperationType parameter is empty!
                }
            }

            if (HasRealWallHost)
            {
                // do hingeside calculation
                Wall wall = HostObject as Wall;
                PosHingeSide = true;

                BoundingBoxXYZ famBBox = null;
                Options options = GeometryUtil.GetIFCExportGeometryOptions();
                GeometryElement geomElement = famInst.GetOriginalGeometry(options);
                if (geomElement != null)
                    famBBox = geomElement.GetBoundingBox();

                if (famBBox != null)
                {
                    XYZ bboxCtr = trf.OfPoint((famBBox.Min + famBBox.Max) / 2.0);

                    Curve curve = WallExporter.GetWallAxis(wall);

                    XYZ wallZDir = WallExporter.GetWallHeightDirection(wall);

                    // famInst.HostParameter will fail if FamilyPlacementType is WorkPlaneBased, regardless of whether or not the reported host is a Wall.
                    // In this case, just use the start parameter of the curve.
                    bool hasHostParameter = famInst.Symbol.Family.FamilyPlacementType != FamilyPlacementType.WorkPlaneBased;
                    double param = hasHostParameter ? famInst.HostParameter : curve.GetEndParameter(0);

                    Transform wallTrf = curve.ComputeDerivatives(param, false);
                    XYZ wallOrig = wallTrf.Origin;
                    XYZ wallXDir = wallTrf.BasisX;
                    XYZ wallYDir = wallZDir.CrossProduct(wallXDir);

                    double eps = MathUtil.Eps();

                    bboxCtr -= wallOrig;
                    PosHingeSide = (bboxCtr.DotProduct(wallYDir) > -eps);

                    XYZ famInstYDir = trf.BasisY;
                    FlippedSymbol = (PosHingeSide != (wallYDir.DotProduct(famInstYDir) > -eps));
                }
            }
        }
Example #7
0
        AddObjectsToTree(FamilyInstance elem, TreeNodeCollection curNodes)
        {
            Autodesk.Revit.DB.Options geomOp = m_app.Create.NewGeometryOptions();
            geomOp.ComputeReferences = false; // Not allowed for GetOriginalGeometry()!
            TreeNode tmpNode;

            // add geometry with the View set to null.
            TreeNode rootNode1 = new TreeNode("View = null");

            curNodes.Add(rootNode1);

            tmpNode            = new TreeNode("Detail Level = Undefined");
            geomOp.DetailLevel = ViewDetailLevel.Undefined;
            tmpNode.Tag        = elem.GetOriginalGeometry(geomOp);
            rootNode1.Nodes.Add(tmpNode);

            tmpNode            = new TreeNode("Detail Level = Coarse");
            geomOp.DetailLevel = ViewDetailLevel.Coarse;
            tmpNode.Tag        = elem.GetOriginalGeometry(geomOp);
            rootNode1.Nodes.Add(tmpNode);

            tmpNode            = new TreeNode("Detail Level = Medium");
            geomOp.DetailLevel = ViewDetailLevel.Medium;
            tmpNode.Tag        = elem.GetOriginalGeometry(geomOp);
            rootNode1.Nodes.Add(tmpNode);

            tmpNode            = new TreeNode("Detail Level = Fine");
            geomOp.DetailLevel = ViewDetailLevel.Fine;
            tmpNode.Tag        = elem.GetOriginalGeometry(geomOp);
            rootNode1.Nodes.Add(tmpNode);

            // SOFiSTiK FS
            // add model geometry including geometry objects not set as Visible.
            {
                Autodesk.Revit.DB.Options opts = m_app.Create.NewGeometryOptions();
                opts.ComputeReferences        = false; // Not allowed for GetOriginalGeometry()!;
                opts.IncludeNonVisibleObjects = true;

                TreeNode rootNode = new TreeNode("View = null - Including geometry objects not set as Visible");
                curNodes.Add(rootNode);

                tmpNode          = new TreeNode("Detail Level = Undefined");
                opts.DetailLevel = ViewDetailLevel.Undefined;
                tmpNode.Tag      = elem.GetOriginalGeometry(opts);
                rootNode.Nodes.Add(tmpNode);

                tmpNode          = new TreeNode("Detail Level = Coarse");
                opts.DetailLevel = ViewDetailLevel.Coarse;
                tmpNode.Tag      = elem.GetOriginalGeometry(opts);
                rootNode.Nodes.Add(tmpNode);

                tmpNode          = new TreeNode("Detail Level = Medium");
                opts.DetailLevel = ViewDetailLevel.Medium;
                tmpNode.Tag      = elem.GetOriginalGeometry(opts);
                rootNode.Nodes.Add(tmpNode);

                tmpNode          = new TreeNode("Detail Level = Fine");
                opts.DetailLevel = ViewDetailLevel.Fine;
                tmpNode.Tag      = elem.GetOriginalGeometry(opts);
                rootNode.Nodes.Add(tmpNode);
            }

            // now add geometry with the View set to the current view
            if (elem.Document.ActiveView != null)
            {
                Options geomOp2 = m_app.Create.NewGeometryOptions();
                geomOp2.ComputeReferences = false; // Not allowed for GetOriginalGeometry()!;
                geomOp2.View = elem.Document.ActiveView;

                TreeNode rootNode2 = new TreeNode("View = Document.ActiveView");
                rootNode2.Tag = elem.GetOriginalGeometry(geomOp2);
                curNodes.Add(rootNode2);

                // SOFiSTiK FS
                // add model geometry including geometry objects not set as Visible.
                {
                    Autodesk.Revit.DB.Options opts = m_app.Create.NewGeometryOptions();
                    opts.ComputeReferences        = false; // Not allowed for GetOriginalGeometry()!;
                    opts.IncludeNonVisibleObjects = true;
                    opts.View = elem.Document.ActiveView;

                    TreeNode rootNode = new TreeNode("View = Document.ActiveView - Including geometry objects not set as Visible");
                    curNodes.Add(rootNode);

                    rootNode.Tag = elem.GetOriginalGeometry(opts);
                }
            }
        }
Example #8
0
        public OriginalInstanceGeometry(string label, FamilyInstance val, Autodesk.Revit.ApplicationServices.Application app)
            : base(label)
        {
            m_val = val;
             m_app = app;

             m_hasGeometry = false;

             if (m_val != null && m_app != null)
             {
            Autodesk.Revit.DB.Options geomOp = m_app.Create.NewGeometryOptions();
            geomOp.DetailLevel = ViewDetailLevel.Undefined;
            if (m_val.GetOriginalGeometry(geomOp) != null)
               m_hasGeometry = true;
             }
        }