vba code to vb.net

vba code to vb.net

David_Prontnicki
Collaborator Collaborator
923 Views
1 Reply
Message 1 of 2

vba code to vb.net

David_Prontnicki
Collaborator
Collaborator

Hi everyone,

 

As a learning exercise I am trying to convert a old vba program to vb.net. I am experienced in vb.net and AutoCAD but not with programing Autocad. Hence the learning exercise.

 

One issue I am having is converting:

 

Private Sub cmdCreateLayerReport_Click()

'connect or instantiate microsoft word
Set mobjWord = CreateObject("Word.Application")

'make microsoft word visible
mobjWord.Visible = True

'create a new document in microsoft word
Set mobjDoc = mobjWord.Documents.Add

'set header and footer and page layout
With mobjDoc

    ' set page layout to landscape
    .PageSetup.Orientation = wdOrientLandscape
    
    'set header (drawing path and name)
    .Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = "Layer Report for:  " & Application.Documents(cboDrawingName.Value).Path & "\ " & Application.Documents(cboDrawingName.Value).Name
    
    'set footer (date created and total layer count)
    .Sections(1).Footers(wdHeaderFooterPrimary).Range.Text = "Date Created: " & Date & vbTab & "Total # of Layers: " & Application.Documents(cboDrawingName.Value).Layers.Count
    
    'set page numbers
    .Sections(1).Footers(wdHeaderFooterPrimary).PageNumbers.Add wdAlignPageNumberRight

End With

 

 

 

I have converted everything up to the point of:

 

 

.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text = "Date Created: " & Date & vbTab & "Total # of Layers: " & Application.Documents(cboDrawingName.Value).Layers.Count

 

I cant figure out how to get the layer count to work. (I have adjusted the date)

 

Any help would be greatly appreciated. Please note that I am using Civil 3D 2016.

0 Likes
Accepted solutions (1)
924 Views
1 Reply
Reply (1)
Message 2 of 2

David_Prontnicki
Collaborator
Collaborator
Accepted solution
I figured it out. I needed to add addition references and Used the code below:

Dim AcadApp As Autodesk.AutoCAD.Interop.AcadApplication
Dim acadDoc As Autodesk.AutoCAD.Interop.AcadDocument
Dim layercount As Integer

AcadApp = GetObject(, "AutoCAD.Application")
acadDoc = AcadApp.ActiveDocument
layercount = acadDoc.Layers.Count

then modified it for the combobox
0 Likes