Beispiel #1
0
 /// <summary>
 /// Dump the selected event list to commandData.Data.
 /// This method is used in ExternalCommand.
 /// </summary>
 /// <param name="eventList"></param>
 /// <param name="data"></param>
 public void DumpEventListToJournalData(List <String> eventList, ref StringStringMap data)
 {
     foreach (String eventname in eventList)
     {
         data.Insert(eventname, "1");
     }
 }
Beispiel #2
0
        /// <summary>
        /// Get the data which is related to a special key in journal
        /// </summary>
        /// <param name="dataMap">the map which store the journal data</param>
        /// <param name="key">a key which indicate which data to get</param>
        /// <returns>The gotten data in string format</returns>
        private static String GetSpecialData(StringStringMap dataMap, String key)
        {
            String dataValue = dataMap.get_Item(key);

            if (String.IsNullOrEmpty(dataValue))
            {
                throw new Exception(key + "information is not exist in journal.");
            }
            return(dataValue);
        }
Beispiel #3
0
        /// <summary>
        /// Get event list from commandData.Data.
        /// This method is used in ExternalCommmand.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public List <String> GetEventsListFromJournalData(StringStringMap data)
        {
            List <String>           eventList = new List <string>();
            StringStringMapIterator iter      = data.GetEnumerator() as StringStringMapIterator;

            while (iter.MoveNext())
            {
                eventList.Add(iter.Key);
            }
            return(eventList);
        }
Beispiel #4
0
        /// <summary>
        /// Write the support data into the journal
        /// </summary>
        private void WriteJournalData()
        {
            // Get the StringStringMap class which can write support into.
            StringStringMap dataMap = m_commandData.Data as StringStringMap;

            dataMap.Clear();

            // Begin to add the support data
            dataMap.Insert("Wall Type Name", m_createType.Name);                  // add wall type name
            dataMap.Insert("Level Id", m_createlevel.Id.IntegerValue.ToString()); // add level id
            dataMap.Insert("Start Point", XYZToString(m_startPoint));             // add start point
            dataMap.Insert("End Point", XYZToString(m_endPoint));                 // add end point
        }
Beispiel #5
0
        /// <summary>
        /// Read the journal data from the journal.
        /// All journal data store in commandData.Data,
        /// and journal data can be gotten when the sample is in the CrsTest environment
        /// </summary>
        private void ReadJournalData()
        {
            // Get the journal data map from API
            Document        doc     = m_commandData.Application.ActiveUIDocument.Document;
            StringStringMap dataMap = m_commandData.Data as StringStringMap;

            String dataValue = null;    // store the journal data value temporarily

            // Get the wall type from the journal
            dataValue = GetSpecialData(dataMap, "Wall Type Name"); // get wall type name
            foreach (WallType type in m_wallTypeList)              // get the wall type by the name
            {
                if (dataValue == type.Name)
                {
                    m_createType = type;
                    break;
                }
            }
            if (null == m_createType)   // assert the wall type is exist
            {
                throw new InvalidDataException("Can't find the wall type from the journal.");
            }

            // Get the level information from the journal
            dataValue = GetSpecialData(dataMap, "Level Id");                                              // get the level id
            Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(Convert.ToInt32(dataValue)); // get the level by its id

            m_createlevel = doc.get_Element(id) as Level;
            if (null == m_createlevel)  // assert the level is exist
            {
                throw new InvalidDataException("Can't find the level from the journal.");
            }

            // Get the start point information from the journal
            dataValue    = GetSpecialData(dataMap, "Start Point");
            m_startPoint = StirngToXYZ(dataValue);

            // Get the end point information from the journal
            dataValue  = GetSpecialData(dataMap, "End Point");
            m_endPoint = StirngToXYZ(dataValue);

            // Create wall don't allow the start point equals end point
            if (m_startPoint.Equals(m_endPoint))
            {
                throw new InvalidDataException("Start point is equal to end point.");
            }
        }
Beispiel #6
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
                                                ref string message,
                                                ElementSet elements)
        {
            StringStringMap data = commandData.Data as StringStringMap;

            // These #if directives within file are used to compile project in different purpose:
            // . Build project with Release mode for regression test,
            // . Build project with Debug mode for manual run
#if !(Debug || DEBUG)
            // playing journal.
            if (ExternalApplication.JnlProcessor.IsReplay)
            {
                ExternalApplication.ApplicationEvents = ExternalApplication.JnlProcessor.GetEventsListFromJournalData(data);
            }

            // running the sample form UI.
            else
            {
#endif

            ExternalApplication.SettingDialog.ShowDialog();
            if (DialogResult.OK == ExternalApplication.SettingDialog.DialogResult)
            {
                // get what user select.
                ExternalApplication.ApplicationEvents = ExternalApplication.SettingDialog.AppSelectionList;

#if !(Debug || DEBUG)
                // dump what user select to a file in order to autotesting.
                ExternalApplication.JnlProcessor.DumpEventListToJournalData(ExternalApplication.ApplicationEvents, ref data);
                    #endif
            }
#if !(Debug || DEBUG)
        }
#endif
            // update the events according to the selection.
            ExternalApplication.AppEventMgr.Update(ExternalApplication.ApplicationEvents);

            // track the selected events by showing the information in the information windows.
            ExternalApplication.InfoWindows.Show();


            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Beispiel #7
0
 /// <summary>
 /// Get event list from commandData.Data.
 /// This method is used in ExternalCommmand.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public List<String> GetEventsListFromJournalData(StringStringMap data)
 {
     List<String> eventList = new List<string>();
     StringStringMapIterator iter = data.GetEnumerator() as StringStringMapIterator;
     while (iter.MoveNext())
     {
         eventList.Add(iter.Key);
     }
     return eventList;
 }
Beispiel #8
0
 /// <summary>
 /// Dump the selected event list to commandData.Data.
 /// This method is used in ExternalCommand.
 /// </summary>
 /// <param name="eventList"></param>
 /// <param name="data"></param>
 public void DumpEventListToJournalData(List<String> eventList, ref StringStringMap data)
 {
     foreach (String eventname in eventList)
     {
         data.Insert(eventname, "1");
     }
 }