How do I turn off the display while macro is running
How do I turn off the display while macro is running
(OP)
I have a macro that involves creating many part files, and a few assemblies.
The macro takes up to 5 minutes to run. I have been able to create a status indicator (as a userform) to show me the progress of the macro.
I would like to be able to turn off the display of everything accept the status indicator userform. I hope that the macro will run faster if it doesnt need to churn out the graphics.
When the macro is finished, I would like to turn the display back on.
Any suggestions as to the coding that i need?
In addition, the part files that were created are creating a cavity in the assembly. Is there a way to keep the final assembly (including cavity) without needing to keep all of the part files that went into creating the cavities? If this was possible, I could delete all of the part files to clean up the system.
The macro takes up to 5 minutes to run. I have been able to create a status indicator (as a userform) to show me the progress of the macro.
I would like to be able to turn off the display of everything accept the status indicator userform. I hope that the macro will run faster if it doesnt need to churn out the graphics.
When the macro is finished, I would like to turn the display back on.
Any suggestions as to the coding that i need?
In addition, the part files that were created are creating a cavity in the assembly. Is there a way to keep the final assembly (including cavity) without needing to keep all of the part files that went into creating the cavities? If this was possible, I could delete all of the part files to clean up the system.






RE: How do I turn off the display while macro is running
"SldWorks::OpenDoc6 does not activate and display the document if the file is already open in memory in an assembly or drawing. However, SldWorks::OpenDoc6 should return a valid ModelDoc2 pointer that is usable with functions that do not require a document to be displayed."
I have routines that modify multiple files and use this method to keep focus on the parent assembly while all of the child files are being modified. The SWX display never updates. I also use a progress bar so the user can see that the routine is actually doing something.
RE: How do I turn off the display while macro is running
How would you use it in the following code?
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set Part = swApp.OpenDoc6("Testpiece.SLDPRT", 1, 0, "", longstatus, longwarnings)
Set Part = swApp.ActivateDoc("Testpiece.SLDPRT")
RE: How do I turn off the display while macro is running
Part.Visible = False
swApp.UserControl = False
swApp.Visible = False
and
Part.Visible = True
swApp.UserControl = True
swApp.Visible = True
The Part.Visible line seems to be the only one that does anything (from my limited experience). And it sounds like what you are looking for. I've also tried iterating thru the assembly and hiding everything, then running my code, then unhide everything. On my longest running file, I actually do both (Part.Visible = False and hide all the components). It really does seem to help, but I have no idea which portion is helping where.
To put text in the Status Bar see this example from the SW subscription API Examples page:
http://
Ken
RE: How do I turn off the display while macro is running
Don't both of your methods only work if you first load the part file and then change its visibility?
I want to prevent the file from being visible, however stil have it load and perform the functions the macro needs to do.
What code would I need to do that?
RE: How do I turn off the display while macro is running
Ken
RE: How do I turn off the display while macro is running
Here is an example which I put together, much of it coming from one of the examples in the api help. It will add an axis to every child part in an assembly. Run this while an assembly document is active and you will see what I mean. The display never updates until all parts have been processed. In fact, if you comment out the last rebuild line, the display won't update at all.
Keep in mind that "OpenDoc6 should return a valid ModelDoc2 pointer that is usable with functions that do not require a document to be displayed." You will need to check the api functions that you are using to see if they meet this requirement.
Sub Main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim ReferencedDoc As SldWorks.ModelDoc2
Dim ReferencedDocExt As SldWorks.ModelDocExtension
Dim sDocName As String
Dim vDepend As Variant
Dim bRet As Boolean
Dim i As Long
Dim nErrors As Long
Dim nWarnings As Long
Dim nDocType As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
sDocName = swModel.GetPathName
Else
sDocName = sDefaultName
End If
vDepend = swApp.GetDocumentDependencies2(sDocName, True, False, False)
Debug.Print sDocName
If IsEmpty(vDepend) Then
Debug.Print " No dependencies."
Exit Sub
End If
For i = 1 To (UBound(vDepend)) Step 2
sDocExtension = UCase(Right(vDepend(i), 6))
nDocType = Switch(sDocExtension = "SLDPRT", swDocPART, sDocExtension = "SLDASM", swDocASSEMBLY, _
sDocExtension = "SLDDRW", swDocDRAWING)
Debug.Print vDepend(i)
Set ReferencedDoc = swApp.OpenDoc6(vDepend(i), nDocType, swOpenDocOptions_Silent, "", nErrors, nWarnings)
Set ReferencedDocExt = ReferencedDoc.Extension
' Create an axis at the intersection of the top and right planes
boolstatus = ReferencedDocExt.SelectByID2("Right", "PLANE", 0, 0, 0, True, 0, Nothing, swSelectOptionDefault)
boolstatus = ReferencedDocExt.SelectByID2("Top", "PLANE", 0, 0, 0, True, 0, Nothing, swSelectOptionDefault)
ReferencedDoc.InsertAxis2 True
Next i
' boolstatus = swModel.ForceRebuild3(False)
End Sub