Section View Creation

I mentioned some basics of

elevation and section view creation

a long time ago, but omitted to publicise the results of the ensuing discussion

with


Konstanty

and similar ones

with

Jenney

and

Bhavana
.
The issue came up in some ADN cases as well, so it really is time to get a bit more information on this out there to you.

Question: I see that the CreateViewSection SDK creates a detail view of a wall seen from one side.
How can I create similar top and front views of it?

Answer: First of all, as always, of course, take a look at the developer guide, e.g. section 18.1.4 Creating and Deleting Views.
It explains the different view types and how they are defined and created programmatically.

The main aspect in defining the section view direction is setting up the BoundingBoxXYZ appropriately.
As you say, this is demonstrated by the CreateViewSection SDK sample.
It sets up the bounding box used in the call to the NewViewSection method in a helper method GenerateBoundingBoxXYZ.
The latter creates a new BoundingBoxXYZ and sets its Min and Max properties.
The most important thing is its Transform property, which defines the origin and directions (RightDirection, UpDirection and ViewDirection) of the created view.
That is defined by the GenerateTransform helper method, which branches off into different flavours depending on the selected element type, wall, beam or floor.
In the case of a wall, it uses the wall location line to determine its midpoint and direction.

Here is some simpler code that does the same thing without branching out into any helper functions, uses the element bounding box to determine the view origin, and a hard-wired view direction to set up a front view:


  Dim uiapp As UIApplication = commandData.Application
  Dim uidoc As UIDocument = uiapp.ActiveUIDocument
  Dim app As Application = uiapp.Application
  Dim doc As Document = uidoc.Document
 
  Dim sel As Selection = uidoc.Selection
 
  Dim e As Element = sel.Elements(0)
 
  ' get the element bounding box;
  ' 'nothing' means model geometry:
 
  Dim ebbox As BoundingBoxXYZ =
    e.BoundingBox(Nothing)
 
  ' determine size of box
 
  Dim w As Double = (ebbox.Max.X - ebbox.Min.X)
  Dim d As Double = (ebbox.Max.Y - ebbox.Min.Y)
  Dim h As Double = (ebbox.Max.Z - ebbox.Min.Z)
 
  ' make it easier to see, e.g., not too narrow
 
  If w < 10.0 Then
    w = 10.0
  End If
  If d < 10.0 Then
    d = 10.0
  End If
 
  ' from front 
 
  Dim maxPt As XYZ = New XYZ(w, h, 0.0)
  Dim minPt As XYZ = New XYZ(-w, -h, -d)
 
  Dim bbox As BoundingBoxXYZ = New BoundingBoxXYZ()
 
  bbox.Enabled = True
  bbox.Max = maxPt
  bbox.Min = minPt
 
  ' set the transform
 
  Dim trans As Transform = Transform.Identity
 
  ' find the mid point of the element
 
  Dim midPt As XYZ = 0.5 * (ebbox.Max + ebbox.Min)
 
  ' set it as origin 
 
  trans.Origin = midPt
 
  ' determine view direction 
 
  trans.BasisX = XYZ.BasisX
  trans.BasisY = XYZ.BasisZ
  trans.BasisZ = -XYZ.BasisY
 
  bbox.Transform = trans
 
  ' create the section view
 
  Dim viewSection As ViewSection =
    doc.Create.NewViewSection(bbox)

To set up a different view, e.g. the right-hand side, you just modify the following lines:


  ' . . .
  ' from right 
  Dim maxPt As XYZ = New XYZ(d, h, 0.0)
  Dim minPt As XYZ = New XYZ(-d, -h, -w)
  ' . . .
  ' determine view direction 
  trans.BasisX = XYZ.BasisY
  trans.BasisY = XYZ.BasisZ
  trans.BasisZ = XYZ.BasisX

For the sake of completeness and your comfort, here is
BackSectionView.zip containing
the rough draft of two entire little VB and C# sample projects.
The C# version implements three methods GetFrontView, GetBackView and GetTopView, which may or may not fulfil the promise of their names, but at least they will give you a starting point.

Detail View, Not Section View

When using the NewViewSection method, you should be aware of the note at the end of the developer guide section 18.5 ViewSection, which points out that these views will appear as details views in the project browser, unlike section views created manually using section using the command View > New > Section, which show up under the Sections (Building Section) node in the Project Browser.


Comments

