Set View template to None

Set View template to None

mliuAP3CU
Participant Participant
592 Views
1 Reply
Message 1 of 2

Set View template to None

mliuAP3CU
Participant
Participant

Looking to click a button and set the view template for all views in project to none.

Button works but code to remove view templates does not.

I ran into the following problem (see screenshot). Not sure how to fix it

Any help appreciated. Thank you

 

0 Likes
Accepted solutions (1)
593 Views
1 Reply
Reply (1)
Message 2 of 2

Mohamed_Arshad
Advisor
Advisor
Accepted solution

HI @mliuAP3CU 

 

    In Revit API we have two ways to Set View Template ID.

 

///1. Using Direct Property of View
 v.ViewTemplateId = ElementId.InvalidElementId;

///2. Using its Parameter
v.get_Parameter(BuiltInParameter.VIEW_TEMPLATE).Set(ElementId.InvalidElementId);

 


Reference Code

 

            using (Transaction viewTemplate=new Transaction(doc,"Set to None"))
            {
                viewTemplate.Start();

                if (!v.IsTemplate)
                {
                    v.ViewTemplateId = ElementId.InvalidElementId;

                    ///Or you can use the below parameter
                    //v.get_Parameter(BuiltInParameter.VIEW_TEMPLATE).Set(ElementId.InvalidElementId); 
                }

                viewTemplate.Commit();
            }

 

Error Definition

    In you code you have used GetParameters Method this method will return IList<Parameter> [List of Parameters having same name]. But in our case to avoid confusion you can directly use the ViewTemplateId Property. Don't prefer Parameter.

 

 

Hope this will helps 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)