PDA

View Full Version : Change Paperspace Background Color with .NET



thomas.bucher
2008-09-05, 08:35 AM
I try to migrate the following VBA program to .NET but witout success.

Could help me?


Public Sub DEU_MDCNE_SwapLayoutBackgrnd()

'Initialize
'----------------------------------------------------------------
Dim preferences As AcadPreferences
Dim currGraphicsWinLayoutBackgrndColor As OLE_COLOR
Dim StdGrey As OLE_COLOR

On Error GoTo Error

Set preferences = ThisDrawing.Application.preferences
StdGrey = 12632256

' Retrieve the current GraphicsWinLayoutBackgrndColor value
currGraphicsWinLayoutBackgrndColor = preferences.Display.GraphicsWinLayoutBackgrndColor

' Change the value for GraphicsWinLayoutBackgrndColor
If currGraphicsWinLayoutBackgrndColor <> vbWhite Then
preferences.Display.GraphicsWinLayoutBackgrndColor = vbWhite
Else: preferences.Display.GraphicsWinLayoutBackgrndColor = StdGrey
End If

Exit Sub

Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure 'DEU_MDCNE_SwapLayoutBackgrnd'"
End Sub


Moderator Note:

Please use [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code)

dmarcotte4
2008-09-09, 05:40 PM
Here is a sample in C#

Daniel




using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

// A reference to COM
using Autodesk.AutoCAD.Interop;
using AcAp = Autodesk.AutoCAD.ApplicationServices;


[assembly: CommandClass(typeof(ExecMethod.Commands))]

namespace ExecMethod
{
public class Commands
{
[CommandMethod("doit")]
public static void PaneButton()
{
Editor ed = AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
try
{
AcadPreferences pref = AcAp.Application.Preferences as AcadPreferences;
pref.Display.GraphicsWinLayoutBackgrndColor = 12632256;
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message);
}
}
}
}