Detecting all objects visible in each AcadPViewport (AutoCAD 2002; VB)

  • Thread starter Thread starter alexf2
  • Start date Start date
A

alexf2

Hi, All!

How can i detect which objects of "Model space" are shown in each AcadPViewport in "Paper space" layout consisting of multiple PViewports?



I am rendering layouts into TIFF-image (from VB OLE Automation controller) and want to store "Paper space" coordinates (bound box) of some objects residing in "Model space" (in order to highlight them on image in my application).

No problems if it is default layout showing "Model space" with VIEWPOINT 0,0,1. In this case i iterate through entire ModelSpace collection, finding my objects and translating bounding boxes WCS-->DCS-->PSDCS.

Problem happens if layout consists of many AcadPViewports and some AcadPViewports are specifically adjusted (has non default VIEWPOINT, excluded objects...). In this case i translating bounding boxes of objects from WCS to PSDCS and clipping invisible objects by means of each AcadPViewport:

a1 = .TranslateCoordinates(a1, acWorld, acDisplayDCS, False)
            a1 = .TranslateCoordinates(a1, acDisplayDCS, acPaperSpaceDCS, False)
            a2 = .TranslateCoordinates(a2, acWorld, acDisplayDCS, False)
            a2 = .TranslateCoordinates(a2, acDisplayDCS, acPaperSpaceDCS, False).

Resulting bounding boxes - are 2D "Paper space" projections of 3D objects from "Model space" and i can clip them by bounding boxes of PViewport object. Projections inside PViewport's bounding box are accepted. Outside projections are rejected and i trying to use the next PViewport for this object (switching ActivePViewport, setting MSpace = true and repeating TranslateCoordinates).

But i do not know which PViewport must been used for projection of each object and which objects are excluded.
 
I wrote a sub to draw a box in ms that represents the ps vp. You could modify that to get what you might consider the bounding box for ms.



 



 



Public Sub VPExtentsBox()
    'draws a box in MS representing the extents
    'of the current PS viewport
    Dim oPsVp As AcadPViewport
    Dim oBox As AcadLWPolyline
    Dim dPt1(0 To 2) As Double
    Dim dPt2(0 To 2) As Double
    Dim vCtrPt As Variant
    Dim vCtrPt1 As Variant
    Dim vMinPoint As Variant
    Dim vMaxPoint As Variant
    Dim BBpoints(0 To 9) As Double   'Bounding box points list
   
    If ThisDrawing.ActiveSpace = acPaperSpace Then 'first check for tilemode = 0
        If ThisDrawing.MSpace = True Then           'then make sure ms is active
            Set oPsVp = ThisDrawing.ActivePViewport
            vCtrPt = ThisDrawing.GetVariable("viewctr")
            Toolbox.ejmath.VPCoords oPsVp, vMinPoint, vMaxPoint
            BBpoints(0) = vMinPoint(0): BBpoints(1) = vMinPoint(1)
            BBpoints(2) = vMaxPoint(0): BBpoints(3) = vMinPoint(1)
            BBpoints(4) = vMaxPoint(0): BBpoints(5) = vMaxPoint(1)
            BBpoints(6) = vMinPoint(0): BBpoints(7) = vMaxPoint(1)
            BBpoints(8) = vMinPoint(0): BBpoints(9) = vMinPoint(1)
            Set oBox = ThisDrawing.ModelSpace.AddLightWeightPolyline(BBpoints)
            vCtrPt1 = Toolbox.ejmath.MidPoint(vMinPoint, vMaxPoint)
            dPt1(0) = vCtrPt1(0): dPt1(1) = vCtrPt1(1): dPt1(2) = vCtrPt1(2)
            dPt2(0) = vCtrPt(0): dPt2(1) = vCtrPt(1): dPt2(2) = vCtrPt(2)
            oBox.Move dPt1, dPt2
           
        Else
            MsgBox "The active viewport must have ModelSpace active for this command to work.", vbExclamation, "Viewport Extents Box"
        End If
    Else
        MsgBox "You must be in paperspace with the active viewport in ModelSpace for this command to work.", vbExclamation, "Viewport Extents Box"
    End If
End Sub





--
Ed
--




"alexf2" <[email protected]> wrote in message news:[email protected]...

Hi, All!

How can i detect which objects of "Model space" are shown in each AcadPViewport in "Paper space" layout consisting of multiple PViewports?



I am rendering layouts into TIFF-image (from VB OLE Automation controller) and want to store "Paper space" coordinates (bound box) of some objects residing in "Model space" (in order to highlight them on image in my application).

No problems if it is default layout showing "Model space" with VIEWPOINT 0,0,1. In this case i iterate through entire ModelSpace collection, finding my objects and translating bounding boxes WCS-->DCS-->PSDCS.

Problem happens if layout consists of many AcadPViewports and some AcadPViewports are specifically adjusted (has non default VIEWPOINT, excluded objects...). In this case i translating bounding boxes of objects from WCS to PSDCS and clipping invisible objects by means of each AcadPViewport:

a1 = .TranslateCoordinates(a1, acWorld, acDisplayDCS, False)
            a1 = .TranslateCoordinates(a1, acDisplayDCS, acPaperSpaceDCS, False)
            a2 = .TranslateCoordinates(a2, acWorld, acDisplayDCS, False)
            a2 = .TranslateCoordinates(a2, acDisplayDCS, acPaperSpaceDCS, False).

Resulting bounding boxes - are 2D "Paper space" projections of 3D objects from "Model space" and i can clip them by bounding boxes of PViewport object. Projections inside PViewport's bounding box are accepted. Outside projections are rejected and i trying to use the next PViewport for this object (switching ActivePViewport, setting MSpace = true and repeating TranslateCoordinates).

But i do not know which PViewport must been used for projection of each object and which objects are excluded.
 
Thank Ed Jobe!

You suggested another equivalent incomplete solution. OK, i can draw bounding rectangle in "Model space", thus i can use SelectByPolygon function. But it not works if VPOINT is distinct from 0,0,1. Opposite, my solution is working always. And problem about detection of suitable PViewPort for each object and about detecting excluded objects is persists.
 
Back
Top