Author Topic: Get the Model Space scale factor  (Read 2895 times)

0 Members and 1 Guest are viewing this topic.

Tyke

  • Guest
Get the Model Space scale factor
« 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?

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Get the Model Space scale factor
« Reply #1 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.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Tyke

  • Guest
Re: Get the Model Space scale factor
« Reply #2 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.

LE3

  • Guest
Re: Get the Model Space scale factor
« Reply #3 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

Tyke

  • Guest
Re: Get the Model Space scale factor
« Reply #4 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.

Bryco

  • Water Moccasin
  • Posts: 1849
Re: Get the Model Space scale factor
« Reply #5 on: February 19, 2010, 10:57:55 AM »
Try setting the centre after messing w/ the ht and width

Tyke

  • Guest
Re: Get the Model Space scale factor
« Reply #6 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.