-IMAGE DETACH * command crashing AutoCAD when not interactive

nsandersonMKCFD
Contributor

-IMAGE DETACH * command crashing AutoCAD when not interactive

nsandersonMKCFD
Contributor
Contributor

Hello,

 

We've recently introduced a piece of code to clear and regenerate (from a SQL database) a set of images from an AutoCAD drawing. 

Due to the XREFs being duplicated when we do this, we've found the only way to do this is fire a command at AutoCAD. The command is 

    thisdrawing.SendCommand("-IMAGE DETACH *" & vbCr)

When the user is interacting with AutoCAD and launches the routine to create a drawing from the database, all works OK and the command runs without issue and the old XREFs are cleared successfully.

 

The problem arises when we're running it in our batch processing application which launches AutoCAD, rebuilds the drawing from the database (running exactly the same code as in interactive) and then shuts down AutoCAD.  In that mode, this command causes AutoCAD to freeze and ultimately crash out.

 

I was therefore wondering if anyone had seen anything similar?  If so, is there a straightforward fix to sort it or is there a method we can call instead of firing the command at AutoCAD?

 

Any help or advice, greatly appreciated!

 

Many thanks,

 

Neil

 

0 Likes
Reply
Accepted solutions (1)
468 Views
6 Replies
Replies (6)

_gile
Consultant
Consultant

Hi,

It looks like you're using VBA:


@nsandersonMKCFD wrote:

[...] The command is 

    thisdrawing.SendCommand("-IMAGE DETACH *" & vbCr)


This forum is related to .NET, you should post in the VBA forum.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes

nsandersonMKCFD
Contributor
Contributor

Hi Gilles,

 

No, we're using VB.NET with .NET Framework 4.8.  The SendCommand method is supported in .NET (or appears to be?  Maybe this is the problem?)

0 Likes

_gile
Consultant
Consultant
Accepted solution

While you're using the .NET API, what about simply erase the concerned RasterImageDef?

private static void DetachImage(Database db, string imageName)
{
    using (var tr = db.TransactionManager.StartTransaction())
    {
        var nod = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
        var imageDict = (DBDictionary)tr.GetObject(nod.GetAt("ACAD_IMAGE_DICT"), OpenMode.ForRead);
        if (imageDict.Contains(imageName))
        {
            var imageDef = (RasterImageDef)tr.GetObject(imageDict.GetAt(imageName), OpenMode.ForWrite);
            imageDef.Erase();
        }
        tr.Commit();
    }
}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

kerry_w_brown
Advisor
Advisor

@nsandersonMKCFD wrote:

Hi Gilles,

 

No, we're using VB.NET with .NET Framework 4.8.  The SendCommand method is supported in .NET (or appears to be?  Maybe this is the problem?)


If that is the case, why did you post the same question in the VBA forum shortly after this response. ?

 

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12

class keyThumper<T> : Lazy<T>;      another  Swamper

0 Likes

ActivistInvestor
Advisor
Advisor

You may be using vb.net but you are not using the managed .NET api. There is no SendCommand() method in the .NET api.

 

You are using the ActiveX API which is what is used from the VBA.

nsandersonMKCFD
Contributor
Contributor

Yes, sorry!  I am trying to maintain some VB.NET code that I've 'inherited' and assumed they were using the .NET API but it turns out that it's some older code that has references to the ActiveX API.

 

As Gilles said, I might be better off posting this in the VBA forums in case anyone has seen anything similar with the Active X implementation.

@_gile Thanks you for the .NET reference - I'll look into that and see if it solves the problem

0 Likes