Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.11 KB | None | 0 0
  1.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  2.    
  3.    
  4.         Dim AcadApp As AcadApplication
  5.         Dim appver, appverc As Object
  6.        
  7.         'Getting Installed CAD Version through Registry
  8.         appver = TryCast(My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Autodesk\AutoCAD", "CurVer", Nothing), Object)
  9.         If appver Is Nothing Then
  10.             'MessageBox.Show("AutoCAD not installed !!")
  11.         else
  12.             appverc = appver.Substring(1, 2)
  13.         End If
  14.        
  15.        
  16.         'Start the proccess
  17.         'First Check if AutoCAD [acad.exe] is running
  18.            If IsProcessRunning("acad") Then
  19.             Try
  20.                 'Assign APP instances with installed version
  21.                 AcadApp = GetObject(, "AutoCAD.Application." + appverc.ToString())
  22.                 'Set Active
  23.                 AcadApp.Visible = True
  24.                 AcadApp.WindowState = AcWindowState.acMax
  25.                 SET_ACAD_Active()
  26.                 '''CODE TO SEND COMMANDS VIA CAD EDITOR
  27.                 ''  Dim AcDoc = AcadApp.ActiveDocument
  28.                 '' Dim command As String = "(alert ""x"" ) "
  29.                 '' AcDoc.SendCommand(command)
  30.                
  31.                 ''GET POINTS
  32.                 Dim start As Object
  33.                
  34.                 ''Using Editor ,get selected point's coordinates
  35.                 start = AcadApp.ActiveDocument.Utility.GetPoint(, "Select Point :")
  36.                
  37.                 ''PROCCESS
  38.                 ''
  39.                 ''
  40.                 ''
  41.                 ''
  42.  
  43.             Catch ex As Exception
  44.                 MessageBox.Show("ERROR IN PROCCESS  :: " + ex.ToString)
  45.  
  46.             End Try
  47.  
  48.         Else
  49.             MessageBox.Show("AutoCAD IS NOT RUNNING")
  50.  
  51.         End If
  52.     End Sub    
  53.        
  54.     Public Function IsProcessRunning(ByVal name As String) As Boolean
  55.         For Each clsProcess As Process In Process.GetProcesses()
  56.             If clsProcess.ProcessName.StartsWith(name) Then
  57.                 Return True
  58.             End If
  59.         Next
  60.         Return False
  61.     End Function
  62.    
  63.         Sub SET_ACAD_Active()
  64.         If IsProcessRunning("acad") Then
  65.             Dim App As Process() = Process.GetProcessesByName("acad")
  66.             If App.Length > 0 Then
  67.                 AppActivate(App(App.Length - 1).Id)
  68.             End If
  69.         End If
  70.  
  71.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement