Example #1
0
        /// <summary>
        /// Create new Load Combination
        /// </summary>
        /// <param name="name">The new Load Combination name</param>
        /// <param name="typeIndex">The index of new Load Combination Type</param>
        /// <param name="stateIndex">The index of new Load Combination State</param>
        /// <returns>true if the creation was successful; otherwise, false</returns>
        public Boolean NewLoadCombination(String name, int typeIndex, int stateIndex)
        {
            // Define some data for creation.
            List <ElementId>     usageIds   = new List <ElementId>();
            List <LoadComponent> components = new List <LoadComponent>();

            double[] factorArray = new double[m_dataBuffer.FormulaMap.Count];

            // First check whether the name has been used
            foreach (String s in m_dataBuffer.LoadCombinationNames)
            {
                if (s == name || null == name)
                {
                    m_dataBuffer.ErrorInformation = "the combination name has been used.";
                    return(false);
                }
            }

            // Get the usage information.
            foreach (UsageMap usageMap in m_dataBuffer.UsageMap)
            {
                if (true == usageMap.Set)
                {
                    LoadUsage usage = FindUsageByName(usageMap.Name);
                    if (null != usage)
                    {
                        usageIds.Add(usage.Id);
                    }
                }
            }

            // Get the formula information
            for (int i = 0; i < m_dataBuffer.FormulaMap.Count; i++)
            {
                FormulaMap formulaMap = m_dataBuffer.FormulaMap[i];
                factorArray[i] = formulaMap.Factor;
                LoadCase loadCase = FindLoadCaseByName(formulaMap.Case);
                if (null != loadCase)
                {
                    LoadComponent component = new LoadComponent(loadCase.Id, formulaMap.Factor);
                    components.Add(component);
                }
            }


            // Begin to new a load combination
            try
            {
                LoadCombination loadCombination = LoadCombination.Create(m_document, name, (LoadCombinationType)typeIndex, (LoadCombinationState)stateIndex);
                if (null == loadCombination)
                {
                    m_dataBuffer.ErrorInformation = "Get null reference after usage creation.";
                    return(false);
                }
                loadCombination.SetComponents(components);
                loadCombination.SetUsageIds(usageIds);

                // Store this load combination information for further use
                m_dataBuffer.LoadCombinationNames.Add(loadCombination.Name);
                LoadCombinationMap combinationMap = new LoadCombinationMap(loadCombination);
                m_dataBuffer.LoadCombinationMap.Add(combinationMap);
            }
            catch (Exception e)
            {
                m_dataBuffer.ErrorInformation = e.Message;
                return(false);
            }

            // If create combination successful, reset the usage check state and clear the formula
            foreach (UsageMap usageMap in m_dataBuffer.UsageMap)
            {
                usageMap.Set = false;
            }
            m_dataBuffer.FormulaMap.Clear();
            return(true);
        }