I've now incorporated this along with
the rest of my routines.
But it's also become apparent that it's still often useful to use old-style Dimensions in Civil-3D. That means we still have some of the same problems as in Land Desktop.
So, in addition to changing PSLTSCALE and LTSCALE as the user switches between modelspace and paperspace, it also sets the DIMSCALE to the Drawing Scale in modelspace, and DIMSCALE=0 in paperspace. It also keeps the DIMSCALE set correctly when the user changes the DIMSTYLE in the dropdown box in the Styles toolbar.
(Note: DIMSCALE=0 is much like DIMSCALE=1, except dimensions also scale correctly when they are created in model space through a viewport located in paperspace. This makes DIMSCALE=0 a particularly useful setting in paperspace. If you are confused about how to define DIMSTYLES and use DIMSCALE, you may want to read
this explanation of how they work in Land Desktop. They work in much the same way in Civil-3D, except Civil-3D has Labels instead of Text Style Sets.)
This doesn't solve all problems in Civil-3D. Since it basically links the DIMSCALE to the DRAWING SCALE, you'll probably want to change DRAWING SCALE to match the viewport you are working on. However, this has the unintended side-effect of causing ALL labels in modelspace to change size. If you are creating labels that will be defined in viewports that are set to radically-different scales, this can be pretty annoying. It's possible that I should create some other variable entirely (possibly one that works much like a system variable), and use it instead of the main Drawing Scale. But this version works fairly well for now.
Here's the part of the C# code that works much like the Lisp in the above post:
/*
* Created by Richard Sincovec
* User: Sinc
* Date: 3/25/2007
* Time: 8:15 AM
*
*/
using System;
using ACAD = Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AECC.Interop.Land;
using Civil3DUtilities;
namespace Sincpac.Misc
{
/// <summary>
/// Contains generic reactor code. Currently, this only contains stuff that corrects
/// various problems with DIMSCALE, LTSCALE, etc. This command can be run from the
/// NETLOAD command while loading the DLL.
/// </summary>
public class Reactors
{
private static bool dimstyleChanged = false;
private static bool fixscalesEnabled = false;
public Reactors()
{
}
[CommandMethod("FIXSCALES")]
public void EnableFixscales()
{
if (!fixscalesEnabled) {
ACAD.Application.SystemVariableChanged += new ACAD.SystemVariableChangedEventHandler(SystemVariableChanged);
fixscalesEnabled = true;
}
}
[CommandMethod("UNFIXSCALES")]
public void DisableFixscales()
{
if (fixscalesEnabled) {
ACAD.Application.SystemVariableChanged -= new ACAD.SystemVariableChangedEventHandler(SystemVariableChanged);
fixscalesEnabled = false;
}
}
public void SystemVariableChanged(object o, ACAD.SystemVariableChangedEventArgs e)
{
try {
// Editor ed = ACAD.Application.DocumentManager.MdiActiveDocument.Editor;
// ed.WriteMessage("\nSystem Variable changed: {0}", e.Name);
if (e.Name.Equals("TILEMODE")) {
// user changed from paperspace to modelspace or vice-versa
Database db = ACAD.Application.DocumentManager.MdiActiveDocument.Database;
if (db.TileMode == false) {
// Paperspace
db.Dimscale = 0;
db.Ltscale = 1;
db.Psltscale = true;
} else {
// Modelspace
C3DUtil c3dUtil = new C3DUtil();
double drScale = c3dUtil.AeccDb.Settings.DrawingSettings.UnitZoneSettings.DrawingScale;
db.Dimscale = drScale;
db.Ltscale = drScale;
db.Psltscale = false;
}
}
// Fix DIMSCALE. This is a bit convoluted, but I had to do this to make it work.
// Basically, after the DIMSTYLE is changed, Autocad will attempt to reset DIMSCALE to 1.
// But it does this *after* changing the DIMSTYLE, and if the DIMSCALE is already 1, then
// it does nothing. So, in order to get a consistent response from Autocad, we first set
// the DIMSCALE to what we want. Autocad will then reset it to 1, at which time we again
// set the DIMSCALE to what we want. This time it will stay. We use the "dimstyleChanged"
// static variable to keep track of what's going on, since this event handler ends up
// being called multiple times. End result is that DIMSCALE = DRAWING SCALE in modelspace,
// and DIMSCALE = 0 in paperspace.
if (e.Name.Equals("DIMSTYLE")) {
// this part gets run after user sets new DIMSTYLE
changeScales();
dimstyleChanged = true;
}
if (dimstyleChanged && e.Name.Equals("DIMSCALE")) {
// after Autocad resets the DIMSCALE back to 1, this part gets run
dimstyleChanged = false;
changeScales();
}
}
catch {}
}
private void changeScales()
{
Database db = ACAD.Application.DocumentManager.MdiActiveDocument.Database;
if (db.TileMode == false) {
// Paperspace
db.Dimscale = 0;
} else {
// Modelspace
C3DUtil c3dUtil = new C3DUtil();
double drScale = c3dUtil.AeccDb.Settings.DrawingSettings.UnitZoneSettings.DrawingScale;
db.Dimscale = drScale;
}
}
}
}