DeleteScene Method (IModelDocExtension)

Programming and macros
gerard
Posts: 60
Joined: Wed Oct 05, 2022 10:24 am
Answers: 0
x 6
x 35

DeleteScene Method (IModelDocExtension)

Unread post by gerard »

All,

I'm tweaking my clean up utility to be able to unfiy the scene settings in my parts/assemblies.

Doing some spelunking I've come across the DelecteScene function: https://help.solidworks.com/2017/Englis ... Scene.html

To be kind, documentation is kinda sparse.

Has anyone gotten this to work? More importantly has anyone gotten this to work under VBA?

Thanks
User avatar
JSculley
Posts: 648
Joined: Tue May 04, 2021 7:28 am
Answers: 55
x 9
x 883

Re: DeleteScene Method (IModelDocExtension)

Unread post by JSculley »

It pretty much works as advertised. Here's a before:
image.png
Here's some code:

Code: Select all

Dim swApp As SldWorks.SldWorks
Dim mDoc As ModelDoc2
Dim mExt As ModelDocExtension
Sub main()
    Set swApp = Application.SldWorks
    Set mDoc = swApp.ActiveDoc
    Set mExt = mDoc.Extension
    mExt.DeleteScene
End Sub
And here's the after:
image.png
User avatar
AlexB
Posts: 502
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 269
x 446

Re: DeleteScene Method (IModelDocExtension)

Unread post by AlexB »

It works for me when I run my code, but I had to test a few things to make sure I knew what was going on.

You can delete a scene, however there needs to be a scene applied to the part so SW re-applies the default theme. This is why it doesn't appear that the scene is deleted from the feature tree.
gerard
Posts: 60
Joined: Wed Oct 05, 2022 10:24 am
Answers: 0
x 6
x 35

Re: DeleteScene Method (IModelDocExtension)

Unread post by gerard »

JSculley wrote: Wed Feb 15, 2023 7:45 am It pretty much works as advertised. Here's a before:
image.png

Here's some code:

Code: Select all

Dim swApp As SldWorks.SldWorks
Dim mDoc As ModelDoc2
Dim mExt As ModelDocExtension
Sub main()
    Set swApp = Application.SldWorks
    Set mDoc = swApp.ActiveDoc
    Set mExt = mDoc.Extension
    mExt.DeleteScene
End Sub
And here's the after:
image.png
Works perfectly.

Thank you
Post Reply