Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
r_nijkamp
706 Views, 2 Replies

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

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
2 REPLIES 2
Message 2 of 3
Jeff_M
in reply to: r_nijkamp

@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
Message 3 of 3
r_nijkamp
in reply to: Jeff_M

Thanks Jeff.

 

the argument about the piperules had to be False.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report