一个来自微软的插件:3D旋转

无极 发表于: 2008-5-29 09:04 来源: 扑奔PPT网

朋友们是否发现了:在给形状添加3D效果之后,如果你要旋转图形,它只能围绕Z轴旋转,要围绕X、Y轴旋转十分不方便,为此,
微软专家John H和 Reiher Jr写了一个PPT插件,允许你围绕X、Y、Z轴的任何一轴自由旋转。
这是一个免费插件,没有实现“动画旋转”功能,不知道其他人是否有完整功能的版本。有的话拿出来分享一下。

 



把插件的代码也一并公布了吧:
这是窗体代码:
' Rotate Me PPTVB project
' By John H. Reiher Jr.
' Define default axis variables, to store initial X,Y positions
' of the object being rotated.
Dim defX As Integer
Dim defY As Integer
Dim defZ As Integer
Dim objName As String
' Define variables used for rotation
Dim newX As Integer
Dim newY As Integer
Dim newZ As Integer
' Define variables used in error checking
Dim lastX As Integer
Dim lastY As Integer
Dim lastZ As Integer

Private Sub Cancelbut_Click()
' Reset object back to original X-Y-Z coords'
' unload VBapp.
    ActiveWindow.Selection.ShapeRange.ThreeD.RotationX = defX
    ActiveWindow.Selection.ShapeRange.ThreeD.RotationY = defY
    ActiveWindow.Selection.ShapeRange.Rotation = defZ
    Unload Me
End Sub
Private Sub cmdReset_Click()
' Reset object back to original X-Y-Z coords'
' Set axis text boxes to original values.
    If chkFancy.Value = True Then
        newX = Xaxis.Value
        newY = Yaxis.Value
        newZ = Zaxis.Value
        FancyRot defX, defY, defZ
    Else
        ActiveWindow.Selection.ShapeRange.ThreeD.RotationX = defX
        ActiveWindow.Selection.ShapeRange.ThreeD.RotationY = defY
        ActiveWindow.Selection.ShapeRange.Rotation = defZ
    End If
    cmdReset.Enabled = False
    Xaxis.Value = defX
    Yaxis.Value = defY
    Zaxis.Value = defZ
End Sub
Private Sub OKbut_Click()
' run RotMe subroutine, unload program.
    RotMe
    Unload Me
End Sub
Private Sub preview_Click()
' Run RotMe so user can see if rotation is acceptable.
    RotMe
    cmdReset.Enabled = True
End Sub
Private Sub SpinButton1_SpinDown()
' nudge down Y axis value. Check for bounds.
    Yaxis.Value = Yaxis.Value - SpinButton1.SmallChange
    If Yaxis.Value < -90 Then
        Yaxis.Value = -90
    End If
End Sub
Private Sub SpinButton1_SpinUp()
' nudge up Y axis value. Check for bounds.
    Yaxis.Value = Yaxis.Value + SpinButton1.SmallChange
    If Yaxis.Value > 90 Then
        Yaxis.Value = 90
    End If
End Sub
Private Sub SpinButton2_SpinDown()
' nudge down X axis value. Check for bounds.
    Xaxis.Value = Xaxis.Value - SpinButton2.SmallChange
    If Xaxis.Value < -90 Then
        Xaxis.Value = -90
    End If
End Sub
Private Sub SpinButton2_SpinUp()
' nudge up X axis value. Check for bounds.
    Xaxis.Value = Xaxis.Value + SpinButton2.SmallChange
    If Xaxis.Value > 90 Then
        Xaxis.Value = 90
    End If
End Sub
Private Sub SpinButton3_SpinDown()
' nudge down Z axis value. Check for bounds.
    Zaxis.Value = Zaxis.Value - SpinButton3.SmallChange
End Sub
Private Sub SpinButton3_SpinUp()
' nudge up Z axis value. Check for bounds.
    Zaxis.Value = Zaxis.Value + SpinButton3.SmallChange
End Sub
Private Sub UserForm_Activate()
' grab X, Y, Z axis coords for object
' set text boxes to same numbers
' set reserved variables.
    defX = ActiveWindow.Selection.ShapeRange.ThreeD.RotationX
    defY = ActiveWindow.Selection.ShapeRange.ThreeD.RotationY
    If ActiveWindow.Selection.ShapeRange.Rotation > 180 Then
        defZ = ActiveWindow.Selection.ShapeRange.Rotation - 360
    Else
        defZ = ActiveWindow.Selection.ShapeRange.Rotation
    End If
    Xaxis.Value = defX
    Yaxis.Value = defY
    Zaxis.Value = defZ
    lastX = defX
    lastY = defY
    lastZ = defZ
    objName = ActiveWindow.Selection.ShapeRange.Name
    cmdReset.Enabled = False
End Sub
Function RotMe()
Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim i As Integer
Dim k As Integer
    ' Is it Blank?
    ' yes, set to zero
    ' else set to axis value.
    On Error Resume Next
    Err.Clear
   
    If Xaxis.Value = "" Then
        x = 0
        Xaxis.Value = x
    Else
        x = Xaxis.Value
    End If
   
    If Yaxis.Value = "" Then
        y = 0
        Yaxis.Value = y
    Else
        y = Yaxis.Value
    End If
   
    If Zaxis.Value = "" Then
        z = 0
        Zaxis.Value = z
    Else
        z = Zaxis.Value
    End If
   
    If Err.Number <> 0 Then
        MsgBox "Please enter a value between -90 and +90"
        Xaxis.Value = lastX
        Yaxis.Value = lastY
        Zaxis.Value = lastZ
    Else
   
    ' Is it bigger than 90?
    ' yes, then set it to 90
    ' no is it less than -90
    ' yes then set it to -90
    If Xaxis.Value > 90 Then
        x = 90
        Xaxis.Value = x
    Else
        If Xaxis.Value < -90 Then
            x = -90
            Xaxis.Value = x
        End If
    End If
   
    If Yaxis.Value > 90 Then
        y = 90
        Yaxis.Value = y
    Else
        If Yaxis.Value < -90 Then
            y = -90
            Yaxis.Value = y
        End If
    End If
   
    If Zaxis.Value > 360 Then
        z = Zaxis.Value - 360
        Zaxis.Value = z
    Else
        If Zaxis.Value < -360 Then
             z = Zaxis.Value + 360
            Zaxis.Value = z
        End If
    End If
   
    ' set axis to new location.
    If chkFancy.Value = True Then
        newX = ActiveWindow.Selection.ShapeRange.ThreeD.RotationX
        newY = ActiveWindow.Selection.ShapeRange.ThreeD.RotationY
        If ActiveWindow.Selection.ShapeRange.Rotation = lastZ Then
            newZ = ActiveWindow.Selection.ShapeRange.Rotation
        Else
            newZ = lastZ
        End If
        FancyRot x, y, z
    Else
        ActiveWindow.Selection.ShapeRange.ThreeD.RotationY = y
        ActiveWindow.Selection.ShapeRange.ThreeD.RotationX = x
        ActiveWindow.Selection.ShapeRange.Rotation = z
    End If
    lastX = x
    lastY = y
    lastZ = z
    End If
End Function
Function FancyRot(x As Integer, y As Integer, z As Integer)
Dim Ix As Integer
Dim Iy As Integer
Dim Iz As Integer
Dim Kx As Integer
Dim Ky As Integer
Dim Kz As Integer
    If newX >= x Then
        Kx = -1
    Else
        Kx = 1
    End If
    If newY >= y Then
        Ky = -1
    Else
        Ky = 1
    End If
    If newZ >= z Then
        Kz = -1
    Else
        Kz = 1
    End If
   
    For Iy = newY To y Step Ky
    ActiveWindow.Selection.SlideRange.Shapes(objName).Select
    ActiveWindow.Selection.ShapeRange.ThreeD.RotationY = Iy
    ActiveWindow.Selection.Unselect
    Next Iy
    For Ix = newX To x Step Kx
    ActiveWindow.Selection.SlideRange.Shapes(objName).Select
    ActiveWindow.Selection.ShapeRange.ThreeD.RotationX = Ix
    ActiveWindow.Selection.Unselect
    Next Ix
   
    For Iz = newZ To z Step Kz
    ActiveWindow.Selection.SlideRange.Shapes(objName).Select
    ActiveWindow.Selection.ShapeRange.Rotation = Iz
    ActiveWindow.Selection.Unselect
    Next Iz
   
    ActiveWindow.Selection.SlideRange.Shapes(objName).Select
   
End Function

[ 本帖最后由 无极 于 2008-5-29 09:58 编辑 ]

一个来自微软的插件:3D旋转 (23.8 KB, 下载次数: 1737)

大家对 一个来自微软的插件:3D旋转 的评论
无极 发表于 2008-5-29 10:00:18
这是模块代码:

Sub LaunchRot()
   On Error Resume Next
   Err.Clear

   Dim not3d As Boolean
      
   'Tests to see if the object selected is a shape
    If ActiveWindow.Selection.Type = ppSelectionShapes Then
   
         ' Check if error occured
         If Err.Number <> 0 Then
           MsgBox "3-D Rotation requires that you have a " _
              & "presentation open. Open a presentation, select " _
              & "a 3-D object and run 3-D Rotation " _
              & "again.", vbExclamation, "3-D Rotation Error"
            End
         End If
         
         'Make sure that only one shape is selected.
         If ActiveWindow.Selection.ShapeRange.Count > 1 Then
         
            MsgBox "You have too many objects selected. 3-D Rotation " _
                 & Chr(13) & "requires that you have one 3-D object selected. To " _
                 & Chr(13) & "rotate more than one object at a time, use PowerPoint's " _
                 & Chr(13) & "group command first.", vbExclamation, "3-D Rotation Error"
            'Stop the macro.
            End
         End If

        ' tests to see if the object selected is a three-d shape
        If ActiveWindow.Selection.ShapeRange.ThreeD.Visible = msoTrue Then
            
            ' Set the dialog position
            frmRotMe.Top = ((Application.Height \ 2) - (frmRotMe.Height \ 2))
            frmRotMe.Left = ((Application.Width \ 2) - (frmRotMe.Width \ 2))
            
            frmRotMe.Show
        Else
            not3d = True
        End If
    Else
        not3d = True
    End If
        
    If not3d Then
   
      MsgBox "Please choose a 3D object first.", _
         vbExclamation, "No 3D Object Selected"
    End If
   
End Sub
Sub Auto_Open()

   ' Store an object reference to a command bar
   Dim ToolsMenu As CommandBars
   
   ' Holds a reference to the new menu item
   Dim NewControl As CommandBarControl
   
   ' Store the position of the control bar
   Dim lPosition As Long
   
   Dim FoundFancy As Boolean
   
   ' Counter
   Dim x As Long
   
   FoundFancy = False
   
   ' Figure out where to place the menu choice
   Set ToolsMenu = Application.CommandBars
   
   ' Loop through the command bars
   For x = 1 To ToolsMenu("Tools").Controls.Count
   
      With ToolsMenu("Tools").Controls.Item(x)
      
         ' Check Fancy rotation is in the menus
         If .Caption = "&3-D Rotation..." Then
         
            ' Fancy rotation was found in the menu
            FoundFancy = True
         
            If .OnAction = "LaunchRot" Then
               Exit For
            Else
               .OnAction = "LaunchRot"
               Exit For
            End If
            
         End If
      
         ' Add the menu choice after auto clipart
         If .Caption = "A&utoClipArt..." Then
            
            Position = x + 1
            Exit For
                     
         End If
      
      End With
      
   Next x
   
   ' If Auto ClipArt not found put the menu
   ' sixth in the list
   If FoundFancy = False And Position = 0 Then
      Position = 6
   End If
   
   If FoundFancy <> True And Position <> 0 Then
   
      ' Create the menu choice
      Set NewControl = ToolsMenu("Tools").Controls.Add _
         (Type:=msoControlButton, _
         Before:=Position)
         
      ' Name the menu item
      NewControl.Caption = "&3-D Rotation..."
            
      ' Conect the menu choice to the macro
      NewControl.OnAction = "LaunchRot"
      
   End If
   
