AutoCAD 2025 and Event Handlers

AutoCAD 2025 and Event Handlers

GeeHaa
Collaborator Collaborator
2,684 Views
8 Replies
Message 1 of 9

AutoCAD 2025 and Event Handlers

GeeHaa
Collaborator
Collaborator

Hi

 

I recently upgraded to AutoCAD 2025 and It keeps Crashing on the insert of Blocks. I narrowed it down to my program that checks the Drawing number against the filename. I have it triggering on Database.saveComplete, Plotmanager.BeginPlot. Has anyone Else had a problem with event Handlers and AutoCAD 2025. It works fine in all Previous versions.

 

Thanks in Advance.

0 Likes
2,685 Views
8 Replies
Replies (8)
Message 2 of 9

ActivistInvestor
Mentor
Mentor

@GeeHaa wrote:

Hi

 

I have it triggering on Database.saveComplete, Plotmanager.BeginPlot. Has anyone Else had a problem with event Handlers and AutoCAD 2025. It works fine in all Previous versions.

 


What is triggering?  An exception? What's the exception. Have you run the code in the debugger to find out what line of code is triggering the exception?  Without seeing code, it's impossible for anyone to tell you what may be the problem.

0 Likes
Message 3 of 9

GeeHaa
Collaborator
Collaborator

Hi,

Thanks for the response.

My debugger won't start AutoCAD 2025 the splash screen appears then I get an 0x8000ffff error. and it stops loading.

Below is the code for the event handlers.

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.LayerManager
Imports Autodesk.AutoCAD.Windows
Imports System.IO
Imports Autodesk.AutoCAD.PlottingServices
<Assembly: ExtensionApplication(GetType(vbcadTemplateClass))>
Module GLOBALVARIABLES
    Public Project As String = "Y"
    Public DWG As String = "Y"
    Public Lay As String = "Y"
    Public layMessage As String = ""
End Module
Public Class vbcadTemplateClass
    Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
    Private MYPlotManager As PlotReactorManager
    Private dcMan As DocumentCollection
    Private Sub BeginPlot(ByVal sender As Object, ByVal e As 
        Autodesk.AutoCAD.PlottingServices.BeginPlotEventArgs)
        readum()
        CheckDrawingNumber()
    End Sub
    Private Sub EndPlot(ByVal sender As Object, ByVal e As 
Autodesk.AutoCAD.PlottingServices.EndPlotEventArgs)
        Dim myDwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = myDwg.Editor
        ed.WriteMessage(layMessage)
    End Sub
    Public Sub initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
        dcMan = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
        AddHandler dcMan.DocumentCreated, AddressOf CallBack_DocCreated
        Dim mydoc As Document
        For Each mydoc In dcMan
            Dim db As Database = mydoc.Database
            AddHandler db.SaveComplete, AddressOf callBack_EndSave
        Next
        MYPlotManager = New PlotReactorManager
        AddHandler MYPlotManager.BeginPlot, AddressOf BeginPlot
        AddHandler MYPlotManager.EndPlot, AddressOf EndPlot
    End Sub
    Public Sub CallBack_DocCreated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
        If e.Document = Nothing Then
            Exit Sub
        End If
        Dim db As Database = e.Document.Database
        AddHandler db.SaveComplete, AddressOf callBack_EndSave
    End Sub
    Private Sub callBack_EndSave(ByVal sender As Object, ByVal e As DatabaseIOEventArgs)
        Dim myDwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        readum()

        CheckDrawingNumber()

    End Sub
Public Sub terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
        RemoveHandler dcMan.DocumentCreated, AddressOf CallBack_DocCreated
        RemoveHandler MYPlotManager.BeginPlot, AddressOf BeginPlot
        RemoveHandler MYPlotManager.EndPlot, AddressOf EndPlot
    End Sub

 

0 Likes
Message 4 of 9

Norman_Yuan
Mentor
Mentor

Your existing code based .NET Framework (for AutoCAD 2024 or older) CANNOT BE debugged against AutoCAD2025. You must migrate the code project to use .NET 8 in order to debug in AutoCAD 2025 (then the compiled code will not work with AutoCAD 2024 or older).

 

