Hello all,
I have folowing problem:
I would like to place some component (I know its file path) via SW insert command. I'm able to start this dialog via API by RunCommand (13) but I'm not able to force the file to place. It is necessary to open (visible!) the document that I want to place to be shown in the "Part/assembly to place" list and after that it must be selected by user (or the file can be browsed of course). Both these ways are not usable for my program.
I would like make this workflow automatical but I don't know any way how to give/force the document filename to this dialog via API. Is there such a possibility?
Thanks
Tomas
SolidworksApi macros
RunCommand can't be used for what you want to do. RunCommand really just duplicates a single user action (in this case, clicking on the Insert Component button) in the GUI. You will have to use the AddComponent5 method of AssemblyDoc.
See:
http://help.solidworks.com/2011/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IAssemblyDoc~AddComponent5.html
Thanks for comment, but it is not what I exactly need. I really need to use (or simulate) SW Insert command. I have already implemented similar solution (https://forum.solidworks.com/message/123806#123806) but this solution is not accepted by users - they want to use native SW dialog.
How about if you open the wanted model to background so it will be automatically in the insert component list?
Yes it was my idea (accepted by customers), but to show document in the list of opened documents, document must be visible in the time when Insert command is called. If document is opened as invisible it is not shown in the list .
Does it matter if it is "visible". if it is not the active doc? I mean that just open it, and then activate the assembly before showing the insert component dialog and after this is done just close the background model. Or does this cause something unwanted?
You have described the process I had already implemented ;-) But what is not acceptable for me (and probably for customers) is necessity to open the document to place as visible or make it visible for a moment - user can be confused in this case. Of course, if there is no other possibility I have to use this workflow I'm programming for SolidEdge and Inventor too and both CADs has some possibility how to make it better...
Yep.. and it can be also a bit time consuming if your wanted component is huge assembly -> first you load it about 20min and then user hits cancel on insertion So it would be great to have the predefined path/filename selected when opening the dialog without actually opening anything.
Some help in your problem might be to use "GetCurrentWorkingDirectory" and "SetCurrentWorkingDirectory" so you could atleast get the dialog to go in correct path but user has to show the right file.
Yes, all these possibilities I have in mind... For me is important that I'm going the right (and possible) way, thank you for your help.