/// <summary> /// Find a load usage by the load usage name /// </summary> /// <param name="name">The name of load usage</param> /// <returns>The reference of the LoadUsage</returns> private LoadUsage FindUsageByName(String name) { LoadUsage usage = null; foreach (LoadUsage l in m_dataBuffer.LoadUsages) { if (name == l.Name) { usage = l; break; } } return(usage); }
/// <summary> /// Delete the selected Load Usage /// </summary> /// <param name="index">The selected index in the DataGridView</param> /// <returns>true if the delete operation was successful; otherwise, false</returns> public Boolean DeleteUsage(int index) { // Get the delete usage LoadUsage deleteUsage = m_dataBuffer.LoadUsages[index]; String usageName = deleteUsage.Name; // Begin to delete the combination try { m_document.Delete(deleteUsage.Id); } catch (Exception e) { m_dataBuffer.ErrorInformation = e.ToString(); return(false); } // Modify the data to show the delete operation m_dataBuffer.LoadUsages.RemoveAt(index); m_dataBuffer.LoadUsageNames.RemoveAt(index); m_dataBuffer.UsageMap.RemoveAt(index); // Need to delete corresponding in Combination foreach (LoadCombinationMap map in m_dataBuffer.LoadCombinationMap) { String oldUsage = map.Usage; int location = oldUsage.IndexOf(usageName); if (-1 == location) { continue; } if (oldUsage.Length == usageName.Length) { map.Usage = oldUsage.Remove(0); continue; } if (0 == location) { map.Usage = oldUsage.Remove(location, usageName.Length + 1); } else { map.Usage = oldUsage.Remove(location - 1, usageName.Length + 1); } } return(true); }
/// <summary> /// Find out all Load Combination and Usage in the existing document. /// As specification require, prepare some Load Combination Usages if they are not in document /// </summary> public void PrepareData() { // Find out all Load Combination and Usage in the existing document. IList <Element> elements = (new FilteredElementCollector(m_document)).OfClass(typeof(LoadCombination)).ToElements(); foreach (Element elem in elements) { LoadCombination combination = elem as LoadCombination; if (null != combination) { // Add the Load Combination name. m_dataBuffer.LoadCombinationNames.Add(combination.Name); // Create LoadCombinationMap object. LoadCombinationMap combinationMap = new LoadCombinationMap(combination); // Add the LoadCombinationMap object to the array list. m_dataBuffer.LoadCombinationMap.Add(combinationMap); } } elements = (new FilteredElementCollector(m_document)).OfClass(typeof(LoadUsage)).ToElements(); foreach (Element elem in elements) { // Add Load Combination Usage information LoadUsage usage = elem as LoadUsage; if (null != usage) { // Add the Load Usage name m_dataBuffer.LoadUsageNames.Add(usage.Name); // Add the Load Usage object to a LoadUsageArray m_dataBuffer.LoadUsages.Add(usage); // Add the Load Usage information to UsageMap. UsageMap usageMap = new UsageMap(m_dataBuffer, usage.Name); m_dataBuffer.UsageMap.Add(usageMap); } } // As specification require, some Load Combination Usages if they are not in document String[] initUsageArray = { "Gravity", "Lateral", "Steel", "Composite", "Concrete" }; foreach (String s in initUsageArray) { NewLoadUsage(s); } }
/// <summary> /// Create a new load combination usage /// </summary> /// <param name="usageName">The new Load Usage name</param> /// <returns>true if the process is successful; otherwise, false</returns> public Boolean NewLoadUsage(String usageName) { // First check whether the name has been used foreach (String s in m_dataBuffer.LoadUsageNames) { if (usageName == s) { m_dataBuffer.ErrorInformation = "the usage name has been used."; return(false); } } // Begin to new a load combination usage try { LoadUsage loadUsage = LoadUsage.Create(m_document, usageName); if (null == loadUsage) { m_dataBuffer.ErrorInformation = "Get null reference after usage creation."; return(false); } // Store this load usage information for further use. m_dataBuffer.LoadUsageNames.Add(loadUsage.Name); m_dataBuffer.LoadUsages.Add(loadUsage); // Add the Load Usage information to UsageMap. UsageMap usageMap = new UsageMap(m_dataBuffer, loadUsage.Name); m_dataBuffer.UsageMap.Add(usageMap); } catch (Exception e) { m_dataBuffer.ErrorInformation = e.Message; return(false); } return(true); }
/// <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); }
/// <summary> /// /// </summary> /// <param name="app"></param> /// <param name="element"></param> /// <returns></returns> public static Revit.Element CloneElement(Application app, Revit.Element element) { Opening opening = element as Opening; if (opening != null) { return(CloneElement(app, opening)); } BoundaryConditions boundaryConditions = element as BoundaryConditions; if (boundaryConditions != null) { return(CloneElement(app, boundaryConditions)); } AreaLoad areaLoad = element as AreaLoad; if (areaLoad != null) { return(CloneElement(app, areaLoad)); } AreaReinforcement areaReinforcement = element as AreaReinforcement; if (areaReinforcement != null) { return(CloneElement(app, areaReinforcement)); } BeamSystem beamSystem = element as BeamSystem; if (beamSystem != null) { return(CloneElement(app, beamSystem)); } Dimension dimension = element as Dimension; if (dimension != null) { return(CloneElement(app, dimension)); } FamilyInstance familyInstance = element as FamilyInstance; if (familyInstance != null) { return(CloneElement(app, familyInstance)); } Floor floor = element as Floor; if (floor != null) { return(CloneElement(app, floor)); } Grid grid = element as Grid; if (grid != null) { return(CloneElement(app, grid)); } Group group = element as Group; if (group != null) { return(CloneElement(app, group)); } Level level = element as Level; if (floor != null) { return(CloneElement(app, floor)); } LineLoad lineLoad = element as LineLoad; if (lineLoad != null) { return(CloneElement(app, lineLoad)); } LoadCase loadCase = element as LoadCase; if (loadCase != null) { return(CloneElement(app, loadCase)); } LoadCombination loadCombination = element as LoadCombination; if (loadCombination != null) { return(CloneElement(app, loadCombination)); } LoadNature loadNature = element as LoadNature; if (loadNature != null) { return(CloneElement(app, loadNature)); } LoadUsage loadUsage = element as LoadUsage; if (loadUsage != null) { return(CloneElement(app, loadUsage)); } ModelCurve modelCurve = element as ModelCurve; if (modelCurve != null) { return(CloneElement(app, modelCurve)); } PointLoad pointLoad = element as PointLoad; if (pointLoad != null) { return(CloneElement(app, pointLoad)); } Rebar rebar = element as Rebar; if (rebar != null) { return(CloneElement(app, rebar)); } ReferencePlane referencePlane = element as ReferencePlane; if (referencePlane != null) { return(CloneElement(app, referencePlane)); } Room room = element as Room; if (room != null) { return(CloneElement(app, room)); } RoomTag roomTag = element as RoomTag; if (roomTag != null) { return(CloneElement(app, roomTag)); } SketchPlane sketchPlane = element as SketchPlane; if (sketchPlane != null) { return(CloneElement(app, sketchPlane)); } View3D view3D = element as View3D; if (view3D != null) { return(CloneElement(app, view3D)); } ViewDrafting viewDrafting = element as ViewDrafting; if (viewDrafting != null) { return(CloneElement(app, viewDrafting)); } ViewSection viewSection = element as ViewSection; if (viewSection != null) { return(CloneElement(app, viewSection)); } ViewSheet viewSheet = element as ViewSheet; if (viewSheet != null) { return(CloneElement(app, viewSheet)); } Wall wall = element as Wall; if (wall != null) { return(CloneElement(app, wall)); } // this element has not yet been exposed in the Creation Document class //Debug.Assert(false); return(null); }
private void Stream( ArrayList data, LoadUsage loadUsage ) { data.Add( new Snoop.Data.ClassSeparator( typeof( LoadUsage ) ) ); // Nothing at this level yet! }
/// <summary> /// Create new Load Combination /// </summary> /// <param name="name">The new Load Combination name</param> /// <param name="typeId">The index of new Load Combination Type</param> /// <param name="stateId">The index of new Load Combination State</param> /// <returns>true if the creation was successful; otherwise, false</returns> public Boolean NewLoadCombination(String name, int typeId, int stateId) { // Define some data for creation. LoadUsageArray usageArray = new LoadUsageArray(); LoadCaseArray caseArray = new LoadCaseArray(); LoadCombinationArray combinations = new LoadCombinationArray(); 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) { usageArray.Append(usage); } } } // 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) { caseArray.Append(loadCase); } } // Begin to new a load combination try { LoadCombination loadCombination = m_document.Create.NewLoadCombination(name, typeId, stateId, factorArray, caseArray, combinations, usageArray); if (null == loadCombination) { m_dataBuffer.ErrorInformation = "Get null reference after usage creation."; return(false); } // 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); }