Author Topic: Basics - Upgrading Updating old .Net code  (Read 1958 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Basics - Upgrading Updating old .Net code
« on: July 25, 2014, 11:53:15 AM »
I have found some Code that was written in 2011 format. I have version 2013 and 2014 that I am trying to learn how to update the code so that it would work with these versions.

Code: [Select]
Option Explicit On
Option Strict Off

'Namespace Imports

'.net imports for Windows operating system
Imports System.IO
Imports System.Windows.Forms

'.net imports for plain Autocad
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Colors

'.net imports for Civil3d
Imports Autodesk.Civil.ApplicationServices
Imports Autodesk.Civil.PipeNetwork.DatabaseServices.Styles
Imports Autodesk.Civil.PipeNetwork.DatabaseServices
Imports Autodesk.Civil.DatabaseServices

'Com Namespace Autocad
Imports Autodesk.AutoCAD.Interop.Common

'Com Namespace Imports for Civil3d
'Pipes
Imports Autodesk.AECC.Interop.UiPipe
Imports Autodesk.AECC.Interop.Pipe
'land
Imports Autodesk.AECC.Interop.UiLand
Imports Autodesk.AECC.Interop.Land

' The following statements declare constants.
'const HRESULT_ERROR as Integer = 0x80000000


Public Class GeneralNote

    ReadOnly Property Thisdrawing() As Autodesk.AutoCAD.Interop.AcadDocument
        Get
            Return Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument
        End Get
    End Property
    <Autodesk.AutoCAD.Runtime.CommandMethod("T2N")> _
Public Sub GeneralNote2()
        ' Write information about the selected pipe network to a
        ' spreadsheed in an instance of Excel.
        ''
        Dim objEnt As AcadEntity
        Dim varPick As Object
        Dim oSourceText As String = Nothing
        Dim oSourceTextStyle As String = Nothing
        Dim osourceObject As String = Nothing

        'Set variables to some value if just nothing to avoid the following build error

        '"Variable ???? is passed by reference before it has been assigned a value.
        'A null reference exception could result at runtime"

        objEnt = Nothing
        varPick = Nothing

        'Ask the user to pick the source mtext or text
        Try
            Thisdrawing.Utility.GetEntity(objEnt, varPick, vbCr & "Pick the source text/note")

        Catch COMex As Runtime.InteropServices.COMException
            'Do not done anything based on this error to do something
            'run with the next block of code uncommented and get the correct error code
            'and add to to the if statement

            'MessageBox.Show("Error " + COMex.ErrorCode.ToString() + ": " + COMex.Message)

            'If COMex.ErrorCode = -2147352567 Then  'HRESULT_ERROR
            '    MsgBox("Do something")
            'End If

        End Try

        If objEnt Is Nothing Then
            Thisdrawing.Utility.Prompt(vbCrLf & "You didn't pick anything. Stopping command try again")
            Exit Sub
        End If

        Dim oObjecttype As String
        oObjecttype = objEnt.ObjectName


        Select Case oObjecttype
            Case "AcDbText"
                'A text object is the source of the text
                Dim oTextobject As Autodesk.AutoCAD.Interop.Common.AcadText
                oTextobject = objEnt
                oSourceText = oTextobject.TextString


            Case "AcDbMText"
                'A mtext object is the source of the text
                Dim oTextobject As Autodesk.AutoCAD.Interop.Common.AcadMText
                oTextobject = objEnt
                oSourceText = oTextobject.TextString

            Case "AeccDbNoteLabel"
                Dim oTextobject As Autodesk.AECC.Interop.Land.AeccNoteLabel
                oTextobject = objEnt
                osourceObject = "AECCNOTE"
                oSourceText = oTextobject.LabelTextContent
                oSourceTextStyle = oTextobject.LabelStyle.Name

            Case Else
                MsgBox("Object selected is not an Mtext or Text object")
                Exit Sub
        End Select

        'Reset objEnt to be nothing
        objEnt = Nothing

        'Ask the user to pick the destination note
        Try
            Thisdrawing.Utility.GetEntity(objEnt, varPick, vbCr & "Pick the destination text/note")

        Catch COMex As Runtime.InteropServices.COMException
            'Do not done anything based on this error
        End Try

        If objEnt Is Nothing Then
            Thisdrawing.Utility.Prompt(vbCrLf & "You didn't pick anything. Stopping command try again")
            Exit Sub
        End If

        Dim oNote As Autodesk.AECC.Interop.Land.AeccNoteLabel

        oNote = objEnt

        'Ask the user if the want to update the note (style,text,both) to match the source object
        If osourceObject = "AECCNOTE" Then

            Thisdrawing.Utility.InitializeUserInput(1, "Style Text Both")
            Dim strInput As String = Nothing
            strInput = Thisdrawing.Utility.GetKeyword(vbCr & "Do you want to update the note [Style/Text/Both]")

            Select Case strInput
                Case "Style"
                    Dim oCurrentDestinationText As String = Nothing
                    oCurrentDestinationText = oNote.LabelTextContent
                    oNote.LabelStyle = oSourceTextStyle
                    oNote.LabelTextContent = oCurrentDestinationText

                Case "Text"
                    oNote.LabelTextContent = oSourceText
                Case "Both"
                    oNote.LabelStyle = oSourceTextStyle
                    oNote.LabelTextContent = oSourceText
                Case Else
                    Thisdrawing.Utility.Prompt(vbCrLf & "You didn't input a valid option")
                    Exit Sub
            End Select
        Else
            oNote.LabelTextContent = oSourceText

        End If
    End Sub
End Class

So I basically setup a new project in 2010 VBE. Pasted the Orignal VB code into MyCommands.vb. I generate 7 Errors.
Type 'Autodesk.AutoCAD.Interop.AcadDocument' is not defined.
'AcadDocument' is not a member of 'Autodesk.AutoCAD.ApplicationServices.Document'.
Type 'AcadEntity' is not defined.
Type 'Autodesk.AutoCAD.Interop.Common.AcadText' is not defined.
Type 'Autodesk.AutoCAD.Interop.Common.AcadMText' is not defined.
Reference required to assembly 'Autodesk.AEC.Interop.Base, Version=7.5.0.0, Culture=neutral, PublicKeyToken=null' containing the implemented interface 'Autodesk.AEC.Interop.Base.IAecEntity'.
Reference required to assembly 'Autodesk.AEC.Interop.Base, Version=7.5.0.0, Culture=neutral, PublicKeyToken=null' containing the implemented interface 'Autodesk.AEC.Interop.Base.IAecEntity'.

Under the Properties of the Project the references are pulling the correct info. Resources in Default with String1 and Settings is set at Setting String User.

Any guidance would be awesome. Thanks for your time too.





Civil3D 2020

huiz

  • Swamp Rat
  • Posts: 913
  • Certified Prof C3D
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.