Example #1
0
        public static LineBasedFamilyCreator_onPlanarFace CreateSimilar(FamilyInstance _fi, Document _tarDoc, double _hostSearchRange)
        {
            var          refDoc = _fi.Document;
            var          refDocId = refDoc.Identifier();
            var          tarDocId = _tarDoc.Identifier();
            var          locLine = _fi.LocationLine();
            var          offsetLocLine = LineBasedFamilyUtils.GetOffsetLocLine(_fi);
            var          param = _fi.GetAllEditableParams();
            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     faceNorm  = _fi.GetPlane().Normal;
            var     bb       = _fi.GetBoundingBoxInModelCS(null);
            var     bbFilter = Methods.GetBBIntersectFilter(bb, _hostSearchRange);
            var     search   = new HostSearchSession(_tarDoc, hostCat, bbFilter, hostDir, faceNorm, dop);
            Element host;
            var     hostFace = search.FindHostFace(locLine, out host);
            var     ctr      = new LineBasedFamilyCreator_onPlanarFace
                                   (_fi.Symbol, offsetLocLine, _fi.FacingOrientation, host, hostFace, param, opContext);

            Methods.GetCutsAndJoins(_fi, out ctr.Cuts, out ctr.CutBy, out ctr.Joins);
            ctr.CutsHost = HostUtils.CutsHost(_fi);
            return(ctr);
        }
Example #2
0
        public LineBasedFamilyInfo(FamilyInstance fi)
        {
            this.FI            = fi;
            this.LocLine       = fi.LocationLine();
            this.OffsetLocLine = LineBasedFamilyUtils.GetOffsetLocLine(fi);

            getHostCondition(fi);
        }
Example #3
0
        private void calcOffset()
        {
            var    norm           = HostUtils.GetHostNormal(this.NewFI);
            var    p0             = this.NewFI.LocationCurve().GetEndPoint(0);
            var    pOffset        = this.OffsetLocLine.GetEndPoint(0);
            var    totalOffset    = (pOffset - p0).DotProduct(norm);
            double symbolOffset   = LineBasedFamilyUtils.GetSymbolOffset(this.fs);
            double profileOffset  = LineBasedFamilyUtils.GetProfileOffset(this.fs);
            double instanceOffset = totalOffset - symbolOffset - profileOffset;

            this.NewFI.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM).Set(instanceOffset);
        }
Example #4
0
        public static LineBasedFamilyCreator_onLevel CreateSimilar(FamilyInstance _fi, Document _tarDoc, int _hostLevel)
        {
            var          hostLevel = _fi.Host as Level;
            var          offsetLocLine = LineBasedFamilyUtils.GetOffsetLocLine(_fi);
            var          param = _fi.GetAllEditableParams();
            var          refDoc = _fi.Document;
            var          refDocId = _fi.Document.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 ctr = new LineBasedFamilyCreator_onLevel
                          (_fi.Symbol, offsetLocLine, _fi.FacingOrientation, hostLevel, _fi.StructuralType, param, opContext);

            return(ctr);
        }
        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);
        }
        /// <summary>
        /// TRANSACTIONS INSIDE
        /// </summary>
        public static void ExecuteSingleLoop
            (Document _doc,
            IEnumerable <ElementOperator> _ops,
            bool _forceRecreate,
            out List <ElementOperator> _reCreated,
            out List <ElementOperator> _notExecuted)
        {
            _reCreated   = new List <ElementOperator>();
            _notExecuted = new List <ElementOperator>();

            //commit operations
            Operation123(_doc, _ops);

            if (_forceRecreate)
            {
                //check if any failed ops
                var needToRecreate = new List <LineBasedFamilyEditor>();
                foreach (var op in _ops)
                {
                    //line-based family might be draged by each other
                    if (op is LineBasedFamilyEditor)
                    {
                        var lbEdtr = op as LineBasedFamilyEditor;
                        //if ops are not finished due to other cause, skip
                        if (lbEdtr.OperationFinished == false)
                        {
                            continue;
                        }
                        var offsetLocLine = LineBasedFamilyUtils.GetOffsetLocLine(lbEdtr.FI);
                        Debug.WriteLine("id: " + lbEdtr.FI.Id);
                        Debug.WriteLine("oll: " + offsetLocLine.ToStringCenterLength(3));
                        var expected = lbEdtr.OffsetLocLine;
                        Debug.WriteLine("exp: " + expected.ToStringCenterLength(3));
                        if (expected != null &&
                            expected.ToStringCenterLength(3) != offsetLocLine.ToStringCenterLength(3))
                        {
                            var similarCtr = lbEdtr.GetSimilarCreator();
                            similarCtr.RecreatedFrom = lbEdtr.Elem.Id;
                            _reCreated.Add(similarCtr);
                            needToRecreate.Add(lbEdtr);
                        }
                    }
                }
                if (needToRecreate.Count != 0)
                {
                    //re-create failed
                    Operation123(_doc, _reCreated);

                    using (Transaction trans = new Transaction(_doc, "delete dup"))
                    {
                        trans.Start();
                        foreach (var edtr in needToRecreate)
                        {
                            edtr.OperationFinished = true;
                            _doc.Delete(edtr.FI.Id);
                        }
                        trans.Commit();
                    }
                }
            }
            //get unfinished ops, due to design options (or other causes)
            _notExecuted = _ops.Where(x => x.OperationFinished == false).ToList();
            return;
        }
        /// <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);
        }