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

Model Space Tiled Viewports

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
mbujak
1674 Views, 5 Replies

Model Space Tiled Viewports

When a new document is created I want to set the model space to have tiled viewports. This can be done within autocad using the view/viewports/new viewports menu option. How do I do this using the API?

 

Any suggestions or pointers to documentation?

 

Mike B

5 REPLIES 5
Message 2 of 6
khoa.ho
in reply to: mbujak

The link from AutoCAD .NET Developer's Guide helps to create 2 horizontal model viewports. The main point is that model viewport comes from database.ViewportTableId. We need to create a new ViewportTableRecord with defined LowerLeftCorner and UpperRightCorner properties, and then add it to the Viewport Table.

 

You should assign the name of a new created viewport as "*Active". Otherwise, AutoCAD will not show correctly.

 

I rewrote the code to be more basic and simpler, to create two vertical tiled viewports:

 

[CommandMethod("CreateModelViewports")]
public static void CreateModelViewports()
{
	Document doc = Application.DocumentManager.MdiActiveDocument;
	Database db = doc.Database;
	using (Transaction trans = db.TransactionManager.StartTransaction())
	{
		var viewportTable = (ViewportTable)trans.GetObject(db.ViewportTableId, OpenMode.ForWrite);
		foreach (ObjectId id in viewportTable)
		{
			var viewport = (ViewportTableRecord)trans.GetObject(id, OpenMode.ForRead);
			// Delete the active viewport
			if (viewport.Name == "*Active")
			{
				viewport.UpgradeOpen();
				viewport.Erase();
			}
		}
// Create a left viewport var vport = new ViewportTableRecord { Name = "*Active", LowerLeftCorner = new Point2d(0, 0), UpperRightCorner = new Point2d(0.5, 1), }; viewportTable.Add(vport); trans.AddNewlyCreatedDBObject(vport, true);
// Create a right viewport vport = new ViewportTableRecord { Name = "*Active", LowerLeftCorner = new Point2d(0.5, 0), UpperRightCorner = new Point2d(1, 1), }; viewportTable.Add(vport); trans.AddNewlyCreatedDBObject(vport, true); viewportTable.DowngradeOpen(); // Update the display with the new tiled viewports arrangement doc.Editor.UpdateTiledViewportsFromDatabase(); trans.Commit(); } }

 

-Khoa

Message 3 of 6
mbujak
in reply to: khoa.ho

Yeah, I actually stumbled upon that document before and after I posted. The problem was before, the introduction and the title made me believe that it related to making a viewport active, not actually creating the tiled view. Shame on me for not reading the entire document before posting Smiley Embarassed. Anyway, after I posted I revisited the document and realized what it was.

 

There seems to be something bugging me though. If you have to call all the new viewports "*Active", how do you refer to them by name in code? Is there a way to identify each viewport? I guess I could save a collection of their ObjectId's in an object that contains my own name.

 

Thanks for the reply.

 

- Mike

Message 4 of 6
khoa.ho
in reply to: mbujak

Hi Mike,

 

After reading the Autodesk's document, I saw there is no reason to clone new created viewports and then use those cloned objects as active and left the original new viewports unused on the ViewportTable. So I rewrote the code to be simpler and shorter.

 

The viewport name in fact is the GROUP NAME of a group of viewports that show together on AutoCAD screen. This name presents the status of viewport, not for individual identification. You can assign new viewports with any name (not just only *Active) and see those names in the Named Viewports tab of Viewports dialog (VPORTS command on AutoCAD).

 

However, there should be at least a viewport named *Active, and this viewport will be active to accept user input. Without any viewport with the name *Active, AutoCAD will hang up the screen.

 

To identify each viewport, the obvious way is to store their ObjectIds to a collection to retrieve later. I can't find a property of ViewportTableRecord that indicates its viewport number (CVPORT variable).

 

-Khoa

Message 5 of 6
asim777
in reply to: mbujak

I am not able update the display of newly created viewport in AutoCAD 2006. 

UpdateTiledViewportsFromDatabase() is not available in AutoCAD 2006.

 

Please suggest.

 

Asim

Message 6 of 6
Alexander.Rivilis
in reply to: asim777

Oh! What a rarity!

Alternative method - P/Invoke acedVportTableRecords2Vports:

[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedVportTableRecords2Vports@@YA?AW4ErrorStatus@Acad@@XZ")]
public static extern int UpdateTiledViewportsFromDatabase();

 

 

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

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