Hide Table of Contents

Insert and Use Plane with Manipulator Example (VBA)

This example shows how to insert a plane that has a manipulator.

'--------------------------------------------------------------
' Preconditions:
' 1. In the IDE:
'    a. Click Tools > References > SOLIDWORKS <version>
'       exposed type libraries for add-in.
'    b. Copy Module to the macro module.
'    c. Click Insert > Class Module and copy Class module
'       to that module.
'    d. Open the Immediate window.
' 2. Verify that the specified part exists.
' 3. Open the Immediate window.
'
' Postconditions:
' 1. Opens the part.
' 2. Displays a plane with a manipulator.
' 3. Gets the distance, angles, height, and width of the plane.
' 4. Examine the Immediate window.
' 5. Hold down the left-mouse button and drag the
'    plane up and down using the manipulator, which calls the
'    the handler. Gets the handle index at each drag.
' 6. Click an edge of the plane and hold down the left-mouse button 
'    and rotate the plane, which calls the handler. Gets the handle 
'    index at each rotation.
' 7. Examine the Immediate window.
'
' NOTE: Because the part is used elsewhere, do not
' save changes.
'---------------------------------------------------------------
'Module
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.ModelDoc2
Dim swModelViewMgr As SldWorks.ModelViewManager
Dim swHdlr As Class1
Dim swManipulator As SldWorks.Manipulator
Dim swPlaneManipulator As SldWorks.PlaneManipulator
Dim fileName As String
Dim errors As Long
Dim warnings As Long
Dim PiVal As Double
Sub main()
    Set swHdlr = New Class1    
    Set swApp = Application.SldWorks    
    fileName = "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2017\tutorial\fillets\knob.sldprt"
    Set swModelDoc = swApp.OpenDoc6(fileName, swDocPART, swOpenDocOptions_Silent, "", errors, warnings)    
    ' Create a plane with a manipulator
    Set swModelViewMgr = swModelDoc.ModelViewManager
    Set swManipulator = swModelViewMgr.CreateManipulator(swManipulatorType_e.swPlaneManipulator, swHdlr)
    Set swPlaneManipulator = swManipulator.GetSpecificManipulator    
    ' Set PI
    PiVal = 4 * Atn(1)    
    ' Set the distance of the plane
    swPlaneManipulator.Distance = 0.04
    Debug.Print "Distance = " & swPlaneManipulator.Distance    
    'Set the angles of the plane
    swPlaneManipulator.XAngle = 2 * PiVal / 180
    Debug.Print "X = " & swPlaneManipulator.XAngle
    swPlaneManipulator.YAngle = 10 * PiVal / 180
    Debug.Print "Y = " & swPlaneManipulator.YAngle    
    ' Set the height and width of the plane
    swPlaneManipulator.Height = 0.1
    Debug.Print ("Height = " & swPlaneManipulator.Height)    
    swPlaneManipulator.Width = 0.075
    Debug.Print ("Width = " & swPlaneManipulator.Width) 

    ' Set the color of plane manipulator
    swPlaneManipulator.Color = RGB(255, 0, 0)
    ' Update the plane's properties
    swPlaneManipulator.Update    
    ' Show plane manipulator
    swManipulator.Show swModelDoc
End Sub

Back to top

' Class module

Option Explicit
Implements SwManipulatorHandler2
Private Sub SwManipulatorHandler2_OnUpdateDrag(ByVal pManipulator As Object, ByVal handleIndex As Long, ByVal newPosMathPt As Object)
    Debug.Print "SwManipulatorHandler2_OnUpdateDrag"
    Debug.Print "  HandleIndex      = " & handleIndex
    Dim swRetManip As SldWorks.PlaneManipulator
    Set swRetManip = pManipulator
    
    If (handleIndex = 8) Then
        Dim retDist As Double
        retDist = swRetManip.Distance
    Else
        Dim angleX As Double
        Dim angleY As Double
        angleX = swRetManip.XAngle
        angleY = swRetManip.YAngle
    End If
    
End Sub
Private Function SwManipulatorHandler2_OnDelete(ByVal pManipulator As Object) As Boolean
End Function
Private Sub SwManipulatorHandler2_OnDirectionFlipped(ByVal pManipulator As Object)
End Sub
Private Function SwManipulatorHandler2_OnDoubleValueChanged(ByVal pManipulator As Object, ByVal Id As Long, Value As Double) As Boolean
End Function
Private Sub SwManipulatorHandler2_OnEndNoDrag(ByVal pManipulator As Object, ByVal handleIndex As Long)
End Sub
Private Sub SwManipulatorHandler2_OnHandleRmbSelected(ByVal pManipulator As Object, ByVal handleIndex As Long)
End Sub
Private Function SwManipulatorHandler2_OnHandleLmbSelected(ByVal pManipulator As Object) As Boolean
End Function
Private Sub SwManipulatorHandler2_OnHandleSelected(ByVal pManipulator As Object, ByVal handleIndex As Long)
End Sub
Private Sub SwManipulatorHandler2_OnItemSetFocus(ByVal pManipulator As Object, ByVal Id As Long)
End Sub
Private Function SwManipulatorHandler2_OnLmbSelected(ByVal pManipulator As Object) As Boolean
End Function
Private Function SwManipulatorHandler2_OnStringValueChanged(ByVal pManipulator As Object, ByVal Id As Long, Value As String) As Boolean
End Function
Private Sub SwManipulatorHandler2_OnEndDrag(ByVal pMani As Object, ByVal index As Long)
End Sub

Back to top

 



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Insert and Use Plane with Manipulator Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2017 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.