コード例 #1
0
        /// <summary>
        /// Copy wall-based family instances to multiple levels.
        /// </summary>
        /// <param name="_refs">wall-based family instances to be copied.</param>
        /// <param name="_tarLevels">target levels</param>
        /// <param name="_baseLevel">base level for calculating height change.</param>
        /// <param name="_snapShot">snap shot of potential host walls. Need to scan before calling this method.</param>
        /// <returns>wall-based family creators.</returns>
        public static List <FamilyCreator> CopyToLevels
            (FamilyInstance refFI,
            IEnumerable <Level> _tarLevels,
            Level _baseLevel,
            double _searchRange)
        {
            var doc       = refFI.Document;
            var dop       = doc.GetElement(DesignOption.GetActiveDesignOptionId(doc)) as DesignOption;
            var ops       = new List <FamilyCreator>();
            var refPoints = HostUtils.GetPointsInsideWallHost(refFI);
            //get params
            var param = refFI.GetAllEditableParams();
            //get orientation
            var hand   = refFI.HandOrientation;
            var facing = refFI.FacingOrientation;
            //search cat
            var bbRef = refFI.GetBoundingBoxForSolidGeometries();

            if (bbRef == null)
            {
                bbRef = refFI.GetBoundingBoxInModelCS(null);
            }
            var hostDir = HostUtils.GetHostDir(refFI);

            foreach (var tarLevel in _tarLevels)
            {
                //skip base level
                if (tarLevel.Id == _baseLevel.Id)
                {
                    continue;
                }
                var deltaZ    = tarLevel.ProjectElevation - _baseLevel.ProjectElevation;
                var tf        = Transform.CreateTranslation(new XYZ(0, 0, deltaZ));
                var tarPoints = refPoints.Select(x => tf.OfPoint(x)).ToList();

                //search host face
                var bbTar    = bbRef.GetTransformed(tf);
                var bbFilter = Methods.GetBBIntersectFilter(bbTar, _searchRange);
                var search   = new HostSearchSession(doc, HostCategory.Wall, bbFilter, hostDir, null, dop);
                var hostWall = search.FindHostWall(tarPoints);
                if (hostWall == null)
                {
                    throw new HostNotFoundException(refFI.Id.ToString());
                }

                var tarPos = tf.OfPoint(refFI.GetPos());
                var ctr    = new WallBasedFamilyCreator
                                 (refFI.Symbol,
                                 hostWall,
                                 tarPos,
                                 hand, facing,
                                 refFI.StructuralType,
                                 param,
                                 null);
                ops.Add(ctr);
            }
            return(ops);
        }
コード例 #2
0
        public static FamilyCreator Mirror
            (FamilyInstance refFI,
            Plane _mirrorPlane,
            double _hostSearchRange)
        {
            var doc       = refFI.Document;
            var dop       = doc.GetElement(DesignOption.GetActiveDesignOptionId(doc)) as DesignOption;
            var tf        = Transform.CreateReflection(_mirrorPlane);
            var refPoints = HostUtils.GetPointsInsideWallHost(refFI);
            var tarPoints = refPoints.Select(x => tf.OfPoint(x)).ToList();
            //get params
            var param = refFI.GetAllEditableParams();
            //get orientation
            var hand   = tf.OfVector(refFI.HandOrientation);
            var facing = tf.OfVector(refFI.FacingOrientation);
            //host search
            var refHostDir = HostUtils.GetHostDir(refFI);
            var hostDir    = refHostDir == null
                ? null
                : tf.OfVector(refHostDir);
            var bb = refFI.GetBoundingBoxForSolidGeometries();

            if (bb == null)
            {
                bb = refFI.GetBoundingBoxInModelCS(null);
            }
            var bbMr     = bb.GetTransformed(tf);
            var bbFilter = Methods.GetBBIntersectFilter(bbMr, 3.0);
            var search   = new HostSearchSession(doc, HostCategory.Wall, bbFilter, hostDir, null, dop);
            var hostWall = search.FindHostWall(tarPoints);

            if (hostWall == null)
            {
                throw new HostNotFoundException(refFI.Id.ToString());
            }
            var tarPos = tf.OfPoint(refFI.GetPos());

            var ctr = new WallBasedFamilyCreator
                          (refFI.Symbol,
                          hostWall,
                          tarPos,
                          hand, facing,
                          refFI.StructuralType,
                          param,
                          null);

            return(ctr);
        }
