We previously discussed various aspects of model lines, such as model line creation, the model line sketch plane, and the minimal length of a model line. Here is a question on the related topic of detail lines handled by my colleague Saikat Bhattacharya:
Question: How can I create a detail line on a drafting view? I tried to use the following statement:
doc.Create.NewDetailCurve( View, curve, y );It is unclear to me what the "curve" and the "sketchPlane" stand for and how to use them. Please could you provide me with a small sample.
Answer: Detail curves are created for drawings such as a detail or drafting view. They are annotation elements and are visible only in the view in which they are drawn. They can currently only be created in plan views.
Except for this, detail curves are similar to model curves. ModelLine and DetailLine both belong to the Lines category. Thus, for a sample on creating detail curves, you can refer to and slightly adapt the Revit SDK sample ModelLines, which shows how to work with the sketch plane and geometry curve to create a new model line.
For more details on sketch planes and model curves, you can also refer to the developer guide "Revit 2010 API Developer Guide.pdf", especially chapter 14, Annotation Elements, and section 14.2, Detail Curve. Another helpful section is 15.3.1 on Creating a ModelCurve and the Code Region 15-2: Creating a new model curve, which illustrates how to create new geometry curves, a sketch plane, and model curves, a ModelLine and a ModelArc. You can use the same approach to create detail curves as well.
I implemented a new external command CmdDetailCurves in The Building Coder sample application by slightly modifying the sample code provided in the developer guide. Here is the code of the new command's Execute method:
Application app = commandData.Application; Document doc = app.ActiveDocument; View view = doc.ActiveView; // Create a geometry line XYZ startPoint = new XYZ( 0, 0, 0 ); XYZ endPoint = new XYZ( 10, 10, 0 ); Line geomLine = app.Create.NewLine( startPoint, endPoint, true ); // Create a geometry arc XYZ end0 = new XYZ( 1, 0, 0 ); XYZ end1 = new XYZ( 10, 10, 10 ); XYZ pointOnCurve = new XYZ( 10, 0, 0 ); Arc geomArc = app.Create.NewArc( end0, end1, pointOnCurve ); // Create a geometry plane XYZ origin = new XYZ( 0, 0, 0 ); XYZ normal = new XYZ( 1, 1, 0 ); Plane geomPlane = app.Create.NewPlane( normal, origin ); // Create a sketch plane in current document SketchPlane sketch = doc.Create.NewSketchPlane( geomPlane ); // Create a DetailLine element using the // created geometry line and sketch plane DetailLine line = doc.Create.NewDetailCurve( view, geomLine ) as DetailLine; // Create a DetailArc element using the // created geometry arc and sketch plane DetailArc arc = doc.Create.NewDetailCurve( view, geomArc ) as DetailArc; return CmdResult.Succeeded;
As you see, the curve parameter above can be any geometric curve entity like Line, Arc, Ellipse or NurbSpline. All of these types are derived from the Curve class and can be used as parameters to create a detail curve.
Here are the resulting detail curves after running this command in a new project document:
Here is version 1.1.0.46 of the complete Building Coder sample source code and Visual Studio solution including the new command.
Thank you Saikat for this helpful explanation!
Addendum: Please make sure you do not overlook the update to this post.
Hi Jeremy,
How are you?
I've got a question for you.
I've searched but...no idea...
I'd like to change de view with API. For exemple, passing floor plan level0 to the floor plan level1 with the API.
I rode that it could be possible using ShowElement..but how??
Cheers.
Posted by: Pierre NAVARRA | September 03, 2009 at 05:35
Dear Pierre,
Thank you, I am fine, I hope you are as well. I am sorry to say that there is currently no possibility in the API to change a view. A wish list item for this functionality has been recorded. One developer found a really horrible workaround which does actually change the view, but it is only usable for internal debugging and development purposes: if you pass the view back to Revit in the set of elements to highlight in case of an error in an external command and then return 'Failed', the view is displayed together with the error message. Obviously this is not usable for production purposes, but it does constitute a funny and surprising workaround.
Cheers, Jeremy.
Posted by: Jeremy Tammik | September 03, 2009 at 06:44
Hi, Jeremy, how are you?
Thanks you answer my questions before.
I get questions for you.
The first one is an error called "Expected two different points.". I think this error comes from two model line on superposition. And how can I make two model line on superposiontion without error?
The second one is how to change the color of model line.
Thanks, have a good day.
Posted by: Owen | September 03, 2009 at 19:48
Dear Owen,
Thank you, I am fine, I hope you are as well. Glad I could answer your questions. I don't know either how to reproduce or how to avoid the error you mention. You might want to have a look at this post on the minimal length of model lines in Revit, though:
http://thebuildingcoder.typepad.com/blog/2009/07/think-big-in-revit.html
Regarding the colour settings, I do not know how to set line colour completely freely. In Revit, things are generally managed in a systematic and parametric manner, which ensures that the model remains well structured. In this case, you can modify model line colours by changing line style settings. I did the following to test this:
- Create a couple of model lines
- For each one of these, right click for the context menu and select Element Properties... > Line style and pick a different line style.
- Right click somewhere in empty space in the current view to bring up the view context menu, and select View Properties... > Visibility/Graphics Overrides > Edit... > Model Categories > Visibility and search for the Lines entry. Click on the little plus sign to display the lines subcategories.
- For each of the line styles you selected above, find the corresponding subcategory and change the colour displayed in its Projection/Surface Lines column.
There are probably other methods as well.
Cheers, Jeremy.
Posted by: Jeremy Tammik | September 04, 2009 at 01:49
Jeremy,
I am using
Document document = application.NewProjectDocument(string templateFile)
Revit shows that it is loading the template as it does usually when it creates a new document; however, it does not really create the new document.
any idea why?
Regards,
Nadim
Posted by: NAyche | November 22, 2009 at 20:53
Dear Nadim,
I implemented a sample external command CmdNewProjectDoc to test it for you and it works fine for me. Please refer to
http://thebuildingcoder.typepad.com/blog/2009/11/new-project-document.html
Cheers, Jeremy.
Posted by: Jeremy Tammik | November 23, 2009 at 06:37
Jeremy,
Thank you again for you response.
I guess the NewProjectDocument() method only creates a document but it does not open it.
So it works so far, I got the doucment saved.
I tried to use the app.OpenDocumentFile(doc.PathName) to open it, it does not display the document. Even though it shows it does.
To verify, I subscribed a simple event handler to the app.OnDocumentOpen event (I am using Revit 2009), it did not execute.
It sounds very simple to implement, but I just can’t find what I am missing.
Regards,
Nadim
Posted by: NAyche | November 24, 2009 at 09:41
Dear Nadim,
Yes, correct, NewProjectDocument only creates a document and does not open it.
There is currently no API method at all to make a document current in the Revit user interface. The only workaround I ever heard about is to use Process.Start as described in the comments
http://thebuildingcoder.typepad.com/blog/2008/09/debugging-a-rev.html?cid=6a00e553e16897883301156fc1fed8970b#comment-6a00e553e16897883301156fc1fed8970b
Sorry for the bad news.
Cheers, Jeremy.
Posted by: Jeremy Tammik | November 24, 2009 at 10:42
Thanks again Jeremy,
It works.
nothing is bad news as long as the RevitAPI developers are planning on fixing it
So basically, the app.OpenDocumentFile() method will open the file but it would not display it :)
Regards,
Nadim
Posted by: NAyche | November 24, 2009 at 12:05
Dear Nadim,
Yes, exactly.
Cheers, Jeremy.
Posted by: Jeremy Tammik | November 24, 2009 at 12:27
I try to implement a macro in VSTA but cannot get this built. The compiler keeps complaining about an abstract class XYZ. 'Cannot create an instance of the abstract class or interface 'Autodesk.Revit.Geometry.XYZ''
It seems like the XYZ class is defined as an abstract class in the VSTA environment and as a public class in the visual studio environment. One can check this by means of the object browser.
What' the reason for the difference? Can I port it somehow to VSTA?
Posted by: wim Tas | January 10, 2010 at 06:06
Dear Wim,
One thing that you need to pay attention to in VSTA is that you cannot use the XYZ class default constructor. You have to use the creation application NewXYZ method instead to create new instances of XYZ objects.
Cheers, Jeremy.
Posted by: Jeremy Tammik | January 11, 2010 at 16:04