Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.