Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Duplicating views with Revit API

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
jjesusdelpino
3165 Views, 2 Replies

Duplicating views with Revit API

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();
            }
        }

Tags (2)
2 REPLIES 2
Message 2 of 3

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.

Message 3 of 3
lariasGHNFM
in reply to: jjesusdelpino

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report