Hide Table of Contents

Reset Untitled Document Count Example (VBA)

SolidWorks users may or may not assign titles to new documents.  For new untitled documents, SolidWorks increments the untitled document count and generates a document name by appending the count to the document type (for example, Part1, for the first untitled document in a SolidWorks session).  The untitled document count is automatically reset between SolidWorks sessions.  A new API method, SldWorks::ResetUntitledCount, resets the untitled document count within a single SolidWorks session.

Programs designed to run multiple times in the same SolidWorks session should either assign titles to new documents or reset the untitled document count at the beginning.  This ensures that SolidWorks creates predictable names for untitled documents, resulting in predictable outcomes for each invocation of the program.

The following code example demonstrates how to use SldWorks::ResetUntitledCount to reset the untitled document count.  The code resets the untitled document count at the beginning, creates two untitled documents, maximizes one document, and minimizes the second document. Comment out the bold line below and rerun this program several times.  Without resetting untitled document counts, the new untitled documents created in this program get names that this program does not recognize, and the program does not minimize the second document.

'---------------------------------------

' Preconditions:

' Document templates are installed at this location:

' C:\Documents and Settings\All Users\Application Data\SolidWorks\SolidWorks 2009\templates\

'

' Postconditions:

' Two new untitled part documents are created:  

' one is maximized and one is minimized

'----------------------------------------

Dim swApp As SldWorks.SldWorks

Dim Part As Object

Dim Part2 As Object

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long

 

Sub main()

 

Set swApp = Application.SldWorks

 

' Reset the counts for untitled documents (parts, assemblies, and drawings) to 8

swApp.resetUntitledCount 8, 8, 8

 

' When a new untitled document is created, SolidWorks increments the untitled document count to 9

' The next untitled document gets a name with count=9 ("Part9")

Set Part = swApp.NewDocument("C:\Documents and Settings\All Users\Application Data\SolidWorks\SolidWorks 2009\templates\Part.prtdot", 0, 0, 0)

 

swApp.ActivateDoc2 "Part9", False, longstatus

Set Part = swApp.ActiveDoc

Dim myModelView As Object

Set myModelView = Part.ActiveView

 

' Maximize Part9

myModelView.FrameState = swWindowState_e.swWindowMaximized

 

' When a new untitled document is created, SolidWorks increments the untitled document count to 10

' The next untitled document gets a name with count=10 ("Part10")

Set Part2 = swApp.NewDocument("C:\Documents and Settings\All Users\Application Data\SolidWorks\SolidWorks 2009\templates\Part.prtdot", 0, 0, 0)

 

swApp.ActivateDoc2 "Part10", False, longstatus

Set Part2 = swApp.ActiveDoc

Dim myModelView2 As Object

Set myModelView2 = Part2.ActiveView

 

' Minimize Part10

myModelView2.FrameState = swWindowState_e.swWindowMinimized

 

End Sub



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:   Reset Untitled Document Count 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) 2013 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.