/// <summary> /// create a new curtain system /// </summary> /// <param name="faceIndices"> /// the faces to be covered with new curtain system /// </param> /// <param name="byFaceArray"> /// indicates whether the curtain system will be created by face array /// </param> public void CreateCurtainSystem(List <int> faceIndices, bool byFaceArray) { // just refresh the main UI if (null == faceIndices || 0 == faceIndices.Count) { if (null != CurtainSystemChanged) { CurtainSystemChanged(); } return; } SystemInfo resultInfo = new SystemInfo(m_mydocument); resultInfo.ByFaceArray = byFaceArray; resultInfo.GridFacesIndices = faceIndices; resultInfo.Index = ++m_csIndex; // // step 1: create the curtain system // // create the curtain system by face array if (true == byFaceArray) { FaceArray faceArray = new FaceArray(); foreach (int index in faceIndices) { faceArray.Append(m_mydocument.MassFaceArray.get_Item(index)); } Autodesk.Revit.DB.CurtainSystem curtainSystem = null; Transaction t = new Transaction(m_mydocument.Document, Guid.NewGuid().GetHashCode().ToString()); t.Start(); try { curtainSystem = m_mydocument.Document.Create.NewCurtainSystem(faceArray, m_mydocument.CurtainSystemType); } catch (System.Exception) { m_mydocument.FatalErrorMsg = Properties.Resources.MSG_CreateCSFailed; t.RollBack(); return; } t.Commit(); resultInfo.CurtainForm = curtainSystem; } // create the curtain system by reference array else { ReferenceArray refArray = new ReferenceArray(); foreach (int index in faceIndices) { refArray.Append(m_mydocument.MassFaceArray.get_Item(index).Reference); } ICollection <ElementId> curtainSystems = null; Transaction t = new Transaction(m_mydocument.Document, Guid.NewGuid().GetHashCode().ToString()); t.Start(); try { curtainSystems = m_mydocument.Document.Create.NewCurtainSystem2(refArray, m_mydocument.CurtainSystemType); } catch (System.Exception) { m_mydocument.FatalErrorMsg = Properties.Resources.MSG_CreateCSFailed; t.RollBack(); return; } t.Commit(); // internal fatal error, quit the sample if (null == curtainSystems || 1 != curtainSystems.Count) { m_mydocument.FatalErrorMsg = Properties.Resources.MSG_MoreThan1CSCreated; return; } // store the curtain system foreach (ElementId cs in curtainSystems) { resultInfo.CurtainForm = m_mydocument.Document.GetElement(cs) as Autodesk.Revit.DB.CurtainSystem; break; } } // // step 2: update the curtain system list in the main UI // m_curtainSystemInfos.Add(resultInfo); if (null != CurtainSystemChanged) { CurtainSystemChanged(); } }
/// <summary> /// create a new curtain system /// </summary> /// <param name="faceIndices"> /// the faces to be covered with new curtain system /// </param> /// <param name="byFaceArray"> /// indicates whether the curtain system will be created by face array /// </param> public void CreateCurtainSystem(List<int> faceIndices, bool byFaceArray) { // just refresh the main UI if (null == faceIndices || 0 == faceIndices.Count) { if (null != CurtainSystemChanged) { CurtainSystemChanged(); } return; } SystemInfo resultInfo = new SystemInfo(m_mydocument); resultInfo.ByFaceArray = byFaceArray; resultInfo.GridFacesIndices = faceIndices; resultInfo.Index = ++m_csIndex; // // step 1: create the curtain system // // create the curtain system by face array if (true == byFaceArray) { FaceArray faceArray = new FaceArray(); foreach (int index in faceIndices) { faceArray.Append(m_mydocument.MassFaceArray.get_Item(index)); } Autodesk.Revit.DB.CurtainSystem curtainSystem = null; Transaction t = new Transaction(m_mydocument.Document, Guid.NewGuid().GetHashCode().ToString()); t.Start(); try { curtainSystem = m_mydocument.Document.Create.NewCurtainSystem(faceArray, m_mydocument.CurtainSystemType); } catch (System.Exception) { m_mydocument.FatalErrorMsg = Properties.Resources.MSG_CreateCSFailed; t.RollBack(); return; } t.Commit(); resultInfo.CurtainForm = curtainSystem; } // create the curtain system by reference array else { ReferenceArray refArray = new ReferenceArray(); foreach (int index in faceIndices) { refArray.Append(m_mydocument.MassFaceArray.get_Item(index).Reference); } ElementSet curtainSystems = null; Transaction t = new Transaction(m_mydocument.Document, Guid.NewGuid().GetHashCode().ToString()); t.Start(); try { curtainSystems = m_mydocument.Document.Create.NewCurtainSystem(refArray, m_mydocument.CurtainSystemType); } catch (System.Exception) { m_mydocument.FatalErrorMsg = Properties.Resources.MSG_CreateCSFailed; t.RollBack(); return; } t.Commit(); // internal fatal error, quit the sample if (null == curtainSystems || 1 != curtainSystems.Size) { m_mydocument.FatalErrorMsg = Properties.Resources.MSG_MoreThan1CSCreated; return; } // store the curtain system foreach (Autodesk.Revit.DB.CurtainSystem cs in curtainSystems) { resultInfo.CurtainForm = cs; break; } } // // step 2: update the curtain system list in the main UI // m_curtainSystemInfos.Add(resultInfo); if (null != CurtainSystemChanged) { CurtainSystemChanged(); } }