Changing variables on side databases....getting repeatable crashes

Changing variables on side databases....getting repeatable crashes

JamesMaeding
Advisor Advisor
1,336 Views
5 Replies
Message 1 of 6

Changing variables on side databases....getting repeatable crashes

JamesMaeding
Advisor
Advisor

Hi All,

I want to set FRAME variable to 0 in many drawings because someone left imageframe to 1 in them.

This should be simple, but there is a catch where Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable operated on current database. I followed what Gile mentioned here: Code 

But am getting fatal errors on the second file every time. Here is my test code, any ideas?

[CommandMethod("TESTVARCHANGE")]
public void testVarChange() {
	List<string> files = new List<string>();
	files.Add(@"C:\Temp\Proxy Tests\SD-MWS4.dwg");
	files.Add(@"C:\Temp\Proxy Tests\PRF-BORREGO-SD5.dwg");
	files.Add(@"C:\Temp\Proxy Tests\ST-ADA.dwg");
	Database db = AcAp.DocumentManager.MdiActiveDocument.Database;
	foreach (string fullpath in files) {
		if (File.Exists(fullpath)) {
			using (Database tmpDb = new Database(false, true)) {
				try {
					tmpDb.ReadDwgFile(fullpath, FileOpenMode.OpenForReadAndAllShare, false, "");
					HostApplicationServices.WorkingDatabase = tmpDb;
					//set var
					Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("FRAME", 0);
					AcAp.SetSystemVariable("WIPEOUTFRAME", 1);
					AcAp.SetSystemVariable("IMAGEFRAME", 1);
					// Save always to current version
					tmpDb.SaveAs(fullpath, DwgVersion.Current);
					HostApplicationServices.WorkingDatabase = db;
				}
				catch (System.Exception ex) {
					Debug.Print(ex.Message);
				}
			}
		}
	}
}

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Accepted solutions (1)
1,337 Views
5 Replies
Replies (5)
Message 2 of 6

daniel_cadext
Advisor
Advisor

edit crashes for me too..

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 3 of 6

_gile
Consultant
Consultant
Accepted solution

Hi,

This seems to be due to the fact you set the FRAME system variable and then, the IMAGEFRAME and WIPEOUTFRAME.

Removing (or commenting) this line seems to fix the issue.

Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("FRAME", 0);


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 6

kerry_w_brown
Mentor
Mentor

@_gile wrote:

Hi,

This seems to be due to the fact you set the FRAME system variable and then, the IMAGEFRAME and WIPEOUTFRAME.

Removing (or commenting) this line seems to fix the issue.

Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("FRAME", 0);

Good pickup Gilles !

https://help.autodesk.com/view/ACD/2025/ENU/?guid=GUID-29BD70BB-07BF-41A2-8C2F-AD41C9402486

Note: You cannot set FRAME to a value of 3 manually. The setting for FRAME is restored to 3 only when one of the other object-specific frame settings is changed to a value that is different from the others.

// 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
Message 5 of 6

JamesMaeding
Advisor
Advisor

@_gile 

So I happen to have stumbled upon an odd case with frames and thought it was my database setting technique?

wow. I tested and you are right.

I saw in help about setting to 3. In my sample I just was trying a few different variables just to make sure I could do more than 1 at a time.

thanks as always, how you are not a 13 rank I'll never know...


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 6 of 6

JamesMaeding
Advisor
Advisor

@_gile 

I was wrong that the issue was only with FRAME var.

As I test more, I am seeing that even changing just WIPEOUTFRAME or IMAGEFRAME var to 1 or 0 will cause the crashes.

If the settings is already the same as what you are changing to, no crashes. That is what fooled me.

The best way to get the crashes reliably is change the setting back and forth right in a row, like:

AcAp.SetSystemVariable("WIPEOUTFRAME", 0);

AcAp.SetSystemVariable("WIPEOUTFRAME", 1);

 

On my tests, the first drawing seemed to tolerate that but second one crashed every time.

Note that if I am just changing things like LTSCALE, DIMSCALE there are never crashes.

So something about WIPEOUTFRAME and IMAGEFRAME, possibly XCLIPFRAME and others, are sensitive.

I noticed somewhere along the way I picked up code to change IMAGEFRAME in dictionary:

 

public static void SetImageFrame(AcDb.Database db, Transaction tr, int value) {
	DBDictionary theNOD = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
	RasterVariables rasterVars;

	string kImageVars = "ACAD_IMAGE_VARS";
	if (theNOD.Contains(kImageVars)) {
		ObjectId rastVarsId = theNOD.GetAt(kImageVars);
		rasterVars = (RasterVariables)tr.GetObject(rastVarsId, OpenMode.ForWrite);
	}
	//or create it
	else {
		rasterVars = new AcDb.RasterVariables();
		theNOD.UpgradeOpen();
		theNOD.SetAt(kImageVars, rasterVars);
		tr.AddNewlyCreatedDBObject(rasterVars, true);
	}
	if (value == 0)
		rasterVars.ImageFrame = FrameSetting.ImageFrameOff;
	else if (value == 1)
		rasterVars.ImageFrame = FrameSetting.ImageFrameAbove;
	else if (value == 2)
		rasterVars.ImageFrame = FrameSetting.ImageFrameOnNoPlot;
}

 

That never crashes.

This must be some kind of bug.

 

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes