.net Create Pipe Network "Object reference not set to an instance of an object"

.net Create Pipe Network "Object reference not set to an instance of an object"

r_nijkamp
Explorer Explorer
1,484 Views
2 Replies
Message 1 of 3

.net Create Pipe Network "Object reference not set to an instance of an object"

r_nijkamp
Explorer
Explorer

I try to create a pipe network with VB.net.

First step is to create the network, this works well.

Next step is to parse a selection of lines and add them as a pipe to my network.

The command AddLinePipe throws the error Object reference not set to an instance of an object.

I can't find why it doesn't work?

 

Somebody who could tell me what's wrong?

 

Public Shared Function createPipeNetwork(ByVal oNetworkId As ObjectId, ByVal sPartListSize as string, ByVal LineSegment As LineSegment3d) As Boolean
	Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
	Dim acCurDb As Database = acDoc.Database
	Dim civilDoc As CivilDocument = CivilApplication.ActiveDocument
	Dim sPartListSet As String = "Company_Parts list"
	Dim sPartList As String = "HDPE_buizen"

	Try
		Using acLockDoc As DocumentLock = acDoc.LockDocument()
			Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
				Dim oPipeNetworkIds As ObjectIdCollection
				Dim oNetwork As Network
				Try
					oNetwork = acTrans.GetObject(oNetworkId, OpenMode.ForWrite)
				Catch ex as Exception
					MsgBox(ex.Message & " --- " & vbCrLf & ex.InnerException.ToString)
					createPipeNetwork = False
					Exit Function
				End Try

				oPipeNetworkIds = civilDoc.GetPipeNetworkIds()
				If (oPipeNetworkIds Is Nothing) Then
					MsgBox("There is no PipeNetwork Collection." + Convert.ToChar(10))
					createPipeNetwork = False
					Exit Function
				End If

				Dim oPartsListId As ObjectId = civilDoc.Styles.PartsListSet(sPartListSet) 
				Dim oPartsList As PartsList = acTrans.GetObject(oPartsListId, OpenMode.ForWrite)
				Dim oidPipe As ObjectId = oPartsList(sPartList)
				Dim opfPipe As PartFamily = acTrans.GetObject(oidPipe, OpenMode.ForWrite)

				Dim psizePipe As ObjectId = opfPipe(sPartListSize)
				Dim oidNewPipe As ObjectId = Autodesk.AutoCAD.DatabaseServices.ObjectId.Null
				oNetwork.AddLinePipe(oidPipe, psizePipe, LineSegment, oidNewPipe, True) 'on this line the error shows
				
				Dim oidStructure As ObjectId = oPartsList("Null Structure")
				Dim opfStructure As PartFamily = acTrans.GetObject(oidStructure, OpenMode.ForWrite)
				Dim psizeStructure As ObjectId = opfStructure(0)
				Dim startPoint As Point3d = LineSegment.StartPoint
				Dim oidNewStructure As ObjectId = Autodesk.AutoCAD.DatabaseServices.ObjectId.Null
				oNetwork.AddStructure(oidStructure, psizeStructure, startPoint, 0, oidNewStructure, True)
				acTrans.Commit()
				createPipeNetwork = True
			End Using
		End Using
	Catch ex As Exception
		MsgBox(ex.Message & " --- " & vbCrLf & ex.InnerException.ToString)
		Exit Function
	End Try
End Function
0 Likes
Accepted solutions (1)
1,485 Views
2 Replies
Replies (2)
Message 2 of 3

Jeff_M
Consultant
Consultant
Accepted solution

@r_nijkamp , I don't use VB so not sure of the wording, but this line:

 

oNetwork.AddLinePipe(oidPipe, psizePipe, LineSegment, oidNewPipe, True)

 should be something like this:

oNetwork.AddLinePipe(oidPipe, psizePipe, LineSegment, ByRef oidNewPipe, False)

The last argument is saying to use the PipeRules, but if the PartSize doesn't have a RuleStyleId assigned then you will get the error you noted. 

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 3 of 3

r_nijkamp
Explorer
Explorer

Thanks Jeff.

 

the argument about the piperules had to be False.

0 Likes