
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to change the parameters of a certain selected element. However, I'm getting the following error:
"Illegal attempt to modify document. Reason: Changes are disabled for the active document!"
The strange part is that this error only occurs when the appended value is different from the original value, which makes me think that the error is caused by the setvaluestring command. I've done some googling but haven't really found a good way to solve this. In the API I read something about Revit API firewall which stated that the activedocument should be closed when trying to execute an external command. However, as I'm quite new to Revit, I have no idea where to start.
Thanks in advance!
Below is my code:
using System; using System.Reflection; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using System.Windows.Media.Imaging; using Autodesk.Revit.UI.Selection; using System.Collections.Generic; namespace Walkthrough { /// <remarks> /// This application's main class. The class must be Public. /// </remarks> public class CsAddPanel : IExternalApplication { // Both OnStartup and OnShutdown must be implemented as public method public Result OnStartup(UIControlledApplication application) { // Add a new ribbon panel RibbonPanel ribbonPanel = application.CreateRibbonPanel("Custom Functies"); // Create a push button to trigger a command add it to the ribbon panel. string thisAssemblyPath = Assembly.GetExecutingAssembly().Location; PushButtonData buttonData = new PushButtonData("cmdHelloWorld", "Hello Form", thisAssemblyPath, "Walkthrough.Document_Selection"); PushButton pushButton = ribbonPanel.AddItem(buttonData) as PushButton; // Optionally, other properties may be assigned to the button // a) tool-tip pushButton.ToolTip = "Say hello to Form."; // b) large bitmap Uri uriImage = new Uri(@"C:\Users\ramdas\Desktop\Revit Test Resources\logosmall.png"); BitmapImage largeImage = new BitmapImage(uriImage); pushButton.LargeImage = largeImage; return Result.Succeeded; } public Result OnShutdown(UIControlledApplication application) { // nothing to clean up in this simple case return Result.Succeeded; } } /// <remarks> /// The "HelloWorld" external command. The class must be Public. /// </remarks> [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] public class HelloWorld : IExternalCommand { // The main Execute method (inherited from IExternalCommand) must be public public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, ElementSet elements) { TaskDialog.Show("Revit", "Hello Form"); return Autodesk.Revit.UI.Result.Succeeded; } } [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.ReadOnly)] public class Document_Selection : IExternalCommand { public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { // Select an element in Revit before invoking this command // Get the handle of current document. UIDocument uidoc = commandData.Application.ActiveUIDocument; Selection selection = uidoc.Selection; Document doc = uidoc.Document; Reference ref1 = selection.PickObject(ObjectType.Element, "Pick element to change its property"); Element elem = doc.GetElement(ref1.ElementId); // TaskDialog.Show("Revit", ref1.ElementId.ToString()); Parameter para = elem.LookupParameter("beukbreedte"); para.SetValueString("5700"); } catch (Exception e) { message = e.Message; return Autodesk.Revit.UI.Result.Failed; } return Autodesk.Revit.UI.Result.Succeeded; } } }
Solved! Go to Solution.