The global function acedActiveViewportId() returns an object ID based on the tile mode. The type of the object referred to by this object ID can be determined by calling AcDbDatabase::tilemode(). The currently active viewport is an object of type AcDbViewportTableRecord in model space (tilemode() returns true), while in paper space it is an object of type AcDbViewport.
The object ID of the active viewport in paper space is returned by the global function acedGetCurViewportObjectId().
Use the CVPORT system variable to get the viewport number of the currently active viewport. Each viewport is assigned a unique number. The global function acedVports() can be used to acquire the current model space configuration and viewport numbers. The viewport number is useful when calling the global AcGs and AcEd functions used for manipulating the viewports and their configuration, as they generally take a viewport number as an argument.