Create 3Dview with sectionsbox

Create 3Dview with sectionsbox

Anonymous
Not applicable
1,033 Views
5 Replies
Message 1 of 6

Create 3Dview with sectionsbox

Anonymous
Not applicable

Hi

I have a few hundred planviews evry month and I want to make a 3D view with a sectionsbox with the same min and max as the crop in the plan view

I have got the level from the planview XYZ base as the Zmin in the Sectionbox, and then adding 9' to the max.

The creation of the perspectiv 3Dview and the sectionsbox XY min/max works OK, but the Z value isn't right

 

I am also trying to set the eye and target elevation, using the XYZ eye and XYZ up, but it I got the wrong values in the model

placed in the middle of the sectionbox.

 

But I get the wrong values, what do I do vrong ??

My code look like this

 

 

if (  . . . . . .  .)

{
View_Code = ViewCODE.AsString();
BoundingBoxXYZ View_BB = viewElements.get_BoundingBox(viewElements);
XYZ BBMin = View_BB.Min;
XYZ BBMax = View_BB.Max;

XYZ Base = new XYZ(viewElements.Origin.X,viewElements.Origin.Y,viewElements.Origin.Z);
XYZ SecBMin = new XYZ(BBMin.X, BBMin.Y, Base.Z);
XYZ SecBMax = new XYZ(BBMax.X, BBMax.Y, Base.Z + 9.055);

ViewFamilyType viewFamilyType = (from v in new FilteredElementCollector(mainDocument).
OfClass(typeof(ViewFamilyType)).
Cast<ViewFamilyType>()
where v.ViewFamily == ViewFamily.ThreeDimensional
select v).First();


using (Transaction t = new Transaction(mainDocument, "Create view"))
{
t.Start();
View3D view = View3D.CreatePerspective(mainDocument, viewFamilyType.Id);
view.Name = viewElements.Name;

ViewCODE = view.get_Parameter("Drawing type");
ViewCODE.Set("Housing No");

BoundingBoxXYZ newSectionBox = new BoundingBoxXYZ();

newSectionBox.Min = SecBMin;
newSectionBox.Max = SecBMax;

view.SetSectionBox(newSectionBox);

XYZ eye = new XYZ((SecBMin.X + SecBMax.X) / 2, (SecBMin.Y + SecBMax.Y) / 2, 80);
XYZ up = new XYZ((SecBMin.X + SecBMax.X) / 2, (SecBMin.Y + SecBMax.Y) / 2, 0);
XYZ forward = new XYZ(0, 0, -1);

view.SetOrientation(new ViewOrientation3D(eye, up, forward));
view.get_Parameter(BuiltInParameter.MODEL_GRAPHICS_STYLE).Set(4);
view.ViewTemplateId = viewTemp.Id;

t.Commit();
}

 

Regards Anders

0 Likes
Accepted solutions (1)
1,034 Views
5 Replies
Replies (5)
Message 2 of 6

Aaron.Lu
Autodesk
Autodesk
Dear,
is viewElements a plan view? if yes, I suspect get_BoundingBox(xx) should return null, should it?

However, would you try to hard code the section box and set it using SetSectionBox to see if the problem still exist?
like this:

var sectionBox = perspectiveView.GetSectionBox();
WriteLog(sectionBox.Max);
WriteLog(sectionBox.Min);
var newSectionBox = new BoundingBoxXYZ();
newSectionBox.Max = sectionBox.Max + new XYZ(10, 10, 10);
newSectionBox.Min = sectionBox.Min - new XYZ(10, 10, 10);
using (Transaction transaction = new Transaction(RevitDoc))
{
transaction.Start("Set Section Box");
perspectiveView.SetSectionBox(newSectionBox);
sectionBox = perspectiveView.GetSectionBox();
WriteLog(sectionBox.Max);
WriteLog(sectionBox.Min);
transaction.Commit();
}


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 3 of 6

Anonymous
Not applicable

Hi

You are right I get er wrong Z value in the boundingbox from the planview

 

I tried to get the associated level from the planview but failed

Can you help me to get the levelId from the associated Level, from there I can get the elevation whitch I can use as the min Z value at my sectionbox in the 3D view ?

 

 

Regards

Anders

0 Likes
Message 4 of 6

Aaron.Lu
Autodesk
Autodesk
View has a property GenLevel, you can have a try


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 5 of 6

Anonymous
Not applicable

Hi

 

That worked to find the assosiated level of the planview

but I can't find the elevation of the level it should be simple, but I can't use Level.elevation or level.projectelevation"

My code lkke like this:

 

FilteredElementCollector Levelcollector = new FilteredElementCollector(mainDocument); 
ICollection<Element> collection = Levelcollector.OfClass(typeof(Level)).ToElements();

 

   foreach (Element ALevel in Levelcollector)
       {
        TaskDialog.Show("Level", ALevel.Name.ToString() + "\n" + ALevel ???
       }

 

0 Likes
Message 6 of 6

Aaron.Lu
Autodesk
Autodesk
Accepted solution
Please cast the Element to Level, e.g.
Level theLevel = ALevel as Level;
var ele = theLevel.Elevation;


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes