change design table settings in invisible document without permanently making it visible

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

change design table settings in invisible document without permanently making it visible

Unread post by Kjara »

I have an invisibly-opened document that has a design table.
I want to change some design table settings, namely those:

Code: Select all

IDesignTable.AutoAddNewConfigs
IDesignTable.AutoAddNewParams
IDesignTable.EnableCellDropdownLists
IDesignTable.Updatable
According to the API help, I can do this by first getting the design table (IModelDoc2.GetDesignTable), then calling IDesignTable.EditFeature, then setting the above values to True/False, then calling IDesignTable.UpdateFeature. The last call will give me a bool telling me if it was successful.

For a visible document, this works perfectly: IDesignTable.UpdateFeature returns True and I can see in the GUI that the settings were actually changed. But for an invisible document, IDesignTable.UpdateFeature returns False and I can see in the GUI that the settings remain unchanged.

So how do I change the settings?


I could make the document visible via IModelDoc2.Visible = True before calling IDesignTable.EditFeature. Then it works. But then the document becomes visible and gets its own window, which I do not want due to performance considerations. Best would be to have a way without touching the visibility state at all, but if there is none, I could live with setting it visible, change the design table settings, then making it inivisble right afterwards. But how? IModelDoc2.Visible = False does not work; the document will still be opened in its own window after I made it visible once.

I am using SolidWorks 2021 SP 5.1.

---

Use case:
The user may or may not have opened some assembly manually, so either no document is visible or only the assembly document is (and all component documents are opened indirectly invisibly by SolidWorks). My program needs to change design table settings in one of these component documents, and it should do so as fast as possible. That's why I do not want it visible at all (visibility gives GUI overhead). But if making it visible is the only option, then I at least want it to be invisible after the design table settings were changed, so that any subsequent changes of data in the component document (by my program) will not give any GUI overhead. And after all changes were done, the user should not see any extra model window (that he did not open himself) because it will confuse him.

---

To reproduce:
I have attached such an assembly (assy2.sldasm) with such a component document (part3.sldprt) and a macro illustrating the problem (tryMakeDocInvisible.swp); all are in the zip file. If you manually open assy2.sldasm before running the macro, part3.sldprt will be already loaded invisibly; if you do not open anything before running the macro, part3.sldprt will be loaded invisibly by the macro. In both cases the macro tries to change design table settings in part3.sldprt and does not succeed (if part3.sldprt is invisible). Afterwards it makes part3.sldprt visible, tries again (now successfully), and reverts it to invisible.

But after the macro has run, you can mouse-over SolidWorks in the Windows task pane and will see an own mini window for part3.sldprt (it may not have the correct description and mini image, but if you click it once, it will update):
part3 own window.png
If you do not see that window, this is probably the case if you have not opened anything prior to calling the macro. In that case you can try switching to another program and back to SolidWorks; the window will sometimes show up then. If not, you will at least see "part3.sldprt" in the menu bar:
part3 open.png
Then if you open a totally unrelated file and minimize it, you will be able to see part3.sldprt open in the background (but not necessarily in its own window).

You can play around with the macro by manually setting the bool variables startVisibility and makeVisible to True/False.
Attachments
tryMakeDocInvisible.zip
(128.16 KiB) Downloaded 35 times
Post Reply