How to delete an IModelView

Programming and macros
Kjara
Posts: 21
Joined: Mon Jul 19, 2021 2:49 am
Answers: 0
x 1

How to delete an IModelView

Unread post by Kjara »

When I open an IModelDoc2 invisibly, then call IModelDoc2.Extension.GetModelViews, I get returned Nothing/null.

When I make the model doc visible via IModelDoc2.Visible = true and call IModelDoc2.Extension.GetModelViews again, I now get an array with one entry of IModelView.

How do I delete that IModelView?


Reason:
I am trying to do some data modifications on model docs, and in order to be fast and hide it from the user, I open them invisibly. But some data is not available/changeable in invisible documents, so I need to make some model docs visible temporarily. But then they become visible to the user (i.e. they get their own window) and even stay that way after I call IModelDoc2.Visible = false.

My goal is to get a model doc back to being REALLY invisible to the user after I made it visible.

---

Here is some C# code where you can see what I tried:

Code: Select all

if (!modelDoc.Visible)
{
	var views = (object[])modelDoc.Extension.GetModelViews(); // is null here

	modelDoc.Visible = true; // makes it visible to the user and creates a view
	modelDoc.Visible = false; // does NOT revert it to invisible!

	views = (object[])modelDoc.Extension.GetModelViews(); // is not null; contains one element (= the view generated when making it visible)

	modelDoc.NameView("foo"); // name the current view...
	modelDoc.DeleteNamedView("foo"); // ...then delete it

	views = (object[])modelDoc.Extension.GetModelViews(); // still contains one element; deleting did not work!
}
so naming then deleting does not work.
User avatar
bnemec
Posts: 1876
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2473
x 1349

Re: How to delete an IModelView

Unread post by bnemec »

There was a nice thread about how to improve performance, but it was in the old SW forums and I cannot find it now. I commented the link, I don't like links in comments because code lasts longer than URLs. Stupid me assumed since this was link to a site supported by a reputable company it would last or have useful redirect. Bad assumption.

Code: Select all

        //to help performance per https://forum.solidworks.com/message/858283
        modelDoc.FeatureManager.EnableFeatureTree = false;
        modelDoc.FeatureManager.EnableFeatureTreeWindow = false;
IIRC Artem had some great tips of how to make SW behave better through the API and covered various cases. I did a little searching but not finding stuff specific to your case. Most useful links go to CodeStack, I'm guessing a little time searching there will prove to be worthwhile.

https://www.codestack.net/solidworks-api/
Post Reply