ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
RRRaphael Rabbi Lage Freitas08/09/2015

Hello everyone. I am a new user of solidworks API with some programming background. I actually have been able to create some useful macros with success. But I am struggling with one problem that I cant seem to find a solution. I hope you guys can help me.

I have attached the macro so you guys can have a better look at the coding. I am sorry about the number of comments, but as I said as a new user I have to do a lot of experimentation before ger everything up and running smoothly.

So let me try to explain my struggle to you.

I have created a macro that check which parts of an assembly do not have its respective drawings (Knowing that the drawings have the same name of the parts and are located in the same folder. So when I run the command for the buttom Open Part it just dont work. After some hours of trying to find a solution I realised that the long warning variable was returning 128, which means that the part is open. The thing is: I have JUST the assembly document opened. If I create a new macro and run just the bit of OpenDoc6 it works normally. But if I have the Assembly opened and try to run the command it gives the warning and nothing happens. What I really dont understand is that it worked before, and I changed some other parts of the code (The create drawings command if I am not mistaken) and then it suddely would work anymore.

I will paste right here the command buttom code and will attach the full macro as well. Hope anyone can understand this, because after some hours spent trying to solve I really am sutcked and cant move on.

Thanks in advance.

Sub OpenSelectedPart(bViewOnly As Boolean)

Dim fileerror   As Long

Dim filewarning As Long

Dim sSelectPath As String

Dim sSelectName As String

Dim sSelection  As String

Dim strRefConfig   As String

Dim sDocType        As String

Dim sCompConfig  As String

   

'Get full path of selected part from list box

   ' sSelectPath = listMissingDrawings.Column(2, listMissingDrawings.ListIndex)

   

    'Get full path of selected part from list box

    sSelectPath = listMissingDrawings.Column(2, listMissingDrawings.ListIndex)

    sSelectName = listMissingDrawings.Column(1, listMissingDrawings.ListIndex)

    sCompFileName = Mid(sSelectPath, InStrRev(sSelectPath, "\") + 1)

    Debug.Print sCompFileName

' Get Used Config

    sSelection = GetSelectionName(sSelectName, sRootCompName)

    boolstatus = swAssem.SelectByID(sSelection, "COMPONENT", 0#, 0#, 0#)

    Set swSelPart = swSelMgr.GetSelectedObject(1)

    'strRefConfig = swSelPart.ReferencedConfiguration

    sDocType = LCase(Mid(sSelectPath, Len(sSelectPath) - 6))

    Debug.Print sSelectPath

    Debug.Print sDocType

   

    swApp.OpenDoc6 sSelectPath, swDocPART, swOpenDocOptions_Silent, sCompConfig, fileerror, filewarning

    If filewarning = 128 Then

    MsgBox "Component is already opened!"

    End If

    If sDocType = ".sldprt" Then

    swApp.OpenDoc6 sSelectPath, swDocPART, swOpenDocOptions_ReadOnly, sCompConfig, fileerror, filewarning

    Else

    swApp.OpenDoc2 sSelectPath, swDocASSEMBLY, bViewOnly, bViewOnly, True, fileerror

    End If

   

End Sub