Exemplo n.º 1
0
        /// <summary>
        /// Gets the hosted element of a host and adds the to a Base object
        /// </summary>
        /// <param name="host"></param>
        /// <param name="base"></param>
        public void GetHostedElements(Base @base, HostObject host)
        {
            var hostedElementIds        = host.FindInserts(true, true, true, true);
            var convertedHostedElements = new List <Base>();

            if (!hostedElementIds.Any())
            {
                return;
            }

            var elementIndex = ContextObjects.FindIndex(obj => obj.applicationId == host.UniqueId);

            if (elementIndex != -1)
            {
                ContextObjects.RemoveAt(elementIndex);
            }

            foreach (var elemId in hostedElementIds)
            {
                var element = Doc.GetElement(elemId);
                var isSelectedInContextObjects = ContextObjects.FindIndex(x => x.applicationId == element.UniqueId);

                if (isSelectedInContextObjects == -1)
                {
                    continue;
                }

                ContextObjects.RemoveAt(isSelectedInContextObjects);

                if (CanConvertToSpeckle(element))
                {
                    var obj = ConvertToSpeckle(element);

                    if (obj != null)
                    {
                        convertedHostedElements.Add(obj);
                        ConvertedObjectsList.Add(obj.applicationId);
                    }
                }
            }

            if (convertedHostedElements.Any())
            {
                if (@base["elements"] == null || !(@base["elements"] is List <Base>))
                {
                    @base["elements"] = new List <Base>();
                }

                (@base["elements"] as List <Base>).AddRange(convertedHostedElements);
            }
        }
Exemplo n.º 2
0
        private bool ShouldConvertHostedElement(DB.Element element, DB.Element host)
        {
            //doesn't have a host, go ahead and convert
            if (host == null)
            {
                return(true);
            }

            // has been converted before (from a parent host), skip it
            if (ConvertedObjectsList.IndexOf(element.UniqueId) != -1)
            {
                return(false);
            }

            // the parent is in our selection list,skip it, as this element will be converted by the host element
            if (ContextObjects.FindIndex(obj => obj.applicationId == host.UniqueId) != -1)
            {
                return(false);
            }
            return(true);
        }