Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I turn off the display while macro is running

Status
Not open for further replies.

Spurs

Mechanical
Nov 7, 2002
297
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.
 
Replies continue below

Recommended for you

Can you build up the assemblies using empty part files initially? If so, you can then call OpenDoc6 on each of the part files to add the required features. The advantage is that the active document does not change even though the processing has switched from the assembly to the referenced parts.

"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.
 
Does the document.visible command work to do this?

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")
 
I've experimented with:

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:



Ken
 
Ken / Stoker

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?
 
I played with it some more last night. I was unable to hide SW unless I first did a Part.Visible = False for each window (part, assembly, and/or drawing) I had open in SW. As you say, I did not try loading in a part after SW was hidden, so I can't speak about that behavior one way or the other.

Ken
 
No, not like that. The part file will be loaded into memory because it will be resolved in the parent assembly. The code is initiated when the parent assembly is the active document. Calling OpenDoc6 allows your code to work on the child parts, but does not change the display while doing so. The screen will continue to show the parent assembly while the code is modifying the individual parts. There is no hiding of parts required in code.

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor