/// <summary> /// Creates a new activity /// </summary> /// <param name="activityId">Unique name identifying the activity</param> /// <param name="script">AutoCAD Script that is associated with the activity</param> /// <param name="linkedPackages">Package Ids to link with the new activity being created</param> /// <returns>true if activity was created, false otherwise</returns> public static bool CreateActivity(String activityId, String script, ObservableCollection<String> linkedPackages) { if (String.IsNullOrEmpty(activityId) || String.IsNullOrEmpty(script)) return false; bool created = false; try { foreach (AIO.ACES.Models.Activity act1 in container.Activities) { if (activityId.Equals(act1.Id)) { // Activity already exists ! Console.WriteLine(String.Format("Activity with name {0} already exists !", act1.Id)); return false; } } // Identify the result file in the script. // The result file name can be any name of your choice, AutoCADIO does not have a restriction on that. // But just to make the code generic and to have it identify the result file automatically from the script, // we look for anything that sounds like result.pdf, Result.dwf, RESULT.DWG etc. String resultLocalFileName = String.Empty; foreach (Match m in Regex.Matches(script, "(?i)result.[a-z][a-z][a-z]")) { resultLocalFileName = m.Value; } if (String.IsNullOrEmpty(resultLocalFileName)) {// Script did not have file name like Result.pdf, Result.dwg .... Console.WriteLine(String.Format("Could not identify the result output file in the provided script ! Please use result.* as the output of the script.")); return false; } // Create a new activity AIO.ACES.Models.Activity act = new AIO.ACES.Models.Activity() { Id = activityId, Version = 1, Instruction = new AIO.ACES.Models.Instruction() { Script = script }, Parameters = new AIO.ACES.Models.Parameters() { InputParameters = { new AIO.ACES.Models.Parameter() { Name = "HostDwg", LocalFileName = "$(HostDwg)" } }, OutputParameters = { new AIO.ACES.Models.Parameter() { Name = "Result", LocalFileName = resultLocalFileName } } }, RequiredEngineVersion = "20.0", AppPackages = linkedPackages }; container.AddToActivities(act); container.SaveChanges(); created = true; } catch (System.Exception ex) { Console.WriteLine(ex.Message); } return created; }
/// <summary> /// Creates a new activity /// </summary> /// <param name="activityId">Unique name identifying the activity</param> /// <param name="script">AutoCAD Script that is associated with the activity</param> /// <param name="linkedPackages">Package Ids to link with the new activity being created</param> /// <returns>true if activity was created, false otherwise</returns> public static bool CreateActivity(String activityId, String script, ObservableCollection <String> linkedPackages) { if (String.IsNullOrEmpty(activityId) || String.IsNullOrEmpty(script)) { return(false); } bool created = false; try { foreach (AIO.ACES.Models.Activity act1 in container.Activities) { if (activityId.Equals(act1.Id)) { // Activity already exists ! Console.WriteLine(String.Format("Activity with name {0} already exists !", act1.Id)); return(false); } } // Identify the result file in the script. // The result file name can be any name of your choice, AutoCADIO does not have a restriction on that. // But just to make the code generic and to have it identify the result file automatically from the script, // we look for anything that sounds like result.pdf, Result.dwf, RESULT.DWG etc. String resultLocalFileName = String.Empty; foreach (Match m in Regex.Matches(script, "(?i)result.[a-z][a-z][a-z]")) { resultLocalFileName = m.Value; } if (String.IsNullOrEmpty(resultLocalFileName)) {// Script did not have file name like Result.pdf, Result.dwg .... Console.WriteLine(String.Format("Could not identify the result output file in the provided script ! Please use result.* as the output of the script.")); return(false); } // Create a new activity AIO.ACES.Models.Activity act = new AIO.ACES.Models.Activity() { Id = activityId, Version = 1, Instruction = new AIO.ACES.Models.Instruction() { Script = script }, Parameters = new AIO.ACES.Models.Parameters() { InputParameters = { new AIO.ACES.Models.Parameter() { Name = "HostDwg", LocalFileName = "$(HostDwg)" } }, OutputParameters = { new AIO.ACES.Models.Parameter() { Name = "Result", LocalFileName = resultLocalFileName } } }, RequiredEngineVersion = "20.0", AppPackages = linkedPackages }; container.AddToActivities(act); container.SaveChanges(); created = true; } catch (System.Exception ex) { Console.WriteLine(ex.Message); } return(created); }