31 responses to “Section View Creation”

  1. Rudolf Honke Avatar
    Rudolf Honke

    Hi Jeremy,
    after the SectionView has been created, you can alter its ElementType.
    In your project file, you may find several different ElementTypes for Sections, depending on the RTE you used.
    Doing so, the new ViewSection will change from Detail View to Section View.

  2. Dear Rudolf,
    Wow, do you mean to say that the note in the developer guide does not actually hold, in that the easy modification of the element type suggested by you changes the situation?
    That you can thus create a section view and then set up its type so that it really appears as a section view in the project browser?
    If so, we should update the developer guide to say so.
    Thank you very much for pointing this out!
    Cheers, Jeremy.

  3. Rudolf Honke Avatar
    Rudolf Honke

    Hi Jeremy,
    yes, I used that in several situations.
    The point is to find a proper ElementType that can be assigned.
    If you browse the database, you will find out that
    the ElementType for any existing Section has a “null” category, so it is only possible to get a valid ElementType by searching it by name, e.g. “Section” or (like in my German files) “Schnitt”, ID 828.
    Since element names are not unique, this may fail if there are other ElementTypes of category “null” named this way.
    But most elementTypes have a valid category, so this is only a little risk.

  4. Dear Rudolf,
    Yes, that makes sense. If you want to make really sure, you can probably determine some specific parameter values that only the desired section view element type has to further ensure uniqueness.
    Cheers, Jeremy.

  5. Rudolf Honke Avatar
    Rudolf Honke

    Hi Jeremy,
    If we use ourViewSection.GetVaildTypes(), we just need to search our section ElementType in this little list. So the amount of possible errors will be reduced to a minimum.
    Bye,
    Rudolf

  6. Dear Rudolf,
    Thank you once again. Of course, that really limits it to a very few candidates!
    These really are very powerful and useful tips you are providing!
    Cheers, Jeremy.

  7. Nick Kovach Avatar
    Nick Kovach

    Jeremy,
    Potential rookie question about creating a new view section. Is it possible to assign a referencing view to the section? In other words, instead of creating a new section view it would actually create a section tag referencing an existing view.
    Any help would be appreciated. I am still a novice at this but I am learning as quickly as possible.

  8. Dear Nick,
    That does not sound rookie to me at all. I have no idea. Have you tried using the Document.NewTag method? Or does that not fit at all?
    Cheers, Jeremy.

  9. Revit Apprentice Avatar
    Revit Apprentice

    Hello Jeremy,
    great blog you have here. I was wondering could you help me with problem that I am having.
    I am creating section view for each wall in a room using room boundary (viewer direction is perpendicular to room boundary segment). I was using BackSectionView (Revit 2011 SDK sample) as reference. Everything works fine, but problem is if in a model exists some additional Revit linked file. Then when I create section view, Outline property of created section view has this value
    sectionView.Outline = ‘((Autodesk.Revit.DB.View)(view)).Outline’ threw an exception of type ‘System.AccessViolationException’ Autodesk.Revit.DB.BoundingBoxUV {System.AccessViolationException}.
    When I try to add this section view to some view sheet I get the exception: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    Can you give me some advice, what is causing this?

  10. Dear Revit Apprentice,
    Thank you for your appreciation.
    Nope, sorry, no idea. Please let us know how you resolve this. Thank you!
    Cheers, Jeremy.

  11. Revit Apprentice Avatar
    Revit Apprentice

    Hello, Jeremy!
    I managed to solve my problem by regenerating document after creation of all section views. After that I can place them on view sheets without any exception.
    I still don’t know what is the reason behind that sectionView.Outline exception.
    Best regards!

  12. Dear Revit Apprentice,
    Congratulations on solving it, very well done, and thank you for letting us know!
    Cheers, Jeremy.

  13. Hi Jeremy,
    How get LeftView or rightView?

  14. Dear Leo,
    You are in the right place. Look at the sample code provided above.
    Cheers, Jeremy.

  15. How to judge toward of door?

  16. More difficult to abtain the correct facede because each door have different toward in the view.

  17. Get to the door on the side wall, and the shows the door front.

  18. Dear Leo,
    To reach full illumination, we must realise the unity of all things and let go of all judgement.
    Cheers, Jeremy.

  19. Dear Leo,
    Here are some family instance properties that you might want to take a look at:
    – CanFlipFacing
    – CanFlipHand
    – HandFlipped
    – HandOrientation
    – FacingFlipped
    – FacingOrientation
    – Mirrored
    I suggest searching for the use of these in the developer guide and the SDK samples.
    Here are some posts that may be of interest as well:
    http://thebuildingcoder.typepad.com/blog/2010/01/transformations.html
    http://thebuildingcoder.typepad.com/blog/2010/01/south-facing-walls.html
    Cheers, Jeremy.

  20. How to hide the view of the profile and the reference plane?

  21. Hi Jeremy,
    1.How to hide the view of the section and the reference plane?
    2.How to rename the type of detail view?

  22. Dear Leo,
    Rudolf Honke very kindly answered your questions here:
    http://thebuildingcoder.typepad.com/blog/2012/05/change-section-view-type-and-hide-cut-line.html
    Cheers, Jeremy.

  23. In the generated detail, I just want to show the door, so I made ​​the followingoperations:
    private void setVisableDoors(ViewSection view)
    {
    ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Doors);
    FilteredElementCollector collector = new FilteredElementCollector(view.Document);
    IList doors = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements();
    ElementSet esdoors = new ElementSet();
    foreach (Element elem in doors)
    {
    esdoors.Insert(elem);
    }
    view.Unhide(esdoors);
    return;
    }
    But view shows, the effect has still retained some elements, such as:walls, beams, structural columns, they are not hidden, why?

  24. How to hide viewsection C, it blocked the view of the door?
    As shown below :
    How up upload pictures?

  25. Dear Leo,
    I see you call Unhide for the doors, but I see no call asking the other elements to be hidden.
    Cheers, Jeremy.

  26. Dear Leo,
    1. No idea.
    2. Look at other people’s comments … some people have uploaded images to other servers and then included the URL.
    Cheers, Jeremy.

  27. Oh,I understand, display, and hidden functions needs to be done?

  28. Like this, it will result in some element does not have to be hidden in the program, and so on to detail the effect of causing an error, such as: I only need to show the door, the results of other elements.

  29. Family facade, why some facade incomplete?

Leave a Reply