Reset Untitled Document Count Example (VB.NET)
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
'----------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System
Partial Class SolidWorksMacro
Public
Sub main()
Dim
Part As ModelDoc2 = Nothing
Dim
Part2 As ModelDoc2 = Nothing
Dim
boolstatus As Boolean = False
Dim
longstatus As Integer = 0
Dim
longwarnings As Integer = 0
' 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")
Part
= CType(swApp.NewDocument("C:\Documents and Settings\All Users\Application
Data\SolidWorks\SolidWorks 2009\templates\Part.prtdot", 0, 0, 0),
ModelDoc2)
swApp.ActivateDoc2("Part9",
False, longstatus)
Part
= CType(swApp.ActiveDoc, ModelDoc2)
Dim
myModelView As ModelView = Nothing
myModelView
= CType(Part.ActiveView, ModelView)
'
Maximize Part9
myModelView.FrameState
= CType(swWindowState_e.swWindowMaximized, Integer)
'
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")
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)
Part2
= CType(swApp.ActiveDoc, ModelDoc2)
Dim
myModelView2 As ModelView = Nothing
myModelView2
= CType(Part2.ActiveView, ModelView)
'
Minimize Part10
myModelView2.FrameState
= CType(swWindowState_e.swWindowMinimized, Integer)
End
Sub
'''
<summary>
'''
The SldWorks swApp variable is pre-assigned for you.
'''
</summary>
Public
swApp As SldWorks
End Class