.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adjust Snap and Grid alignment example code

3 REPLIES 3
Reply
Message 1 of 4
sriva041
665 Views, 3 Replies

Adjust Snap and Grid alignment example code

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
3 REPLIES 3
Message 2 of 4
norman.yuan
in reply to: sriva041

Editor.ActiveViewportId property is only available for Acad2009 or later, not for Acad2008 (even Acad2007/8/9 are the same major release R17.x). So, you are out of luck to run the code. I have checked this with my previously downloaded Acad2008/9's ObjectARX SDK documents.

The same is with your next question, I guess (but did not check with the ObjectARS SDK document)

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 4
Anonymous
in reply to: sriva041

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
Message 4 of 4
sriva041
in reply to: sriva041

That explains it!

Thanks!

I spent hours trying to get this work...

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost