<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Alignment.StationOffset() Function in Excel VBA in Civil 3D Customization Forum</title>
    <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9340391#M8699</link>
    <description>&lt;P&gt;&lt;STRIKE&gt;Hi Jeff,&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;File is attached below, it assumes you have an active drawing with a Pipe Network in it, the spreadsheet is intended to deal with those in the end. I can write something quick dealing only with the alignments if needed.&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;Thanks for looking into this&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jeff,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Having problems attaching the xlsm file, I'll post the code below unless there's a way to attach the macro enabled file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Sub Access_AutoCad()


Dim MyApp As Object
Dim MyDwg As AcadDocument


Set MyApp = GetObject(, "Autocad.Application")
Set MyDwg = MyApp.ActiveDocument


Dim oApp As AcadApplication
Set oApp = MyDwg.Application
Dim sAppName As String

'sAppName will need to change with 2020 to "AeccXUiPipe.AeccPipeApplication.XX.0" the XX being whichever
'version number 2020 uses.
sAppName = "AeccXUiPipe.AeccPipeApplication.12.0"
Dim oPipeApplication As AeccPipeApplication
Set oPipeApplication = oApp.GetInterfaceObject(sAppName)

 'Get a reference to the currently active document.
Dim oPipeDocument As AeccPipeDocument
Set oPipeDocument = oPipeApplication.ActiveDocument

'Creates set of Pipe networks Within the Drawing
Dim oPipeNetworks As AeccPipeNetworks
Set oPipeNetworks = oPipeDocument.PipeNetworks

'Establishes the Working Network
Dim WNet As AeccPipeNetwork
Dim K As Integer

    For P = 0 To oPipeNetworks.Count - 1
        If oPipeNetworks(P).Name = Sheet1.Cells(1, 23).Value Then
        K = P
        End If
    Next P
    
           
Set WNet = oPipeNetworks.Item(K)

Dim WPipes As AeccPipes
Dim WStructures As AeccStructures
Set WPipes = WNet.Pipes
Set WStructures = WNet.Structures
Dim PipeLim As Long
PipeLim = CInt(WPipes.Count) - 1
Dim StrucLim As Long
StrucLim = CInt(WStructures.Count) - 1


Dim stn As Double
Dim Offset As Double

Dim Align As AeccAlignment
Dim Wstruc As AeccStructure
Dim WPipe As AeccPipe
Dim WStrucX As Double
Dim WStrucY As Double


Dim PipeArray(0 To 400, 0 To 8)  As Variant
Dim StrucArray(0 To 400, 0 To 7)  As Variant

Worksheets("Sheet1").Range("A1:V400").ClearContents


        For j = 0 To PipeLim
            
             Set WPipe = WPipes.Item(j)

             PipeArray(j, 0) = WPipe.Description
             PipeArray(j, 1) = WPipe.Style.Name
             PipeArray(j, 2) = WPipe.InnerDiameterOrWidth * 12
             PipeArray(j, 3) = WPipe.StartStructure.Name
             PipeArray(j, 4) = WPipe.EndStructure.Name
             PipeArray(j, 5) = WPipe.StartPoint.Z - (WPipe.InnerDiameterOrWidth / 2)
             PipeArray(j, 6) = WPipe.EndPoint.Z - (WPipe.InnerDiameterOrWidth / 2)
             PipeArray(j, 7) = WPipe.Length2D
             PipeArray(j, 8) = WPipe.Length2D - WPipe.StartStructure.StructureInnerDiameterOrWidth / 2 - WPipe.EndStructure.StructureInnerDiameterOrWidth / 2
             
        Next j



        For w = 0 To StrucLim

             Set Wstruc = WStructures.Item(w)
             Set Align = Wstruc.Alignment
             WStrucX = Wstruc.Position.X
             WStrucY = Wstruc.Position.y
             'Set stn, offset = Align.StationOffset(WstrucX,WStrucY,stn,offset)



             StrucArray(w, 0) = Wstruc.Name
             StrucArray(w, 1) = Wstruc.Style.Name
             'StrucArray(w, 2) = stn
             'StrucArray(w, 3) = offset
             StrucArray(w, 4) = WStrucY
             StrucArray(w, 5) = WStrucX
             StrucArray(w, 6) = Wstruc.RimElevation
        
        Next w


Sheet1.Range("A1:G400").Value = StrucArray
Sheet1.Range("M1:U400").Value = PipeArray


End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Feb 2020 15:26:36 GMT</pubDate>
    <dc:creator>csandersonGKMZ9</dc:creator>
    <dc:date>2020-02-25T15:26:36Z</dc:date>
    <item>
      <title>Alignment.StationOffset() Function in Excel VBA</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9338356#M8697</link>
      <description>&lt;P&gt;I'm trying to use the .StationOffset VBA function to find out the station and offset of a point in relation to an alignment, all within Excel VBA editor.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know within the AutoCAD VBA manager you would simply write out:&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;EM&gt;Align.StationOffset x, y, station, offset&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the syntax doesn't seem to work within Excel's editor. The problem seems to be that the function gives two outputs and I'm not sure how to code for that within Excel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for any help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 18:52:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9338356#M8697</guid>
      <dc:creator>csandersonGKMZ9</dc:creator>
      <dc:date>2020-02-24T18:52:55Z</dc:date>
    </item>
    <item>
      <title>Re: Alignment.StationOffset() Function in Excel VBA</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9338543#M8698</link>
      <description>&lt;P&gt;Can you post your Excel file with the VBA? It's been years since I've worked with that so would take too long to set it up.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 20:10:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9338543#M8698</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2020-02-24T20:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: Alignment.StationOffset() Function in Excel VBA</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9340391#M8699</link>
      <description>&lt;P&gt;&lt;STRIKE&gt;Hi Jeff,&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;File is attached below, it assumes you have an active drawing with a Pipe Network in it, the spreadsheet is intended to deal with those in the end. I can write something quick dealing only with the alignments if needed.&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;Thanks for looking into this&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jeff,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Having problems attaching the xlsm file, I'll post the code below unless there's a way to attach the macro enabled file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Sub Access_AutoCad()


Dim MyApp As Object
Dim MyDwg As AcadDocument


Set MyApp = GetObject(, "Autocad.Application")
Set MyDwg = MyApp.ActiveDocument


Dim oApp As AcadApplication
Set oApp = MyDwg.Application
Dim sAppName As String

'sAppName will need to change with 2020 to "AeccXUiPipe.AeccPipeApplication.XX.0" the XX being whichever
'version number 2020 uses.
sAppName = "AeccXUiPipe.AeccPipeApplication.12.0"
Dim oPipeApplication As AeccPipeApplication
Set oPipeApplication = oApp.GetInterfaceObject(sAppName)

 'Get a reference to the currently active document.
Dim oPipeDocument As AeccPipeDocument
Set oPipeDocument = oPipeApplication.ActiveDocument

'Creates set of Pipe networks Within the Drawing
Dim oPipeNetworks As AeccPipeNetworks
Set oPipeNetworks = oPipeDocument.PipeNetworks

'Establishes the Working Network
Dim WNet As AeccPipeNetwork
Dim K As Integer

    For P = 0 To oPipeNetworks.Count - 1
        If oPipeNetworks(P).Name = Sheet1.Cells(1, 23).Value Then
        K = P
        End If
    Next P
    
           
Set WNet = oPipeNetworks.Item(K)

Dim WPipes As AeccPipes
Dim WStructures As AeccStructures
Set WPipes = WNet.Pipes
Set WStructures = WNet.Structures
Dim PipeLim As Long
PipeLim = CInt(WPipes.Count) - 1
Dim StrucLim As Long
StrucLim = CInt(WStructures.Count) - 1


Dim stn As Double
Dim Offset As Double

Dim Align As AeccAlignment
Dim Wstruc As AeccStructure
Dim WPipe As AeccPipe
Dim WStrucX As Double
Dim WStrucY As Double


Dim PipeArray(0 To 400, 0 To 8)  As Variant
Dim StrucArray(0 To 400, 0 To 7)  As Variant

Worksheets("Sheet1").Range("A1:V400").ClearContents


        For j = 0 To PipeLim
            
             Set WPipe = WPipes.Item(j)

             PipeArray(j, 0) = WPipe.Description
             PipeArray(j, 1) = WPipe.Style.Name
             PipeArray(j, 2) = WPipe.InnerDiameterOrWidth * 12
             PipeArray(j, 3) = WPipe.StartStructure.Name
             PipeArray(j, 4) = WPipe.EndStructure.Name
             PipeArray(j, 5) = WPipe.StartPoint.Z - (WPipe.InnerDiameterOrWidth / 2)
             PipeArray(j, 6) = WPipe.EndPoint.Z - (WPipe.InnerDiameterOrWidth / 2)
             PipeArray(j, 7) = WPipe.Length2D
             PipeArray(j, 8) = WPipe.Length2D - WPipe.StartStructure.StructureInnerDiameterOrWidth / 2 - WPipe.EndStructure.StructureInnerDiameterOrWidth / 2
             
        Next j



        For w = 0 To StrucLim

             Set Wstruc = WStructures.Item(w)
             Set Align = Wstruc.Alignment
             WStrucX = Wstruc.Position.X
             WStrucY = Wstruc.Position.y
             'Set stn, offset = Align.StationOffset(WstrucX,WStrucY,stn,offset)



             StrucArray(w, 0) = Wstruc.Name
             StrucArray(w, 1) = Wstruc.Style.Name
             'StrucArray(w, 2) = stn
             'StrucArray(w, 3) = offset
             StrucArray(w, 4) = WStrucY
             StrucArray(w, 5) = WStrucX
             StrucArray(w, 6) = Wstruc.RimElevation
        
        Next w


