Duplicating views with Revit API

Duplicating views with Revit API

jjesusdelpino
Advocate Advocate
3,789 Views
2 Replies
Message 1 of 3

Duplicating views with Revit API

jjesusdelpino
Advocate
Advocate

Hi there! Im trying to build some Macros for duplicating views and I have got an issue I havent found an anwser to. Its pretty simple, this code is only working when I choose "AsDependent" as ViewDuplicateOption. As long as I choose "WithDetailing" or "Duplicate" it raise an error that says "View cannot be duplicated". I know I can check if a view is available to duplicate it with CanBeDuplicated method. But what I want to know is why I cant duplicate the active view if I can do it normally in Revit.

Testing with FloorPlan. Level 1.

The code:

 

 

        public void DuplicarVista()
        {
            UIDocument uidoc = this.ActiveUIDocument;
            Document doc = uidoc.Document;
        
            View ActiveView = null;
            
            ActiveView= uidoc.ActiveView;
            
            int nduplicates = 4;
                    
            using (Transaction t = new Transaction(doc,"Duplicate Views"))
            {
                    t.Start();
                       
                    for (int i = 1; i < nduplicates; i++) 
                    {
                         Element CreatedView = doc.GetElement(ActiveView.Duplicate(ViewDuplicateOption.Duplicate));                
                    }
                    t.Commit();
            }
        }

Accepted solutions (1)
3,790 Views
2 Replies
Replies (2)
Message 2 of 3

jjesusdelpino
Advocate
Advocate
Accepted solution

I have restarted Revit, tried again and now it works fine. Dont know what was going on but its working so... I mark this as a solution in case someone need code to duplicate Views. Thanks.

0 Likes
Message 3 of 3

lariasGHNFM
Contributor
Contributor

Hi, I am new to Revit Api. My question is what is the purpose of the for loop here?