List Corridor Target Mapping

By Augusto Goncalves

At the Corridor Properties window, under Parameters tab, it is possible see access the targets mapping of the corridor, as shown at the image below How can we access that using APIs?

target_mapping_corridor

The following code sample opens the corridor and list its target mapping. But this is the first level. For each baseline we can also see find targets, so the second step of this sample iterate through the collection of baselines and list its targets.

Moving forward, SubassemblyTargetInfo.TargetIds collection accepts Add and Remove methods for editing.

<CommandMethod("listCorridorTargetProperties")> _

Public Shared Sub CmdListCorridorTargets()

  ‘ acess Civil 3D Document and Editor

  Dim ed As Editor = Application.DocumentManager. _

    MdiActiveDocument.Editor

  Dim civilDoc As CivilDocument = _

    CivilApplication.ActiveDocument

 

  ‘ select the corridor

  Dim opCorridor As New PromptEntityOptions( _

    "Select a corridor: ")

  opCorridor.SetRejectMessage( _

    "Only corridor allowed")

  opCorridor.AddAllowedClass( _

    GetType(Corridor), True)

  Dim resCorridor As PromptEntityResult = _

    ed.GetEntity(opCorridor)

  If (resCorridor.Status <> _

      PromptStatus.OK) Then Return

 

  ‘ get the list

  Dim listOfTargets As String = _

    ListCorridorTargets(resCorridor.ObjectId)

 

  ‘ print

  ed.WriteMessage(listOfTargets)

End Sub

 

Private Shared Function ListCorridorTargets( _

        ByVal corridorId As ObjectId) As String

  Dim list As New System.Text.StringBuilder

 

  ‘ get the database and start a transaction

  Dim db As Database = corridorId.Database

  Using trans As Transaction = db. _

    TransactionManager.StartTransaction()

 

    ‘ open corridor

    Dim corr As Corridor = trans.GetObject( _

      corridorId, OpenMode.ForRead)

 

    ‘ list targets of the corridor

    list.Append(ListTargets(trans, corr.GetTargets()))

 

    ‘ now append each baseline

    For Each bline As Baseline In corr.Baselines

      list.AppendFormat("{0}{0}{1}", _

                        Environment.NewLine, _

                        bline.Name)

      list.Append( _

        ListTargets( _

          trans, _

          bline.GetTargets()))

    Next

 

    trans.Commit()

  End Using

 

  Return list.ToString()

End Function

 

Private Shared Function ListTargets( _

          ByVal trans As Transaction, _

          ByVal targets As  _

          SubassemblyTargetInfoCollection) _

        As String

  Dim list As New System.Text.StringBuilder

 

  ‘ list targets

  For Each target As SubassemblyTargetInfo In targets

    list.AppendFormat("{0}{1}", _

                      Environment.NewLine, _

                      target.DisplayName)

 

    ‘ list targets names

    ‘ it must be done with Civil 3D Entity object, as the

    ‘ generic AutoCAD Entity don’t have the Name we want

    Autodesk.Civil.DatabaseServices.Entity

    For Each itemTargetId As ObjectId In _

      target.TargetIds

      Dim itemTarget As Autodesk.Civil. _

        DatabaseServices.Entity = _

        trans.GetObject(itemTargetId, _

                        OpenMode.ForRead)

      list.AppendFormat("{0}{1}{2}", _

                        Environment.NewLine, _

                        ControlChars.Tab, _

                        itemTarget.Name)

    Next

  Next

 

  Return list.ToString()

End Function


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading