VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Locating Model Space Objects in a PViewport

1 REPLY 1
SOLVED
Reply
Message 1 of 2
icyzola
574 Views, 1 Reply

Locating Model Space Objects in a PViewport

    In a 2D drawing I want to arrange model space objects in a pviewport such that a specific model space point is in the center of the pviewport.  I'm manipulating the pviewport properties to try to accomplish this.  To have the view perpendicular to the model space XY plane, I've set the pviewport direction property at 0,0,1 and am varying the arrangement of model space objects with the pviewport target property.

    When doing this by hand, I use the DVIEW command and the POints option to set the camera and target.  The model space point I want in the center of the pviewport is 16.25,11.5,0.  In the DVIEW command, POints option, I set target to 16.25,11.5,0 and camera to 16.25,11.5,1.

     When attempting to do this with a macro I'm not finding any obvious correlation between the pviewport target property setting and the location of the desired model space point.  Below are the lines to set the target property in a pviewport called PVPort created in previous steps.  When I set the target property to 0,0,0, the model space point 45.3541, 17, 0 is in the center of the pviewport.  When I set the target property to 16.25,11.5,0, the model space point 61.6041,28.5,0 is in the center of the pviewport.

     If the pviewport has a twist angle of a scale not 1.0 (and therfore a different model space point I'm wanting in the center of the pviewport), it  gets more confusing.

 

Any suggestions would be appreciated.

 

Thanks

 

Dim VPP(0 to 2) as Double

VPP(0) = 0: VPP(1) = 0: VPP(2) = 0
PVPort.Target = VPP

1 REPLY 1
Message 2 of 2
icyzola
in reply to: icyzola

If anybody needs this, here's the solution to my problem (Thanks to an older post by Ed Jobe in http://forums.autodesk.com/t5/Visual-Basic-Customization/PViewport-ModelSpace-Center-Point/m-p/30176...

 

Sub VPScale()
Dim oPsVp As AcadPViewport
Dim vCtrPt As Variant
Dim vCtrPt1(0 To 2) As Double
Dim MSCtr(0 To 2), ScXP


ScXP = 0.5 'Pviewport XP scale


MSCtr(0) = 16.25 / ScXP 'X coordinate of desired model space centerpoint in Pviewport
MSCtr(1) = 11.5 / ScXP 'Y coordinate of desired model space centerpoint in Pviewport
MSCtr(2) = 0 'Z coordinate of desired model space centerpoint in Pviewport

 

'Make paper space active with model space editing enabled.
ThisDrawing.ActiveSpace = acPaperSpace
ThisDrawing.MSpace = True

 

'Fetch the pviewport and the display locked status
Set oPsVp = ThisDrawing.ActivePViewport

'Set the pviewport scale
oPsVp.StandardScale = acVpCustomScale
oPsVp.CustomScale = ScXP

'Find the model space center of the pviewport
vCtrPt = ThisDrawing.GetVariable("viewctr")

 

'Calculate new target settings to get the desired model space center of the pviewport
vCtrPt1(0) = oPsVp.Target(0) + MSCtr(0) - vCtrPt(0)
vCtrPt1(1) = oPsVp.Target(1) + MSCtr(1) - vCtrPt(1)
vCtrPt1(2) = oPsVp.Target(2) + MSCtr(2) - vCtrPt(2)

 

'Place the new target settings in the pviewport
oPsVp.DisplayLocked = False
oPsVp.Target = vCtrPt1

End Sub

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

Post to forums  

Autodesk Design & Make Report

”Boost