コード例 #3
0
        public static FamilyCreator MirrorFaceBased
            (FamilyInstance _fi, Plane _plane, double _hostSearchRange)
        {
            var tf  = Transform.CreateReflection(_plane);
            var doc = _fi.Document;
            var dop = doc.GetElement(DesignOption.GetActiveDesignOptionId(doc)) as DesignOption;
            //host search
            var bb = _fi.GetBoundingBoxForSolidGeometries();

            if (bb == null)
            {
                bb = _fi.GetBoundingBoxInModelCS(null);
            }
            bb = bb.GetTransformed(tf);
            var filter  = Methods.GetBBIntersectFilter(bb, _hostSearchRange);
            var hostCat = HostUtils.GetHostCategory(_fi);
            var hostDir = HostUtils.GetHostDir(_fi);

            if (hostDir != null)
            {
                hostDir = tf.OfVector(hostDir);
            }

            var refOffsetLocLine = LineBasedFamilyUtils.GetOffsetLocLine(_fi);
            var tarOffsetLocLine = refOffsetLocLine.CreateTransformed(tf) as Line;
            var refLocLine       = _fi.LocationLine();
            var tarLocLine       = refLocLine.CreateTransformed(tf) as Line;
            var facing           = tf.OfVector(_fi.FacingOrientation);
            var faceNormal       = tf.OfVector(_fi.GetPlane().Normal);

            var     search = new HostSearchSession(doc, hostCat, filter, hostDir, faceNormal, dop);
            Element host;
            var     hostFace = search.FindHostFace(tarLocLine, out host);

            if (hostFace == null)
            {
                throw new HostNotFoundException(_fi.Id.ToString());
            }

            var param = _fi.GetAllEditableParams();
            var ctr   = new LineBasedFamilyCreator_onPlanarFace
                            (_fi.Symbol, tarOffsetLocLine, facing, host, hostFace, param, null);

            ctr.CutsHost = HostUtils.CutsHost(_fi);
            return(ctr);
        }
コード例 #4
0
        /// <summary>
        /// TRANSACTIONS INSIDE.
        /// Create mirror ONLY FOR vertical host face.
        /// </summary>
        public static FamilyCreator Mirror
            (FamilyInstance fi, Plane _plane, double _hostSearchRange)
        {
            var doc        = fi.Document;
            var dop        = doc.GetElement(DesignOption.GetActiveDesignOptionId(doc)) as DesignOption;
            var tf         = Transform.CreateReflection(_plane);
            var refPos     = fi.GetPos();
            var tarPos     = tf.OfPoint(refPos);
            var hand       = tf.OfVector(fi.HandOrientation);
            var facing     = tf.OfVector(fi.FacingOrientation);
            var refPlane   = fi.GetPlane();
            var faceNormal = tf.OfVector(refPlane.Normal);
            //find host face
            var bb = fi.GetBoundingBoxForSolidGeometries();

            if (bb == null)
            {
                bb = fi.GetBoundingBoxInModelCS(null);
            }
            bb = bb.GetTransformed(tf);
            var     bbFilter = Methods.GetBBIntersectFilter(bb, _hostSearchRange);
            var     hostCat  = HostUtils.GetHostCategory(fi);
            var     hostDir  = HostUtils.GetHostDir(fi);
            var     search   = new HostSearchSession(doc, hostCat, bbFilter, hostDir, faceNormal, dop);
            Element host;
            var     hostFace = search.FindHostFace(tarPos, out host);

            if (hostFace == null)
            {
                throw new HostNotFoundException(fi.Id.ToString());
            }
            var param = fi.GetAllEditableParams();
            var ctr   = new FaceBasedFamilyCreator
                            (fi.Symbol, host, hostFace, tarPos, hand, facing, param, null);

            return(ctr);
        }
