I'm attaching my macro.... Could you tell me what I'm doing wrong?
thank you in advance for your help
LSE
Sub main()
Dim swModel As ModelDoc2 Dim swModelDocExt As ModelDocExtension Sun swSelMgr As SelectionMgr Dim partFile As String Dim assemblyFile As String Dim drawingFile As String Dim errors As Integer Dim warnings As Integer
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc Dim myModelView As Object Set myModelView = Part.ActiveView myModelView.FrameState = swWindowState_e.swWindowMaximized
' Open an assembly document and select all components in the assembly
assemblyFile = "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\samples\introsw\bolt-assembly.sldasm" Set swApp = CreateObject("SldWorks.Application") Set swModel = swApp.GetOpenDocumentByName(assemblyFile)
I haven't tried the macro but to the remark: "I get a Run Time Error type 13 (typ mismatch)", I wouldn't be surprised if it comes from typing the variables "Dim errors As Integer" and "Dim warnings As Integer" which normally should be "Long". Of course, you also have to check that the file defined in the "assemblyFile" variable exists.
For the question "Could you tell me what I'm doing wrong?" I will not dwell on myself, as my imminent colleagues Sbadenis and Mandrake have already begun to respond... But I agree, or even more, with the remark "but it's not the cleanest" of Sbadenis.
In theory, the assembly is already open, so solidworks is not going to re-open it.
You have to play with other functions I think, put your 130101 lighten and activate your macro, see if it goes to solve.
It's computer science, software can be very 'stupid'. There are a lot of different functions for each function, I saw a '
swApp. CreateNewWindow' which can surely help you forced the software to open your 130101 in a new window.
After that, we have a lot of people who do api here if you enlighten us a little more on what you want to do and why someone can already do it or we can guide you more quickly.
If your subassembly is already open in SW then you have to use the "ActivateDoc3" function to open it (in reality it's activate that you have to say since it's already open) in a new SW window.
@mandragore: I don't quite agree with the remark "It's computer science, software can be very 'stupid'. There are a lot of different functions for each function", I find that APIs are rather logical precisely. In this case there is a difference between "open" and "activate"...