SetViewRange always fails with CeilingPlan

SetViewRange always fails with CeilingPlan

Anonymous
Not applicable
929 Views
5 Replies
Message 1 of 6

SetViewRange always fails with CeilingPlan

Anonymous
Not applicable

Why this code always fails when the ViewPlan is a CeilingPlan?

 

                foreach (var view in document.CollectElements<View>())
                {
                    if ((view.ViewType == ViewType.FloorPlan) || (view.ViewType == ViewType.CeilingPlan))
                    {
                        if (view.ViewType == ViewType.CeilingPlan) { planCut = offset - 110; }
                        planCut = UnitConversion.Convert(LengthUnits.Millimeter, LengthUnits.Feet, planCut);
                        ViewPlan viewPlan = view as ViewPlan;
                        PlanViewRange viewRange = viewPlan.GetViewRange();
                            using (var t = TransactionFactory.CreateOpenTransaction(document, "Set view range"))
                            {
                                viewRange.SetOffset(PlanViewPlane.TopClipPlane, planCut);
                                viewRange.SetOffset(PlanViewPlane.CutPlane, planCut);
                                viewPlan.SetViewRange(viewRange);
                                t.Commit();
                            }
                    }
                }

When the ViewPlan is FoorPlan is 100% OK.
0 Likes
Accepted solutions (1)
930 Views
5 Replies
Replies (5)
Message 2 of 6

jeremytammik
Autodesk
Autodesk

What is a 'FoorPlan'?

 

🙂

 

Seriously, have you tried to set the value manually in the user interface? Does that work as expected? If not, the PI can probably not do it either. If yes, then please examine the detailed properties of the view before and after the modification, take a not of all the changes, and that will help you see how to achieve the same programmatically:

 

https://thebuildingcoder.typepad.com/blog/2017/01/virtues-of-reproduction-research-mep-settings-onto...

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 6

Anonymous
Not applicable

Seriously, was a typo...: FloorPlan.

 

By hand is OK with the UI, the offset value is set.

the line code not working when the view is a CeilingPlan is:

viewPlan.SetViewRange(viewRange);

The error is: "the planViewRange is not valid" but, I check the viewPlan.CheckPlanViewRangeValidity and is OK

 

I don't understand the "detailed properties", nothing is hide, is a normal view!

 

The Family is created, by code, using a generic template and I use the symbol height for offset calculation.

 

Maybe the plan is not ready a that moment of the generation of the family?

 

No idea!!!

0 Likes
Message 4 of 6

jeremytammik
Autodesk
Autodesk

Maybe the plan is not ready a that moment of the generation of the family?

 

That is a brilliant thought!

 

Yes, quite often, one setting in Revit will affect another. In that case, you need to regenerate the model between setting the two:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.33

 

Please try out calling doc.Regenerate between the settings and let us know how it goes.

  

Thank you!

 

Oh, no, on second thoughts, you are just making one single call to set one single property, so that cannot be the reason. Sorry, no idea.

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 6

Anonymous
Not applicable

No changes using doc.Regenerate.

I can get the offset, exam:

Top = 0

Cut = 7.5

Try to set

Top = 0

Cut = 3.5

and fails...

0 Likes
Message 6 of 6

FAIR59
Advisor
Advisor
Accepted solution

In the UI the BottomClipPlane automaticly gets the same value as the CutPlane. Apparently using the API, you have to set both values yourself.

 viewRange.SetOffset(PlanViewPlane.TopClipPlane, planCut);
 viewRange.SetOffset(PlanViewPlane.CutPlane, planCut);
 viewRange.SetOffset(PlanViewPlane.BottomClipPlane, planCut);
 viewPlan.SetViewRange(viewRange);
 t.Commit();