TheSwamp

Code Red => VB(A) => Topic started by: Tyke on February 15, 2010, 03:41:28 AM

Title: Get the Model Space scale factor
Post by: Tyke on February 15, 2010, 03:41:28 AM
Hi,
I have a drawing with two viewports in Model space.
In one of the viewports the user zooms onto an object using any of the normal zoom functions.
How can I, in VBA, get the final scale factor the user zoomed in to and then apply it to the second viewport so that the two viewports have the same zoom factor.

The second part would appear to be solved with:
           ZoomScaled Zoomfactor, acZoomScaledRelative
but I can't seem to get the scale factor.

Does anyone have any ideas?
Title: Re: Get the Model Space scale factor
Post by: David Hall on February 15, 2010, 10:12:27 AM
you will have to get the viewport scale factor for the current VP.  Let me see if I have code for that.
Title: Re: Get the Model Space scale factor
Post by: Tyke on February 17, 2010, 11:05:54 AM
I can't find any properties that would seem to hold the viewport scale.
I've tried using the height property but that doesn't work either.
Title: Re: Get the Model Space scale factor
Post by: LE3 on February 17, 2010, 12:53:14 PM
I can't find any properties that would seem to hold the viewport scale.
I've tried using the height property but that doesn't work either.
I don't use this language, but must be a way to find the properties or methods exposed, not even a help file?.

The Viewport class -have a CustomScale property - read/write
Title: Re: Get the Model Space scale factor
Post by: Tyke on February 19, 2010, 04:01:15 AM
OK guys we have a partial solution. It copies the view in one viewport to the other, with the same view scale.
One quirk it still has is that the views in both viewports jump a quarter of the screen width to the left.
Code: [Select]
Sub CopyViewPort()
   
    Dim objViewPort As AcadViewport
    Dim objCurrentViewport As AcadViewport
    Dim vpCentre(0 To 1) As Double
    Dim dblViewSize As Double
    Dim dblCVPHeight As Double
    Dim dblCVPWidth As Double
    Dim dblCVPScale As Double
   
    Set objCurrentViewport = ThisDrawing.ActiveViewport
   
    Set objViewPort = ThisDrawing.ActiveViewport
   
    ' get centre of current viewport
    vpCentre(0) = ThisDrawing.GetVariable("ViewCtr")(0)
    vpCentre(1) = ThisDrawing.GetVariable("ViewCtr")(1)
   
    'get current vp scale
    dblCVPHeight = objCurrentViewport.Height
    dblCVPWidth = objCurrentViewport.Width
    dblCVPScale = dblCVPWidth / dblCVPHeight
   
    ' get sysvar ViewSize
    dblViewSize = ThisDrawing.GetVariable("ViewSize")
   
    For Each objViewPort In ThisDrawing.Viewports
        ThisDrawing.ActiveViewport = objViewPort
        objViewPort.Center = vpCentre
        objViewPort.Height = dblViewSize
        objViewPort.Width = dblViewSize * dblCVPScale
    Next
   
    ThisDrawing.ActiveViewport = objCurrentViewport
   
    ' regen in all viewports
    ThisDrawing.Regen acAllViewports
   
End Sub

Thanks for all of your help and I hope someone can make use of it.
Title: Re: Get the Model Space scale factor
Post by: Bryco on February 19, 2010, 10:57:55 AM
Try setting the centre after messing w/ the ht and width
Title: Re: Get the Model Space scale factor
Post by: Tyke on February 22, 2010, 02:12:37 AM
@ Bryco

That did it. Great, now it works super.

Thanks Bryco for your help and all the others too.