If looks like your code in callBack_EndSave(), which you did not show, nor explain what it does, maybe the cause of the exception (i.e. the code somehow is not compatible with .NET 8).

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 5 of 9

GeeHaa
Collaborator
Collaborator

Hi Norman,

 

Thanks for the reply. The code in question just checks the drawing number attribute in the title block against a parsed drawing number found in the file name. This part actually works. it asks to change the drawing number if it doesn't match. or does nothing if it matches. The only problem is when these event handlers are running. Inserting any block manually causes AutoCAD to display a window that says AutoCAD will close and asked to send a report. It doesn't actually Close though. I will migrate the code to use .net 8. and let you know how it goes. Thanks again.

0 Likes
Message 6 of 9

GeeHaa
Collaborator
Collaborator

Hi

 

I was able to migrate my code to  .net 8 according to Giles Guide without errors but trying to run the debugger I get this error

GeeHaa_0-1714080968542.png

Does anyone know what's causing this error?   I'm using VS Community 2022. and VB.net. The migrated code runs in AutoCAD 2025 without error. I just need to get the Debugger working.

 

Thanks.

 

0 Likes
Message 7 of 9

GeeHaa
Collaborator
Collaborator

I think the problem with the program crashing AutoCAD 2025 was, I was calling the CheckDrawing number routine directly after loading it with ACADDOC.lsp file. I moved the call to the DocumentManager.DocumentCreated event which fires when the drawing opens and AutoCAD stopped crashing on Insertion of Objects.

I found this if I hit ctrl+alt+P. Was hoping it would help with the above Managed coreCLR error.

GeeHaa_0-1715271385283.png

I hit select and added Managed .net Core and Native code. And the debugger still gives the same error.

 

This is my .vbproj file. Contents

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <OutputType>Library</OutputType>
    <RootNamespace>Check_Drawing_Number</RootNamespace>
    <MyType>WindowsFormsWithCustomSubMain</MyType>
    <IsWebBootstrapper>false</IsWebBootstrapper>
    <PublishUrl>publish\</PublishUrl>
    <Install>true</Install>
    <InstallFrom>Disk</InstallFrom>
    <UpdateEnabled>false</UpdateEnabled>
    <UpdateMode>Foreground</UpdateMode>
    <UpdateInterval>7</UpdateInterval>
    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
    <UpdatePeriodically>false</UpdatePeriodically>
    <UpdateRequired>false</UpdateRequired>
    <MapFileExtensions>true</MapFileExtensions>
    <ApplicationRevision>0</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
    <UseApplicationTrust>false</UseApplicationTrust>
    <BootstrapperEnabled>true</BootstrapperEnabled>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <UseWindowsForms>true</UseWindowsForms>
    <ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
    <Copyright>Copyright © </Copyright>
    <AssemblyVersion>1.0.0.0</AssemblyVersion>
    <FileVersion>1.0.0.0</FileVersion>
    <StartupObject>Check_Drawing_Number.</StartupObject>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
  </ItemGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DocumentationFile>Check-Drawing-Number.xml</DocumentationFile>
    <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022,42353,42354,42355</NoWarn>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DefineDebug>false</DefineDebug>
    <DocumentationFile>Check-Drawing-Number.xml</DocumentationFile>
    <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022,42353,42354,42355</NoWarn>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="AcCoreMgd, Version=19.0.0.0, Culture=neutral, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>C:\ObjectARX 2025\inc\AcCoreMgd.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="AcDbMgd">
      <HintPath>C:\ObjectARX 2025\inc\AcDbMgd.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="AcMgd">
      <HintPath>C:\ObjectARX 2025\inc\AcMgd.dll</HintPath>
      <Private>False</Private>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <Compile Update="ConfigForm.Designer.vb">
      <DependentUpon>ConfigForm.vb</DependentUpon>
    </Compile>
    <Compile Update="My Project\Application.Designer.vb">
      <AutoGen>True</AutoGen>
      <DependentUpon>Application.myapp</DependentUpon>
      <DesignTime>True</DesignTime>
    </Compile>
    <Compile Update="My Project\Resources.Designer.vb">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
    <Compile Update="My Project\Settings.Designer.vb">
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
    </Compile>
    <Compile Update="OnDrawingCheck.Designer.vb">
      <DependentUpon>OnDrawingCheck.vb</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <None Update="My Project\Application.myapp">
      <Generator>MyApplicationCodeGenerator</Generator>
      <LastGenOutput>Application.Designer.vb</LastGenOutput>
    </None>
    <None Update="My Project\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
    </None>
  </ItemGroup>
  <ItemGroup>
    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
      <Visible>False</Visible>
      <ProductName>.NET Framework 2.0 %28x86%29</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.0 %28x86%29</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
      <Visible>False</Visible>
      <ProductName>Windows Installer 3.1</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
  
  </ItemGroup>
