Exemple #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);
            }
        }
 internal void PopContext()
 {
     ContextObjects.RemoveAt(0);
 }