Problem in creation of Detail Line

Problem in creation of Detail Line

MehtaRajesh
Advocate Advocate
2,368 Views
3 Replies
Message 1 of 4

Problem in creation of Detail Line

MehtaRajesh
Advocate
Advocate
 
 
Hello All, 
I am creating Detail Line in View, I am getting error "System.NullReferenceException: Object reference not set to an instance of an object"  at DetailLine line1 = doc.Create.NewDetailCurve(view, geomLine1) as DetailLine; 

Please let me know why this error is coming and what is the solution,
Thanks in advance for your kind support in this regards
Rajesh


ExternalCommandData cdata = commandData; m_app = commandData.Application; m_doc = commandData.Application.ActiveUIDocument.Document; view = m_doc.ActiveView; uiApp = commandData.Application; uiDoc = uiApp.ActiveUIDocument; app = m_app.Application; if (null == m_doc) { message = "There is no active document."; return Autodesk.Revit.UI.Result.Failed; } // Create a few geometry lines. These lines are transaction (not in the model), // therefore they do not need to be created inside a document transaction. XYZ Point1 = XYZ.Zero; XYZ Point2 = new XYZ(10, 0, 0); XYZ Point3 = new XYZ(10, 10, 0); XYZ Point4 = new XYZ(0, 10, 0); Line geomLine1 = Line.CreateBound(Point1, Point2); // This geometry plane is also transaction and does not need a transaction XYZ origin = XYZ.Zero; XYZ normal = new XYZ(0, 0, 1); Plane geomPlane = app.Create.NewPlane(normal, origin); using (Transaction transaction = new Transaction(m_doc)) { if (transaction.Start("Create model curves") == TransactionStatus.Started) { // Create a sketch plane in current document SketchPlane sketch = SketchPlane.Create(m_doc, geomPlane); DetailLine line1 = doc.Create.NewDetailCurve(view, geomLine1) as DetailLine; (ERROR I am getting is System.NullReferenceException: Object reference not set to an instance of an object }

 

}

 

0 Likes
Accepted solutions (1)
2,369 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Hello MehtaRajesh,

 

are you running it in a view where detail lines can't be created?

Where do you start/Commit your transaction?

 

/Martin

0 Likes
Message 3 of 4

MehtaRajesh
Advocate
Advocate

Hi Martin,

Thanks,

I need to create Detail Line in currently opened Sheet,
Please help me, what I am doing wrong in the code.

Thanks and Regards,
Rajesh

0 Likes
Message 4 of 4

Anonymous
Not applicable
Accepted solution

When creating your detail line you are using doc.create but your Document variable is named m_doc

 

Change your transaction to something like this:

 

Transaction transaction = new Transaction(m_doc, "Create Detail Line");
{
 transaction.Start();
      // Create a sketch plane in current document
      SketchPlane sketch = SketchPlane.Create(m_doc, geomPlane);                

      DetailLine line1 = m_doc.Create.NewDetailCurve(view, geomLine1) as DetailLine; 
	

 transaction.Commit();
}
   }

Good Luck!

 /Martin

0 Likes