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: 

surface Offset on the sections sample lines

7 REPLIES 7
Reply
Message 1 of 8
alexjuinamt
150 Views, 7 Replies

surface Offset on the sections sample lines

The following code works if the surface is of the CorridorSurface type, if a TinSurface is selected, an error occurs, what is wrong in the code?

 

Private Function ObterLargurasSecoes(alinID As ObjectId, sufID As ObjectId, estaca As Double, larguraMax As Double, ByRef LE As Double, ByRef LD As Double) As Boolean
    ' Documents
    Dim acadDoc As Document = acApp.DocumentManager.MdiActiveDocument
    Dim civilDoc As CivilDocument = CivilApplication.ActiveDocument
    Dim ed As Editor = acadDoc.Editor

    Using tr2 As Transaction = acadDoc.TransactionManager.StartTransaction
        ' Get the alignment
        Dim alin As Alignment = tr2.GetObject(alinID, OpenMode.ForRead)

        ' Create a group of points with the external vertices of the sample line
        Dim grupoDePontos2D As New Point2dCollection()

        ' Define the coordinates for the left side
        Dim esteLE As Double = Nothing
        Dim norteLE As Double = Nothing
        alin.PointLocation(estaca, -larguraMax, esteLE, norteLE)
        Dim pontoLE As New Point2d(esteLE, norteLE)
        grupoDePontos2D.Add(pontoLE)

        ' Define the coordinates for the right side
        Dim esteLD As Double = Nothing
        Dim norteLD As Double = Nothing
        alin.PointLocation(estaca, larguraMax, esteLD, norteLD)
        Dim pontoLD As New Point2d(esteLD, norteLD)
        grupoDePontos2D.Add(pontoLD)

        ' Create a temporary sample line group
        Dim slGrupID As ObjectId = SampleLineGroup.Create("AlX_x-x_GrLixo " & alin.Name, alinID)
        Dim slGrup As SampleLineGroup = tr2.GetObject(slGrupID, OpenMode.ForWrite)

        ' Create a sample line
        Dim SlID As ObjectId = SampleLine.Create("AlX_x-x_slLixo", slGrupID, grupoDePontos2D)

        ' Get the section sources available for the SampleLineGroup and choose the surface
        Dim sectionSources As SectionSourceCollection = slGrup.GetSectionSources()
        For Each sectionSource As SectionSource In sectionSources
            If sectionSource.SourceId = sufID Then
                sectionSource.IsSampled = True
                Exit For
            End If
        Next

        ' Get the sample line
        Dim sl As SampleLine = tr2.GetObject(SlID, OpenMode.ForRead)

        ' Get the collection of sections in the sample line; there will be only one
        Dim slIDs As ObjectIdCollection = sl.GetSectionIds()

        ' Get the section
        Dim secao As Autodesk.Civil.DatabaseServices.Section = tr2.GetObject(slIDs(0), OpenMode.ForWrite)

        Try
            LE = secao.LeftOffset
        Catch
            LE = Nothing
        End Try

        Try
            LD = secao.RightOffset
        Catch
            LD = Nothing
        End Try

        ' Do not commit to avoid creating the auxiliary sample line
    End Using

    ' Return false if no values are found
    If LD = Nothing And LE = Nothing Then
        Return False
    Else
        Return True
    End If
End Function

 

 

 

 

7 REPLIES 7
Message 2 of 8
essam-salah
in reply to: alexjuinamt


@alexjuinamt wrote:

The following code works if the surface is of the CorridorSurface type, if a TinSurface is selected, an error occurs, what is wrong in the code?


what is the error type and error message you get?

Message 3 of 8
alexjuinamt
in reply to: essam-salah

I get the error: 'System.InvalidOperationException'. I will attach the images where the error occurs and another that does not occur.

Message 4 of 8
Jeff_M
in reply to: alexjuinamt

This appears to be the error thrown when there is no portion of the section on the right side.

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 8
alexjuinamt
in reply to: Jeff_M

Yes, it seems to be the same error, however there is a section of the surface on both sides. The following image is the section view generated by the code.

Message 6 of 8
essam-salah
in reply to: alexjuinamt


@alexjuinamt wrote:

I get the error: 'System.InvalidOperationException'. I will attach the images where the error occurs and another that does not occur.


sadly, as VS decompiled code below it shows that there is two types of sections that don't have Left/Right Offsets properties,

  public unsafe double LeftOffset
  {
    get
    {
      //IL_003b: Expected I, but got I8
      //IL_0053: Expected I4, but got I8
      //IL_005e: Expected I, but got I8
      //IL_0074: Expected I, but got I8
      //IL_0076: Expected I8, but got I
      //IL_0095: Expected I4, but got I8
      //IL_00dc: Expected I, but got I8
      string message = "LeftOffset is not supported by current Section.";
      byte b = (isSectionSupportOffsetElevation() ? ((byte)1) : ((byte)0));
      if (0 == b)
      {
        throw new InvalidOperationException(message);
      }

      AeccDbSection* impObj = GetImpObj();
      long num = *(long*)(*(long*)impObj + 3544);

...
}

  [return: MarshalAs(UnmanagedType.U1)]
  private unsafe bool isSectionSupportOffsetElevation()
  {
    //IL_0017: Expected I, but got I8
    bool result = true;
    AeccDbSection* impObj = GetImpObj();
    AeccSectionSource.SectionDataType sectionDataType = ((delegate* unmanaged[Cdecl, Cdecl]<IntPtr, AeccSectionSource.SectionDataType>)(*(ulong*)(*(long*)impObj + 3400)))((nint)impObj);
    if (sectionDataType == (AeccSectionSource.SectionDataType)4 || sectionDataType == (AeccSectionSource.SectionDataType)8)
    {
      result = false;
    }

    GC.KeepAlive(this);
    return result;
  }

public enum SectionSourceType
{
  TinSurface,
  Grading,
  Corridor,
  CorridorSurface,
  PipeNetwork,
  Material,
  GridSurface
}

 

 

Message 7 of 8
essam-salah
in reply to: essam-salah


@essam-salah wrote:
sadly, as VS decompiled code below it shows that there is two types of sections that don't have Left/Right Offsets properties,

so if you can show us in a pic what exactly what do you want to get/achieve some one might be able to help,

for example, if you want that section start/end points as offsets (from assembly CL) simply we can use props like  section.StartPoint or section.SectionPoints to get the end points as XY coordinates then use profile view function called profileView.FindStationAndElevationAtXY  to get station/offset.

Message 8 of 8
essam-salah
in reply to: alexjuinamt


@alexjuinamt wrote:

The following code works if the surface is of the CorridorSurface type, if a TinSurface is selected, an error occurs, what is wrong in the code?


now it make sense cuz corridor section has created from an assembly that have Left/Right props, any other section that created from Non-Corridor surface (so to speak) no nothing about the corridor nor the used assemblies

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

Post to forums  

Rail Community


Autodesk Design & Make Report