Example #1
0
        public static FaceBasedFamilyCreator CreateSimilar(FamilyInstance _fi, Document _tarDoc, double _hostSearchRange)
        {
            var          refDoc = _fi.Document;
            var          pos = _fi.GetPos();
            var          hostCat = HostUtils.GetHostCategory(_fi);
            var          bb = _fi.GetBoundingBoxInModelCS(null);
            var          bbFilter = Methods.GetBBIntersectFilter(bb, _hostSearchRange);
            XYZ          faceNorm = null;
            DesignOption dop; string dopUid, dopName;

            OpContext.GetActiveDesignOptionInfo(_tarDoc, out dop, out dopUid, out dopName);
            var     hostDir = HostUtils.GetHostDir(_fi);
            var     search  = new HostSearchSession(_tarDoc, hostCat, bbFilter, hostDir, faceNorm, dop);
            Element host;
            var     hostFace = search.FindHostFace(pos, out host);
            var     param    = _fi.GetAllEditableParams();
            var     refDocId = refDoc.Identifier();
            var     tarDocId = _tarDoc.Identifier();

            var opContext = new OpContext(refDocId, tarDocId, refDoc, _tarDoc, dopUid, dopName, _fi.Id);
            var ctr       = new FaceBasedFamilyCreator
                                (_fi.Symbol, _fi.Host, hostFace, pos, _fi.HandOrientation, _fi.FacingOrientation, param, opContext);

            return(ctr);
        }
        /// <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);
        }
        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);
        }
Example #4
0
        public static Line GetOffsetLocLine(FamilyInstance _fi)
        {
            var hand           = _fi.HandFlipped ? _fi.HandOrientation * -1.0 : _fi.HandOrientation;
            var facing         = _fi.FacingFlipped ? _fi.FacingOrientation * -1.0 : _fi.FacingOrientation;
            var norm           = hand.CrossProduct(facing);
            var basePlane      = Plane.CreateByNormalAndOrigin(norm, _fi.GetPos());
            var instanceOffset = _fi.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM).AsDouble();
            var symbolOffset   = GetSymbolOffset(_fi.Symbol);
            var profileOffset  = GetProfileOffset(_fi.Symbol);
            var totalOffset    = instanceOffset + symbolOffset + profileOffset;
            var tf             = Transform.CreateTranslation(totalOffset * basePlane.Normal);
            var locLine        = _fi.LocationLine();
            //extension at start and end?
            double startExt = GetStartExtension(_fi, true);
            double endExt   = GetStartExtension(_fi, false);
            var    exLine   = locLine.ExtendOneEndByDist(-1.0 * startExt, 0);

            exLine = exLine.ExtendOneEndByDist(endExt, 1);
            return(exLine.CreateTransformed(tf) as Line);
        }
Example #5
0
        public static WallBasedFamilyCreator CreateSimilar(FamilyInstance _fi, Document _tarDoc, double _hostSearchRange)
        {
            var          refDoc = _fi.Document;
            var          param = _fi.GetAllEditableParams();
            var          refDocId = refDoc.Identifier();
            var          tarDocId = _tarDoc.Identifier();
            DesignOption dop; string dopUid, dopName;

            OpContext.GetActiveDesignOptionInfo(_tarDoc, out dop, out dopUid, out dopName);
            var opContext = new OpContext(refDocId, tarDocId, refDoc, _tarDoc, dopUid, dopName, _fi.Id);
            var hostCat   = HostUtils.GetHostCategory(_fi);
            var hostDir   = HostUtils.GetHostDir(_fi);
            var bb        = _fi.GetBoundingBoxInModelCS(null);
            var bbFilter  = Methods.GetBBIntersectFilter(bb, _hostSearchRange);
            var posPoints = HostUtils.GetPointsInsideWallHost(_fi);
            var search    = new HostSearchSession(_tarDoc, hostCat, bbFilter, hostDir, null, dop);
            var hostWall  = search.FindHostWall(posPoints);
            var ctr       = new WallBasedFamilyCreator
                                (_fi.Symbol, hostWall, _fi.GetPos(), _fi.HandOrientation, _fi.FacingOrientation, _fi.StructuralType, param, opContext);

            return(ctr);
        }
        /// <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);
        }
Example #7
0
 public static List <XYZ> GetPointsInsideWallHost(FamilyInstance _fi)
 {
     if (goaCustomFamilyFilter.IsEnviFamilyInstanceElem(_fi))
     {
         var    pos    = _fi.GetPos();
         double width  = _fi.get_Parameter(FirmStandards.EnviFamParam[7]).AsDouble();
         double height = _fi.Symbol.get_Parameter(FirmStandards.EnviFamParam[8]).AsDouble();
         var    hand   = _fi.HandOrientation;
         var    facing = _fi.FacingOrientation;
         var    cross  = hand.CrossProduct(facing);
         if (_fi.HandFlipped)
         {
             cross *= -1.0;
         }
         if (_fi.FacingFlipped)
         {
             cross *= -1.0;
         }
         var p0     = pos - hand * 0.5 * width;
         var p1     = p0 + hand * width;
         var p2     = p1 + cross * height;
         var p3     = p0 + cross * height;
         var center = (p0 + p2) * 0.5;
         return(new List <XYZ>()
         {
             center, p0, p1, p2, p3
         });
     }
     else
     {
         return(new List <XYZ>()
         {
             _fi.GetBoundingBoxInModelCS(null).GetCentroid()
         });
     }
 }