How to create spot elevation with Revit API

How to create spot elevation with Revit API

AndrewButenko
Advocate Advocate
3,038 Views
5 Replies
Message 1 of 6

How to create spot elevation with Revit API

AndrewButenko
Advocate
Advocate

Anybody have vb.net code?

3,039 Views
5 Replies
Replies (5)
Message 2 of 6

jeremytammik
Autodesk
Autodesk
0 Likes
Message 3 of 6

AndrewButenko
Advocate
Advocate

Dear Jeremy!

 

Your code don't work. 

Error message translated to english is mean :

"One or more point coordinates are not correct. The coordinates of a point as a whole can refer only to those occurrences that have the correct coordinates on the view."

 

This is screenshot 

 http://piccy.info/view3/11527140/6a4eca43a95eb71c731f7d81c940da0f/orig/

 

 

0 Likes
Message 4 of 6

AndrewButenko
Advocate
Advocate

I want create spot elevation in the intersection point wall and toposurface. What i do wrong?

 

 

 Private Function CalculateLineAboveFloor(doc As Document, wWall As Wall) As Line
      

        ' Find a 3D view to use for the ReferenceIntersector constructor
        Dim collector As New FilteredElementCollector(doc)
        Dim isNotTemplate As Func(Of View3D, Boolean) = Function(v3) Not (v3.IsTemplate)
        Dim view3D As View3D = collector.OfClass(GetType(View3D)).Cast(Of View3D)().First(isNotTemplate)

        ' Use the center of the skylight bounding box as the start point.
        Dim box As BoundingBoxXYZ = wWall.BoundingBox(view3D)
        Dim center As XYZ = box.Min.Add(box.Max).Multiply(0.5)

        ' Project in the negative Z direction down to the floor.
        Dim rayDirection As New XYZ(0, 0, -1)

        'Dim filter As New ElementClassFilter(GetType(Floor))
        ' Dim filter As New ElementClassFilter(GetType(TopographySurface))
        Dim filter As New ElementClassFilter(GetType(TopographySurface))

        'Dim refIntersector As New ReferenceIntersector(filter, FindReferenceTarget.Face, view3D)
        Dim refIntersector As New ReferenceIntersector(filter, FindReferenceTarget.Mesh, view3D)
        Dim referenceWithContext As ReferenceWithContext = refIntersector.FindNearest(center, rayDirection)

        Dim reference As Reference = referenceWithContext.GetReference()
        Dim intersection As XYZ = reference.GlobalPoint

        ' Create line segment from the start point and intersection point.
        Dim result As Line = Line.CreateBound(center, intersection)


        'Create spot elevation


        Dim p As XYZ = result.GetEndPoint(1)

        Dim bEnd As XYZ = p.Add(New XYZ(0, 1, 4))
        Dim EndPnt As XYZ = p.Add(New XYZ(0, 2, 4))


        Dim curView As DB.View = doc.ActiveView
        Dim rp As New Reference(curView)



        Dim sd As SpotDimension = doc.Create.NewSpotElevation(curView, reference, p, bEnd, EndPnt, p, True)



        Return result
    End Function
0 Likes
Message 5 of 6

FAIR59
Advisor
Advisor

I vaguely remember that the X coordinate of bEnd can't be the same as the X-coordinate of EndPnt.

0 Likes
Message 6 of 6

jeremytammik
Autodesk
Autodesk

Please fix the code and submit a pull request for the correction to be included in future versions.

 

To explore what might be going wrong, you might want to perform the operation manually in the user interface first, then explore the results and how to achieve the same via API. 

 

The error message in your screen snapshot is in Russian. Please submit the text, so we can plug it into a translation tool.

 

Thank you!



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

0 Likes