コード例 #5
0
        /// <summary>
        /// Copy line-based family instances to multiple levels.
        /// </summary>
        /// <param name="_refs">line-based family instances to be copied.</param>
        /// <param name="_tarLevels">target levels</param>
        /// <param name="_baseLevel">base level for calculating height change.</param>
        /// <param name="_snapShot">snap shot of potential host faces. Need to scan before calling this method.</param>
        /// <returns>Line-based family creators of correct type.</returns>
        public static List <FamilyCreator> CopyToLevels
            (FamilyInstance _refFI,
            IEnumerable <Level> _tarLevels,
            Level _baseLevel,
            double _searchRange)
        {
            var doc        = _refFI.Document;
            var dop        = doc.GetElement(DesignOption.GetActiveDesignOptionId(doc)) as DesignOption;
            var ops        = new List <FamilyCreator>();
            var refLocLine = _refFI.LocationLine();
            //get params
            var param = _refFI.GetAllEditableParams();
            //get orientation
            var facing     = _refFI.FacingOrientation;
            var faceNormal = _refFI.GetPlane().Normal;
            //scan for host face
            var hostCat = HostUtils.GetHostCategory(_refFI);
            var hostDir = HostUtils.GetHostDir(_refFI);
            var bbRef   = _refFI.GetBoundingBoxForSolidGeometries();

            if (bbRef == null)
            {
                bbRef = _refFI.GetBoundingBoxInModelCS(null);
            }
            bool cutsHost = HostUtils.CutsHost(_refFI);

            foreach (var tarLevel in _tarLevels)
            {
                //skip base level
                if (tarLevel.Id == _baseLevel.Id)
                {
                    continue;
                }
                var deltaZ     = tarLevel.ProjectElevation - _baseLevel.ProjectElevation;
                var tf         = Transform.CreateTranslation(new XYZ(0, 0, deltaZ));
                var tarLocLine = refLocLine.CreateTransformed(tf) as Line;
                //check host dir
                FamilyCreator ctr  = null;
                var           info = new LineBasedFamilyInfo(_refFI);
                //host on level
                if (hostCat == HostCategory.Level)
                {
                    ctr = new LineBasedFamilyCreator_onLevel
                              (_refFI.Symbol,
                              tarLocLine,
                              _refFI.FacingOrientation,
                              tarLevel,
                              _refFI.StructuralType,
                              param,
                              null);
                }
                //host on face
                else
                {
                    //search host face
                    var     bbTar  = bbRef.GetTransformed(tf);
                    var     filter = Methods.GetBBIntersectFilter(bbTar, _searchRange);
                    var     search = new HostSearchSession(doc, hostCat, filter, hostDir, faceNormal, dop);
                    Element host;
                    var     hostFace = search.FindHostFace(tarLocLine, out host);
                    if (hostFace == null)
                    {
                        throw new HostNotFoundException(_refFI.Id.ToString());
                    }
                    var refOffsetLocLine = LineBasedFamilyUtils.GetOffsetLocLine(_refFI);
                    var tarOffsetLocLine = refOffsetLocLine.CreateTransformed(tf) as Line;
                    var lineBasedCtr     = new LineBasedFamilyCreator_onPlanarFace
                                               (_refFI.Symbol,
                                               tarOffsetLocLine,
                                               facing,
                                               host,
                                               hostFace,
                                               param,
                                               null);
                    lineBasedCtr.CutsHost = cutsHost;
                    ctr = lineBasedCtr;
                }
                ops.Add(ctr);
            }
            return(ops);
        }