PressurePipeRun.Merge open for write?

PressurePipeRun.Merge open for write?

kevin.bza
Advocate Advocate
246 Views
2 Replies
Message 1 of 3

PressurePipeRun.Merge open for write?

kevin.bza
Advocate
Advocate

Greetings,

PressurePipeRun does not include the ObjectId property.

How do you open PressurePipeRun objects for write to do the PressurePipeRun Merge method?

Thx for your patience,

K.

 

0 Likes
Accepted solutions (1)
247 Views
2 Replies
Replies (2)
Message 2 of 3

hippe013
Advisor
Advisor
Accepted solution

The PressurePipeNetwork is what needs to be opened for write. 

 

See quick example below: 

<CommandMethod("PP_Merge")>
Public Sub CmdPP_Merge()
   Dim aDoc As Document = Application.DocumentManager.MdiActiveDocument
   Dim db As Database = aDoc.Database
   Dim ed As Editor = aDoc.Editor

   Dim opt1 As New PromptEntityOptions(vbCrLf & "Select First Pressure Part: ")
   opt1.SetRejectMessage(vbCrLf & "Selected entity must be a Pressure Part. Try again.")
   opt1.AddAllowedClass(GetType(PressurePart), False)

   Dim res1 As PromptEntityResult = ed.GetEntity(opt1)

   If res1.Status <> PromptStatus.OK Then Exit Sub

   Dim opt2 As New PromptEntityOptions(vbCrLf & "Select Second Pressure Part: ")
   opt2.SetRejectMessage(vbCrLf & "Selected entity must be a Pressure Part. Try again.")
   opt2.AddAllowedClass(GetType(PressurePart), False)

   Dim res2 As PromptEntityResult = ed.GetEntity(opt2)

   If res2.Status <> PromptStatus.OK Then Exit Sub

   Using tr As Transaction = db.TransactionManager.StartTransaction
      Dim pp1 As PressurePart = tr.GetObject(res1.ObjectId, OpenMode.ForRead)
      Dim pp2 As PressurePart = tr.GetObject(res2.ObjectId, OpenMode.ForRead)

      If pp1.NetworkId <> pp2.NetworkId Then
         ed.WriteMessage(vbCrLf & "Selected parts must belong to the same network.")
         Exit Sub
      End If

      Dim network As PressurePipeNetwork = tr.GetObject(pp1.NetworkId, OpenMode.ForWrite)

      Dim runs As PressurePipeRunCollection = network.PipeRuns

      Dim run1 As PressurePipeRun = Nothing
      Dim run2 As PressurePipeRun = Nothing

      For Each run As PressurePipeRun In runs
         If run.GetPartIds.Contains(pp1.ObjectId) Then
            run1 = run
         End If
         If run.GetPartIds.Contains(pp2.ObjectId) Then
            run2 = run
         End If
      Next

      If run1 Is Nothing OrElse run2 Is Nothing Then
         ed.WriteMessage(vbCrLf & "Error finding runs.")
         Exit Sub
      End If

      If run1.Name = run2.Name Then
         ed.WriteMessage(vbCrLf & "Pipe runs cannot be the same.")
         Exit Sub
      End If

      Try
         run1.Merge(run2)
      Catch ex As Exception
         ed.WriteMessage(vbCrLf & "Cannot merge pipe runs that are not connected.")
         Exit Sub
      End Try

      ed.WriteMessage(vbCrLf & "Pipe runs have been merged.")

      tr.Commit()
   End Using
End Sub

 

If someone knows of a better way of getting the corresponding pipe run from the pressure part, please chime in. It seems to me that there should be a more direct way of getting the pipe run from the selected pressure part.

Message 3 of 3

kevin.bza
Advocate
Advocate

THANK YOU  : )

0 Likes