Sheet1.Range("A1:G400").Value = StrucArray
Sheet1.Range("M1:U400").Value = PipeArray


End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 15:26:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9340391#M8699</guid>
      <dc:creator>csandersonGKMZ9</dc:creator>
      <dc:date>2020-02-25T15:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: Alignment.StationOffset() Function in Excel VBA</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9340420#M8700</link>
      <description>&lt;P&gt;In your Excel VBA editor, have you added references to necessary Civil3D COM libraries (AeccXLandLib/AeccXUiLandLib, ... )? If you did, you should have been able to see in Object Browser, like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Civil3D References in Excel VBA.png" style="width: 603px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/733948i480E0F90DD3CD84A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Civil3D References in Excel VBA.png" alt="Civil3D References in Excel VBA.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 15:30:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9340420#M8700</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2020-02-25T15:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: Alignment.StationOffset() Function in Excel VBA</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9340493#M8701</link>
      <description>&lt;P&gt;I have them referenced, the error that pops up when I try to run the function is "Compile Error: Expected function or variable". This is making me think its a difference in the syntax between the VBA in excel and Autocad. The StationOffset function gives two outputs and I'm not sure how to set two variable values at once in the Excel VBA.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 16:00:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9340493#M8701</guid>
      <dc:creator>csandersonGKMZ9</dc:creator>
      <dc:date>2020-02-25T16:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Alignment.StationOffset() Function in Excel VBA</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9340685#M8702</link>
      <description>&lt;P&gt;If you ZIP up a file you should be able to post the ZIP file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm assuming this is the line giving you problems:&lt;/P&gt;
&lt;PRE&gt;'Set stn, offset = Align.StationOffset(WstrucX,WStrucY,stn,offset)&lt;/PRE&gt;
&lt;P&gt;This should work:&lt;/P&gt;
&lt;PRE&gt;Dim stn As double
Dim offset As Double
Align.StationOffset(WstrucX,WStrucY,stn,offset)&lt;/PRE&gt;
&lt;P&gt;Then the 2 variables will contain the values obtained from the alignment.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 17:25:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9340685#M8702</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2020-02-25T17:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Alignment.StationOffset() Function in Excel VBA</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9340717#M8703</link>
      <description>&lt;P&gt;I tried that solution and get a Syntax Error when I try to compile.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I attached the zip file below, there might just be a simple syntax fix that I am missing but I haven't been able to assign both variables values at once.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 17:45:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9340717#M8703</guid>
      <dc:creator>csandersonGKMZ9</dc:creator>
      <dc:date>2020-02-25T17:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Alignment.StationOffset() Function in Excel VBA</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9340727#M8704</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/32637"&gt;@Jeff_M&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;If you ZIP up a file you should be able to post the ZIP file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm assuming this is the line giving you problems:&lt;/P&gt;
&lt;PRE&gt;'Set stn, offset = Align.StationOffset(WstrucX,WStrucY,stn,offset)&lt;/PRE&gt;
&lt;P&gt;This should work:&lt;/P&gt;
&lt;PRE&gt;Dim stn As double
Dim offset As Double
&lt;FONT color="#FF0000"&gt;Align.StationOffset(WstrucX,WStrucY,stn,offset)&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Then the 2 variables will contain the values obtained from the alignment.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The red line should be (no bracket, we have left VBA long enough to be not used to that kind of strange syntax):&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#0000FF"&gt;Align.StationOffset WstrucX, WStrucY, stn, offset&lt;/FONT&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 17:49:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9340727#M8704</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2020-02-25T17:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: Alignment.StationOffset() Function in Excel VBA</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9340737#M8705</link>
      <description>&lt;P&gt;That worked perfectly, thank you both for your help&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 17:55:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/alignment-stationoffset-function-in-excel-vba/m-p/9340737#M8705</guid>
      <dc:creator>csandersonGKMZ9</dc:creator>
      <dc:date>2020-02-25T17:55:09Z</dc:date>
    </item>
  </channel>
</rss>