End Sub
Sub Auto_Close()

   On Error Resume Next
   
   ' Counter
   Dim x As Long
   
   ' Store an object reference to a command bar
   Dim ToolsMenu As CommandBars
   
   ' Figure out where to place the menu choice
   Set ToolsMenu = Application.CommandBars

   ' Loop through the command bars
   For x = 1 To ToolsMenu("Tools").Controls.Count
   
      With ToolsMenu("Tools").Controls.Item(x)
      
         ' Check Fancy rotation is in the menus
         If .Caption = "&3-D Rotation..." Then
         
            ' Remove the menu choice
            .Delete
            
         End If
      
      End With
      
   Next x

End Sub
Venkey 发表于 2008-5-29 10:06:06
请问楼主这个软件怎么使用啊?
皇城根下 发表于 2008-5-29 10:17:44
楼主真实辛苦。连原代码都出来了。收下了
无极 发表于 2008-5-29 10:29:16
下载文件后,把文件解压缩到一个目录。打开PPT从“工具”菜单中选择“加载宏”,在出现的对话框中单击“添加”,找到目录中的3D旋转.ppa文件,就会加载插件。然后在“工具”菜单中会出现一个新的菜项目:3-D旋转。
在幻灯片上添加一个图形,设置它的三维效果,然后从“工具”菜单中选择“3-D旋转”,就会出现3D旋转窗体,单击窗体上的旋钮就可以改变角度,并可随机预览效果。
JoannaJJ 发表于 2008-6-01 02:15:47
感谢了,首先要先解决我自己ppt的加载宏问题。
ekinwuxiao 发表于 2008-6-04 11:23:59
谢谢楼主,但是就算偶把宏安全级别调至最低了也不能加载厄。。。。。
请问楼主是怎么回事,俺是新手,请不要见怪
ekinwuxiao 发表于 2008-6-04 11:58:58
俺的错,现在好了,再次谢谢楼主
rising 发表于 2008-6-04 12:00:46
2007实现起来很方便啊
dragonlcy 发表于 2008-6-04 14:24:11
我这显示: 运行时的错误 70

拒绝的权限
sundark 发表于 2008-6-04 21:42:29
长见识了!!!!!很好!
sherley_08 发表于 2008-6-04 23:19:11
谢谢,xinku
nxszslj 发表于 2008-6-15 17:14:22
真的,你太好了,你就是好人,强烈要求给你发工资,哈哈
gezhi 发表于 2008-6-15 17:21:12
好东西,谢谢分享!!!
ffuucckku 发表于 2008-6-20 10:05:47
为什么加载了没反应????
mzj324 发表于 2008-6-23 10:37:42
感谢提供这么好的东东!!:D
fy_wdm 发表于 2008-7-02 17:06:54
好东西,谢谢楼主:$
rachelpku 发表于 2008-7-03 16:42:15
我怎么加载不上啊?有谁能解答这个问题吗?
LZOM 发表于 2008-7-03 17:21:01
谢谢!我就去试试!
allkill5488 发表于 2008-7-04 14:49:24
我试了下,可以把物体旋转,可是不能生成旋转的动画呀,不知道是怎么设置的?
netdat 发表于 2008-7-05 09:48:04

QUOTE:

原帖由 dragonlcy 于 2008-6-4 14:24 发表
我这显示: 运行时的错误 70

拒绝的权限
我也是这样的提示,不知为何原因
最新PPT模板
最新贴子
PPT热贴