</Project>

 

Any help would be much appreciated. 

0 Likes
Message 8 of 9

_gile
Consultant
Consultant

Hi,

Did you try correcting this line (actual AcCoreMgd 2025 version is 25.0.58.0.0):

<Reference Include="AcCoreMgd, Version=19.0.0.0, Culture=neutral, processorArchitecture=MSIL">

 and removing all reference to .NET Framework:

<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
      <Visible>False</Visible>
      <ProductName>.NET Framework 2.0 %28x86%29</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.0 %28x86%29</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 9

GeeHaa
Collaborator
Collaborator

Thanks for the response. I changed the version to 25.0.58.0.0 and removed all references to the .Net Framework and it still shows the same message when I hit start debug.

 

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <OutputType>Library</OutputType>
    <RootNamespace>Check_Drawing_Number</RootNamespace>
    <MyType>WindowsFormsWithCustomSubMain</MyType>
    <IsWebBootstrapper>false</IsWebBootstrapper>
    <PublishUrl>publish\</PublishUrl>
    <Install>true</Install>
    <InstallFrom>Disk</InstallFrom>
    <UpdateEnabled>false</UpdateEnabled>
    <UpdateMode>Foreground</UpdateMode>
    <UpdateInterval>7</UpdateInterval>
    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
    <UpdatePeriodically>false</UpdatePeriodically>
    <UpdateRequired>false</UpdateRequired>
    <MapFileExtensions>true</MapFileExtensions>
    <ApplicationRevision>0</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
    <UseApplicationTrust>false</UseApplicationTrust>
    <BootstrapperEnabled>true</BootstrapperEnabled>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <UseWindowsForms>true</UseWindowsForms>
    <ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
    <Copyright>Copyright © </Copyright>
    <AssemblyVersion>1.0.0.0</AssemblyVersion>
    <FileVersion>1.0.0.0</FileVersion>
    <StartupObject>Check_Drawing_Number.</StartupObject>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
  </ItemGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DocumentationFile>Check-Drawing-Number.xml</DocumentationFile>
    <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022,42353,42354,42355</NoWarn>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DefineDebug>false</DefineDebug>
    <DocumentationFile>Check-Drawing-Number.xml</DocumentationFile>
    <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022,42353,42354,42355</NoWarn>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="AcCoreMgd, Version=25.0.58.0.0, Culture=neutral, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>C:\ObjectARX 2025\inc\AcCoreMgd.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="AcDbMgd">
      <HintPath>C:\ObjectARX 2025\inc\AcDbMgd.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="AcMgd">
      <HintPath>C:\ObjectARX 2025\inc\AcMgd.dll</HintPath>
      <Private>False</Private>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <Compile Update="ConfigForm.Designer.vb">
      <DependentUpon>ConfigForm.vb</DependentUpon>
    </Compile>
    <Compile Update="My Project\Application.Designer.vb">
      <AutoGen>True</AutoGen>
      <DependentUpon>Application.myapp</DependentUpon>
      <DesignTime>True</DesignTime>
    </Compile>
    <Compile Update="My Project\Resources.Designer.vb">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
    <Compile Update="My Project\Settings.Designer.vb">
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
    </Compile>
    <Compile Update="OnDrawingCheck.Designer.vb">
      <DependentUpon>OnDrawingCheck.vb</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <None Update="My Project\Application.myapp">
      <Generator>MyApplicationCodeGenerator</Generator>
      <LastGenOutput>Application.Designer.vb</LastGenOutput>
    </None>
    <None Update="My Project\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
    </None>
    </ItemGroup>
</Project>

 

 Thanks again.

0 Likes