Hide Table of Contents

Fire Notifications When Renaming Part Document Belonging to Assembly Example (VBA)

This example shows how to fire notifications when you:

  • are about to rename a part document belonging to an assembly.
  • rename the part document.
'----------------------------------------------------------------------
' Preconditions:
' 1. Copy and paste Main into your project.
' 2. Insert a class module and copy and paste Class1 into that module.
' 3. Open public_documents\samples\tutorial\EDraw\claw\center.sldprt.
' 4. Open the Immediate window.
'
' Postconditions:
' 1. Renames center to centerXXX.
' 2. Fires the PreRenameItemNotify and RenameItemNotify events.
' 3. Examine the FeatureManager design tree and Immediate window.
'
' NOTE: Because the part is used elsewhere, do not save changes.
'---------------------------------------------------------------------
'Main
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swPart As SldWorks.PartDoc
Dim swPartEvents As Class1
Dim errors As Long
Dim status As Boolean
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc        
    'Set up event
    Set swPart = swModel
    Set swPartEvents = New Class1
    Set swPartEvents.swPart = swApp.ActiveDoc    
    Set swModelDocExt = swModel.Extension
    status = swModelDocExt.SelectByID2("center.SLDPRT", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
    errors = swModelDocExt.RenameDocument("centerXXX")    
End Sub
'Class1
Option Explicit

Public WithEvents swPart As SldWorks.PartDoc

Private Function swPart_PreRenameItemNotify(ByVal EntityType As Long, ByVal oldName As String, ByVal newName As String) As Long
	Debug.Print "PreRenameItemNotify fired"
End Function

'Fire notification when item is renamed
Public Function swPart_RenameItemNotify(ByVal entType As Long, ByVal oldName As String, ByVal newName As String) As Long
	Debug.Print "RenameItemNotify fired"
End Function


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:   Fire Notifications When Renaming Part Document Belonging to Assembly 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) 2024 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.