I don't know who wrote or approved that sample, but
it shouldn't have been published, at least not without an
explaination of what it does and its limitations.
ActiveViewportId can return the ObjectId of either a
ViewportTableRecord, or a Viewport object, depending
on whether the model tab or a layout tab is active, so
that code will obviously fail if a layout tab is active.
You can use the Editor's CurrentViewportObjectId property
to get a Viewport object when a layout tab is active, or you
can look up and get the ViewportTableRecord whose name
is "*ACTIVE*" when the model tab is active.
Both Viewports and ViewportTableRecords support the same
set of properties manipluated by the code sample, but contrary
to what it seems to suggest, there is no simple way to manipulate
the properties of either of those types with the same code.
I don't know what release ActiveViewportId showed up in.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011
http://www.acadxtabs.com
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
wrote in message news:6401703@discussion.autodesk.com...
Hi everyone:
Here is the sample code from the Autocad.Net Dev guide
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
[CommandMethod("ChangeGridAndSnap")]
public static void ChangeGridAndSnap()
{
// Get the current database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the active viewport
ViewportTableRecord acVportTblRec;
acVportTblRec = acTrans.GetObject(acDoc.Editor.ActiveViewportId,
OpenMode.ForWrite) as
ViewportTableRecord;
// Turn on the grid for the active viewport
acVportTblRec.GridEnabled = true;
// Adjust the spacing of the grid to 1, 1
acVportTblRec.GridIncrements = new Point2d(1, 1);
// Turn on the snap mode for the active viewport
acVportTblRec.SnapEnabled = true;
// Adjust the snap spacing to 0.5, 0.5
acVportTblRec.SnapIncrements = new Point2d(0.5, 0.5);
// Change the snap base point to 1, 1
acVportTblRec.SnapBase = new Point2d(1, 1);
// Change the snap rotation angle to 30 degrees (0.524 radians)
acVportTblRec.SnapAngle = 0.524;
// Update the display of the tiled viewport
acDoc.Editor.UpdateTiledViewportsFromDatabase();
// Commit the changes and dispose of the transaction
acTrans.Commit();
}
}
Problem:
Editor.ActiveViewportId doesnt exist in the Editor (attribute/Property?)
I use AutoCAD 2008.
is it not there in AUtocad 2008? or do I need to include additional files ?
here is my Include list:
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.Colors;
Any help is greatly appreciated!
Thanks,
Rav