ModelCurve & ModelLine - How?

Anonymous

ModelCurve & ModelLine - How?

Anonymous
Not applicable

In the course of learning and debugging, I wanted to do something simple - create a visible line (an element in the database or simply a visible mark) from a known point to let me see if I'd got the right position in the drawing. ModelLine seems to fit the bill. 

 

1) Why on earth do I need a sketch plane? Why does inserting a visible line from one 3D point to another - which gives every single piece of information you need to create the object and was perfectly good enough in AutoCAD - require anything else? How do I *use* sketch planes? Where should the ModelLine be in relation to the plane's origin and normal? 

 

2) The example code given in the WikiHelp (http://wikihelp.autodesk.com/Revit/enu/2013/Help/00006-API_Developer's_Guide/0074-Revit_Ge74/0114-Sk...) for creating various ModelCurve types does *not* work - it throws an exception saying 'curve must be in the plane'. So attempting to figure it out from there was a complete failure. 

 

3) Is WikiHelp the only source of help on the API? Is there no API help file like arxref.chm for AutoCAD's ObjectARX classes, or acad_mgd.chm for .NET? I'm finding the Wiki very slow to search, it often bombs out (ERR_EMPTY_RESPONSE), and it is very hard to find relevant and useful information in there - many pages in the API guide side of things talk about things from the UI side only, and don't have code samples. Is there a reference on the classes and their methods? 

 

I should clarify that I'm testing with Visual Studio 2010 Pro and Revit Architecture 2013. 

 

0 Likes
Reply
Accepted solutions (1)
1,899 Views
2 Replies
Replies (2)

augusto.goncalves
Alumni
Alumni
Accepted solution

Here is a small sample code to help you draw a Model Line, hope it helps...

 

public static void MakeLine(Autodesk.Revit.UI.UIApplication app,

  Autodesk.Revit.DB.XYZ startpt, Autodesk.Revit.DB.XYZ endpt,

  Autodesk.Revit.DB.XYZ direction, string style)

{

  try

  {

    Line line = app.Application.Create.NewLineBound(startpt, endpt);

    XYZ rotatedDirection = XYZ.BasisX;

    if (!direction.IsAlmostEqualTo(XYZ.BasisZ) && !direction.IsAlmostEqualTo(-XYZ.BasisZ))

    {

      rotatedDirection = direction.Normalize().CrossProduct(XYZ.BasisZ);

    }

 

    Plane geometryPlane = app.Application.Create.NewPlane(direction, rotatedDirection, startpt);

    SketchPlane skplane = app.ActiveUIDocument.Document.Create.NewSketchPlane(geometryPlane);

    ModelCurve mcurve = app.ActiveUIDocument.Document.Create.NewModelCurve(line, skplane);

    ElementArray lsArr = mcurve.LineStyles;

    foreach (Autodesk.Revit.DB.Element e in lsArr)

    {

      if (e.Name == style)

      {

        mcurve.LineStyle = e;

        break;

      }

    }

  }

  catch (System.Exception e)

  {

  }

}

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network

Anonymous
Not applicable

Thank you.

 

What I discovered in the end - and I was hoping someone would clarify here - is that in order to draw a ModelCurve of any kind, *all* points on that curve must lie *on* the plane used to construct it. That is why the sample in the Wiki didn't work - and shame on people for not checking it because it is of zero help as it stands - because the line was pointing in the plane's normal, rather than lying fully on the plane.

 

With all due respect, giving another sample (while valid this time) didn't really do what was needed, which was to explain *how* the ModelCurve and plane are related - i.e., what the requirements are for it to be successful. This, unfortunately, is the biggest problem with documentation - lots of lengthy paragraphs but very few *explanations* and no clear examples that demonstrate the information. Very hard to learn from it 😞

 

That doesn't mean that I don't appreciate your response, though.