Perform command for Checked treenodes and roll back for unchecked treenodes

Perform command for Checked treenodes and roll back for unchecked treenodes

201606594
Contributor Contributor
810 Views
10 Replies
Message 1 of 11

Perform command for Checked treenodes and roll back for unchecked treenodes

201606594
Contributor
Contributor

Hi!

 

I have made a windows form featuring a treeview, that is populated with a list of walls instances in my document when opened. I would like to make a drawing of lines marking the wall instance whenever this is checked in the treeview. I have the script for the drawing however i do not know, how this is to be set up. How do I make the document aware that a treenode has been selected og deselected thus the wall is either drawn or removed in Revit, while the windows forms is open? Currently, the drawing works through a simple external command, but I want to make a connection with the tree nodes. Is this possible? Can I set up a transaction in the Forms script or do you have other suggestions? 

 

Accepted solutions (3)
811 Views
10 Replies
Replies (10)
Message 2 of 11

jeremy_tammik
Alumni
Alumni

I would suggest completely and utterly separating your user interface (the form) from your database interaction (the transaction, and the Revit API in general).

 

I would suggest implementing the form to just generate a list of element ids or some other data. Once the form has been closed, communicate this UI result to the completely separate subsequent database processing step.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 11

smarente1
Enthusiast
Enthusiast
Accepted solution

Sounds like you need a modeless form. There are a handful of examples online. 

 

Here is one that helped me:

 

https://forums.autodesk.com/t5/revit-api-forum/modeless-form-example/td-p/5800785

 

 

Message 4 of 11

201606594
Contributor
Contributor

Hi guys!

Thank you both for the answers! I have managed to get my externaleventhandler running and make changes in the model through a transaction from my forms window. However, I would like to have the option to rollback this transaction when pressing the button again. Do you have any suggestions how to do this?Screenshot_6.jpg

^This is what I've got so far. If necessary I can upload some of the code.

0 Likes
Message 5 of 11

jeremy_tammik
Alumni
Alumni

Nice. I like your screen snapshot.

  

Tricky. Your external command handler terminated and committed its transaction. That is just as if Revit had completed a built-in command. The only way to undo it is to use the Undo command:

 

https://thebuildingcoder.typepad.com/blog/2015/09/family-category-element-ids-transaction-undo-and-u...

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 6 of 11

201606594
Contributor
Contributor

Hi Jeremy,

Thanks for the reply! I have considered the undo-options, however if eg. the visual style is changed before applying the undo command, this will be reverted instead. Is there a way to choose which transaction to undo?

Another option I've considered is simply selecting all model lines and deleting them though I don't know what effect it will have on the rest of the model.

A third option could be drawing all model lines beforehand and then turning them visible and invisble.

 

Do you have any suggestions regarding these options?

0 Likes
Message 7 of 11

jeremy_tammik
Alumni
Alumni
Accepted solution

Is there a way to choose which transaction to undo?

 

No. Not afaik.

 

> selecting all model lines and deleting them

 

might make some users very unhappy not to say furious.

 

> third option could be drawing all model lines beforehand and then turning them visible and invisible.

 

Fourth option: mark your model lines somehow, e.g., with a special line style or by adding an extensible storage data marker. Then you can delete them at will without destroying other user's work.

  

There are only about 42 million other possible approaches that we have also not considered yet.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 8 of 11

201606594
Contributor
Contributor

Great, I'll go for the fourth option then. Ive tried to look at the ElementParameterFilter and the example. However, the parametervalue i will be filtering for is LINE_PEN, which i do not know which filterrule to apply to it. 

public class MyElementParameterFilter : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document doc = commandData.Application.ActiveUIDocument.Document;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;

            // Creates an ElementParameter filter
            // Create filter by provider and evaluator 
            // provider
            ParameterValueProvider pvp = new ParameterValueProvider(new ElementId(BuiltInParameter.LINE_PEN));
            // evaluator
            FilterNumericRuleEvaluator fnrv = new FilterNumericEquals();
            // rule value    
            double ruleValue = 100.0; // filter Model Lines equal to
                                      // rule
            FilterRule fRule = new FilterDoubleRule(pvp, fnrv, ruleValue, 1E-6);

            // Create an ElementParameter filter
            ElementParameterFilter filter = new ElementParameterFilter(fRule);

            // Apply the filter to the elements in the active document
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            IList<Element> rooms = collector.WherePasses(filter).ToElements();


            ElementParameterFilter EqualFilter = new ElementParameterFilter(fRule, true);
            collector = new FilteredElementCollector(doc);
            IList<Element> EqualFounds = collector.WherePasses(EqualFilter).ToElements();

            return Result.Succeeded;
        }

 Do you have any suggestions?

0 Likes
Message 9 of 11

jeremy_tammik
Alumni
Alumni

Nope. I do not understand your question or how you intend to use the LINE_PEN parameter value.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 10 of 11

201606594
Contributor
Contributor

I tried to use a unique line weight (so far) as parametervalue and identify it via the builtinparameter(LINE_PATTERN, LINE_COLOR, LINE_PEN) but this might not be the right approach to this?

How would one assign this and identify it?

0 Likes
Message 11 of 11

201606594
Contributor
Contributor
Accepted solution

I decided on storing the model lines in list upon creating them which I then emptied and deleted its contents when starting a new transaction. This seems to solve the problem.

0 Likes