Results 1 to 8 of 8

Thread: AutoCAD crashes on plot in an event initialized mode

  1. #1
    Member
    Join Date
    2008-03
    Location
    Muscat
    Posts
    14
    Login to Give a bone
    0

    Default AutoCAD crashes on plot in an event initialized mode

    I have a .net assembly that deals with the events (open,save) and writes some info into an access database. I have used a command initializer (command "initevent") in my acad.lsp file.
    Event procedures are working fine.
    But when I plot the drawing, AutoCAD crashes down.
    I tried to remove the (command "initevent") from my acad.lsp and my plotting working fine as usual.
    Any help on this is appreciated in advance.
    Version - AutoCAD-2012

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: AutoCAD crashes on plot in an event initialized mode

    Post your code.
    Last edited by BlackBox; 2013-03-11 at 12:59 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: AutoCAD crashes on plot in an event initialized mode

    Quickly written example:

    Code:
    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.EditorInput;
    using Autodesk.AutoCAD.Runtime;
    
    using acApp = Autodesk.AutoCAD.ApplicationServices.Application;
    
    [assembly: ExtensionApplication(typeof(Augi.Sample.Events.Save))]
    
    namespace Augi.Sample.Events
    {
        public class Save : IExtensionApplication
        {
            public void Initialize()
            {
                DocumentCollection acDocs = acApp.DocumentManager;
                Document doc = acDocs.MdiActiveDocument;
                Editor ed = doc.Editor;
    
                acDocs.DocumentCreated += OnDocumentCreated;
    
                doc.CommandWillStart += OnCommandWillStart;
            }
    
            public void Terminate()
            {
            }
    
            public void BowtiesAreCool(Document doc) //<-- Change this to something useful
            {
                doc.Editor.WriteMessage("\n** Bowties are cool ** \n");
            }
    
            void OnCommandWillStart(object sender, CommandEventArgs e)
            {
                string cmd = e.GlobalCommandName.ToUpper();
    
                if (cmd.Contains("SAVE") || cmd.Contains("OPEN"))
                    BowtiesAreCool((Document)sender); //<-- Change this to something useful
            }
    
            void OnDocumentCreated(object sender, DocumentCollectionEventArgs e)
            {
                if (e.Document != null)
                    e.Document.CommandWillStart += OnCommandWillStart;
            }
        }
    }
    Last edited by BlackBox; 2013-03-11 at 01:07 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  4. #4
    Member
    Join Date
    2008-03
    Location
    Muscat
    Posts
    14
    Login to Give a bone
    0

    Default Re: AutoCAD crashes on plot in an event initialized mode

    Quote Originally Posted by BlackBox View Post
    Post your code.
    Here is the code:
    Code:
    Imports Microsoft.Office.Interop
    Imports System.Data.OleDb
    Imports Autodesk.AutoCAD.Interop
    Imports Autodesk.AutoCAD.Interop.Common
    Imports PDOUTIL.PDOUT
    Imports System.Windows.Forms
    
    Public Class dbConn
        Public Shared ReadOnly Property ThisDrg() As AcadDocument
            Get
                Return Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument
            End Get
        End Property
    
        <Autodesk.AutoCAD.Runtime.CommandMethod("InitEvent", Autodesk.AutoCAD.Runtime.CommandFlags.Session)> _
    Public Sub InitEvent()
            'acApp = ThisDrg.Application
            acApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication
            'acDoc = ThisDrg.Application.ActiveDocument
            acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument
        End Sub
    acad.lsp contains the following code to initialize on startup
    Code:
    (command "initevent")

  5. #5
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: AutoCAD crashes on plot in an event initialized mode

    I would suggest creating a module with a public global boolean variable that is set to true when the events are initialized. like

    Code:
    blnGlobalEventsInitialized
    Then make sure your code doesn't try to rerun the initialization by checking that variable

    Code:
    if not blnGlobalEventsinitialized then
          '' ...initialization code here....
    End if
    Worth a shot

    P=
    Last edited by BlackBox; 2013-03-12 at 08:33 PM.
    AutomateCAD

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: AutoCAD crashes on plot in an event initialized mode

    Quote Originally Posted by peter View Post
    I would suggest creating a module with a public global boolean variable that is set to true when the events are initialized. like

    blnGlobalEventsInitialized

    Then make sure your code doesn't try to rerun the initialization by checking that variable

    if not blnGlobalEventsinitialized then
    ...initialization code here....
    End if

    Worth a shot

    P=
    I've only ever needed a 'Loaded' Property when dealing with per-Document data management... Given that (as I understand it) the OP's intent is Event-driven reading/writing some Document data to/from an external Access database... I wouldn't think that to be required here.


    Quote Originally Posted by habeebpm View Post
    Here is the code:
    Code:
    Imports Microsoft.Office.Interop
    Imports System.Data.OleDb
    Imports Autodesk.AutoCAD.Interop
    Imports Autodesk.AutoCAD.Interop.Common
    Imports PDOUTIL.PDOUT
    Imports System.Windows.Forms
    
    Public Class dbConn
        Public Shared ReadOnly Property ThisDrg() As AcadDocument
            Get
                Return Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument
            End Get
        End Property
    
        <Autodesk.AutoCAD.Runtime.CommandMethod("InitEvent", Autodesk.AutoCAD.Runtime.CommandFlags.Session)> _
    Public Sub InitEvent()
            'acApp = ThisDrg.Application
            acApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication
            'acDoc = ThisDrg.Application.ActiveDocument
            acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument
        End Sub
    acad.lsp contains the following code to initialize on startup
    Code:
    (command "initevent")
    The code you posted is incomplete (it doesn't do anything).

    You can use the Imports (using in C#) directive in order to enable Type names to be referenced without Namespace qualification.

    Further, there's no need to use Acad.lsp to invoke your CommandMethod Method at all... Simply implement IExtensionApplication.Initialize() to call your CommandMethod Method asynchronously via SendStringToExecute().



    P.S. - Don't forget your CommandClass, and ExtensionApplication attributes.
    Last edited by BlackBox; 2013-03-12 at 08:34 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  7. #7
    Member
    Join Date
    2008-03
    Location
    Muscat
    Posts
    14
    Login to Give a bone
    0

    Default Re: AutoCAD crashes on plot in an event initialized mode

    BB,
    Thanks a lot for your guidance.
    Being a newbie.net, I haven't got much exposure to the implementation of methods such as IExtensionAplication.Initialize(). Now is the time, I believe that I am crawling towards the right direction.
    But still, my problem stays behind.
    btw. I could plot to a PDF/Image in the event initialized mode, but not to a paper. somehow weird? An Environmental barrier ?

  8. #8
    Member
    Join Date
    2008-03
    Location
    Muscat
    Posts
    14
    Login to Give a bone
    0

    Default Re: AutoCAD crashes on plot in an event initialized mode

    BB & Peter.
    Even if the problem persists, I wish to share an interesting case instance with you.
    In the event initialized AutoCAD instance, if I create a simple geometry(a line or circle) in the default blank drawing and plot the drawing, it is working fine and plots without trouble for all the other drawings.
    That is not the case when I open an existing drawing and try to plot (AutoCAD crashes down)

Similar Threads

  1. AutoCAD Raster Design is not initialized
    By danzashishimai in forum Raster Design - General
    Replies: 1
    Last Post: 2009-09-15, 12:57 PM
  2. .NET code crashes in debug mode, but works otherwise.
    By rkmcswain in forum Dot Net API
    Replies: 6
    Last Post: 2009-07-27, 12:34 PM
  3. AutoCAD crashes when trying to Plot a 3D Model
    By emodderman in forum AutoCAD Plotting
    Replies: 11
    Last Post: 2007-06-07, 01:05 PM
  4. AutoCAD 2007 crashes when I try to plot to my Lexmark z22
    By dkowis1 in forum AutoCAD Plotting
    Replies: 9
    Last Post: 2007-04-17, 12:52 AM
  5. AutoCAD Map 2000 message - Object not initialized
    By m.storey in forum AutoCAD Map 3D - General
    Replies: 3
    Last Post: 2006-06-30, 03:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •