ok, I have been stuck on something for quite a while now, sorry if it is a newby question. When wanting to draw a line via the Revit api, all works perfect as long as the view is a drafting view. How can I draw in a section or elevation without having to figure out what direction I am looking for the x,y,z? How do you make the current view "normal" to where x is to the right and y is up the page? Any thoughts?
Thanks!!
these are model lines. So are you saying, no matter how the section is cut, X should always be to the right, and Y should always be up? I that is the case, I am missing something, when I cut a section and draw a line via .net, XY and Z are different depending on which way the section cut is looking.
would detail lines behave better?
Thanks
Hi bcampbell,
as far as I understand your question, you just want to draw lines in a 2D context, as if using GDI methods.
It is okay to ignore the Z value in drafting views (using value 0 for it) since those views reside in a XY plane on elevation 0.
In elevation views and section views, you are forced to use the transformed geometry of your proposed lines.
This means you need to calculate the transform of your target view, using its origin and up, right and view direction vectors.
Revitalizer
I have done some pretty cool things with the Revit api (in my opinion) but to simply draw a line seems to be one of the most difficult things you can do with the Revit API (Autocad is much much easier).
Lets try a model line, could you explain to me why even trying to get the example below from the SDK tells me "Curve must be in the plane". and by "absolute" do you mean anywhere in the model, looking any direction, I can a line that goes up and to the right with the same coordinates? Not a lot of good resources out there for this kind of thing unfortunately, hard to learn.
Thanks
' get handle to application from document
Dim application As Autodesk.Revit.ApplicationServices.Application = document.Application
' Create a geometry line in Revit application
Dim startPoint As New XYZ(0, 0, 0)
Dim endPoint As New XYZ(10, 10, 0)
Dim geomLine As Line = Line.CreateBound(startPoint, endPoint)
' Create a geometry arc in Revit application
Dim end0 As New XYZ(1, 0, 0)
Dim end1 As New XYZ(10, 10, 10)
Dim pointOnCurve As New XYZ(10, 0, 0)
Dim geomArc As Arc = Arc.Create(end0, end1, pointOnCurve)
' Create a geometry plane in Revit application
Dim origin As New XYZ(0, 0, 0)
Dim normal As New XYZ(1, 1, 0)
Dim geomPlane As Plane = application.Create.NewPlane(normal, origin)
' Create a sketch plane in current document
Dim sketch As SketchPlane = SketchPlane.Create(document, geomPlane)
' Create a ModelLine element using the created geometry line and sketch plane
Dim line__1 As ModelLine = TryCast(document.Create.NewModelCurve(geomLine, sketch), ModelLine)
' Create a ModelArc element using the created geometry arc and sketch plane
so, did you just change this line in the example???
from:
Dim normal As New XYZ(1, 1, 0)
to:
Dim normal As New XYZ(0, 0, 1)
either way, it produces the same error.
This code works for your model line:
XYZ origin = new XYZ(0, 0, 0); XYZ normal = new XYZ(0, 0, 1); Plane plane = app.Create.NewPlane(normal, origin); SketchPlane skplane = SketchPlane.Create(doc, plane); XYZ startPoint = new XYZ(0, 0, 0); XYZ endPoint = new XYZ(10, 10, 0); Line l = Line.CreateBound(startPoint, endPoint); ModelLine ml = doc.Create.NewModelCurve(l, skplane) as ModelLine;
Now your code for arc is a bit different as the points are in a more complex scenario... so let's try a more generic approach with CrossProduct from end1 and pointOnCurve and using end0 as origin for the plane
XYZ end0 = new XYZ(1, 0, 0); XYZ end1 = new XYZ(10, 10, 10); XYZ pointOnCurve = new XYZ(10, 0, 0); Arc a = Arc.Create(end0, end1, pointOnCurve); XYZ origin = end0; XYZ normal = end1.CrossProduct(pointOnCurve); Plane plane = app.Create.NewPlane(normal, origin); SketchPlane skplane = SketchPlane.Create(doc, plane); ModelArc ml = doc.Create.NewModelCurve(a, skplane) as ModelArc;
And I hope my math is ok 🙂
Form wikipedia, just in case: https://en.wikipedia.org/wiki/Cross_product
I know this is an old post, but I wonder if you found the way to get point XYZ (start and end) for the detail line to always match the viewplane (to draw on the view plane)?
Can't find what you're looking for? Ask the community or share your knowledge.