Duplicating views does not preserve ViewType

Duplicating views does not preserve ViewType

a-carpentier
Advocate Advocate
334 Views
1 Reply
Message 1 of 2

Duplicating views does not preserve ViewType

a-carpentier
Advocate
Advocate

Hi everyone,

 

I am currently working on a macro that batch duplicate views.

The macro works well except for one issue: when I use the View.Duplicate Method, the ViewType of the original view gets lost in the process (meaning, if I duplicate a structural plan, the duplicate might be a structural plan, a floor plan or even a ceiling plan).

Does anybody know how to fix that issue?

The macro seems to be working on Revit 2015, but the later versions have that issue.

 

Thanks,

Antoine

0 Likes
335 Views
1 Reply
Reply (1)
Message 2 of 2

BenoitE&A
Collaborator
Collaborator

Hey,

You are right it is fun: duplicating views looses their Type. 

Still usually I do not filter on Type but using a cast:

 

// One view which I suppose you get from a FilteredElementCollector

View myview;

ViewPlan myViewPlan = myview as ViewPlan;

if(myViewPlan == null)

{

// It means that my view was not a view Plan

// Usually when you are in a foreach loop : continue;

}

else

{

// It means that the view was a viewPlan, which I can handle

}

 

Hope this helps.

Benoit


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes