public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { if (!VersionLoader.LaunchDynamoCommand(8, commandData)) { return(Result.Failed); } return(Result.Succeeded); }
public Result OnStartup(UIControlledApplication application) { uiControlledApplication = application; var revitVersion = application.ControlledApplication.VersionNumber; var revitFolder = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); var debugPath = revitFolder.Parent.FullName; var dynamoProducts = FindDynamoRevitInstallations(debugPath, revitVersion); Products = new List <DynamoProduct>(); PlaylistProducts = new List <DynamoProduct>(); foreach (var p in dynamoProducts) { var path = VersionLoader.GetDynamoRevitPath(p, revitVersion); if (!File.Exists(path)) { continue; } Products.Add(p); if (p.VersionInfo.Major >= MinDynamoMajorVersionForPlaylist && p.VersionInfo.Minor >= MinDynamoMinorVersionForPlaylist) { PlaylistProducts.Add(p); } } if (Products.Count == 0) { return(Result.Failed); } Result preliminaryLoadResult = Result.Succeeded; // If there are multiple versions installed, then do the command // binding to prompt for version selector task dialog for user to // select specific Dynamo version. if (Products.Count > 1) { var dynamoCmdId = RevitCommandId.LookupCommandId("ID_VISUAL_PROGRAMMING_DYNAMO"); dynamoCommand = application.CreateAddInCommandBinding(dynamoCmdId); dynamoCommand.CanExecute += canExecute; dynamoCommand.BeforeExecuted += beforeExecuted; dynamoCommand.Executed += executed; if (PlaylistProducts.Count >= 1) { var dynamoPlayerCmdId = RevitCommandId.LookupCommandId("ID_PLAYLIST_DYNAMO"); if (dynamoPlayerCmdId != null) { dynamoPlayerCommand = application.CreateAddInCommandBinding(dynamoPlayerCmdId); dynamoPlayerCommand.CanExecute += canExecute; dynamoPlayerCommand.BeforeExecuted += beforeExecuted; dynamoPlayerCommand.Executed += executedPlaylist; } } } else //If only one product is installed load the Revit App directly { preliminaryLoadResult = loadProduct(Products.First(), revitVersion); } return(preliminaryLoadResult); }
public Result OnStartup(UIControlledApplication application) { uiApplication = application; // now we have a default path, but let's look at // the load path file to see what was last selected var cachedPath = String.Empty; var revitVersion = application.ControlledApplication.VersionNumber; var fileLoc = Utils.GetVersionSaveFileLocation(revitVersion); if (File.Exists(fileLoc)) { using (var sr = new StreamReader(fileLoc)) { cachedPath = sr.ReadToEnd().TrimEnd('\r', '\n'); } } var revitFolder = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); var debugPath = revitFolder.Parent.FullName; var dynamoProducts = FindDynamoInstallations(debugPath); Products = new List <DynamoProduct>(); int index = -1; foreach (var p in dynamoProducts) { var path = VersionLoader.GetDynamoRevitPath(p, revitVersion); if (!File.Exists(path)) { continue; } if (path.Equals(cachedPath)) { index = Products.Count; } Products.Add(p); } // If there are multiple versions installed, then create // a couple of push buttons in a panel to allow selection of a version. // If only one version is installed, no multi-selection is required. if (Products.Count > 1) { RibbonPanel ribbonPanel = application.CreateRibbonPanel(Resources.DynamoVersions); splitButton = AddSplitButtonGroup(ribbonPanel); if (index != -1) { splitButton.CurrentButton = splitButton.GetItems().ElementAt(index); } } string loadPath = GetDynamoRevitPath(Products.Last(), revitVersion); if (File.Exists(cachedPath)) { loadPath = cachedPath; } if (String.IsNullOrEmpty(loadPath)) { return(Result.Failed); } if (Products.Count == 1) //If only one product is installed load the Revit App directly { var ass = Assembly.LoadFrom(loadPath); var revitApp = ass.CreateInstance("Dynamo.Applications.DynamoRevitApp"); revitApp.GetType().GetMethod("OnStartup").Invoke(revitApp, new object[] { application }); } return(Result.Succeeded); }
public Result OnStartup(UIControlledApplication application) { uiApplication = application; var revitVersion = application.ControlledApplication.VersionNumber; //Get the default selection data var selectorData = VersionSelectorData.ReadFromRegistry(revitVersion); var revitFolder = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); var debugPath = revitFolder.Parent.FullName; var dynamoProducts = FindDynamoRevitInstallations(debugPath, revitVersion); Products = new List <DynamoProduct>(); int index = -1; var selectedVersion = selectorData.SelectedVersion.ToString(2); foreach (var p in dynamoProducts) { var path = VersionLoader.GetDynamoRevitPath(p, revitVersion); if (!File.Exists(path)) { continue; } if (p.VersionInfo.ToString(2) == selectedVersion) { index = Products.Count; } Products.Add(p); } if (index == -1) { index = Products.Count - 1; } // If there are multiple versions installed, then create // a couple of push buttons in a panel to allow selection of a version. // If only one version is installed, no multi-selection is required. if (Products.Count > 1) { ribbonPanel = application.CreateRibbonPanel(Resources.DynamoVersions); splitButton = AddSplitButtonGroup(ribbonPanel); if (index != -1) { splitButton.CurrentButton = splitButton.GetItems().ElementAt(index); } } string loadPath = GetDynamoRevitPath(Products.ElementAt(index), revitVersion); if (String.IsNullOrEmpty(loadPath)) { return(Result.Failed); } if (Products.Count == 1) //If only one product is installed load the Revit App directly { var ass = Assembly.LoadFrom(loadPath); var revitApp = ass.CreateInstance("Dynamo.Applications.DynamoRevitApp"); revitApp.GetType().GetMethod("OnStartup").Invoke(revitApp, new object[] { application }); } return(Result.Succeeded); }