SolidWorks API – OpenDoc6 Explained

Hi all

I came across a weirdo with the OpenDoc6 function. In a part of my macro, I try to open each component of my assembly consecutively in the order of the feature manager. What I don't understand is that I have to specify the type of document to open as an assembly to open a part and vice versa to open a part otherwise the document doesn't open.

    If FileTyp = swDocPART Then
        swApp.OpenDoc6 CompPath, swDocASSEMBLY, swOpenDocOptions_Silent, ConfigName, longstatus, longwarnings
     End If

    If FileTyp = swDocASSEMBLY Then
        swApp.OpenDoc6 CompPath, swDocPART, swOpenDocOptions_Silent, ConfigName, longstatus, longwarnings
    End If

Does anyone have an explanation?

 

Jump

This is the normal way the OpenDoc6 method works. See here: http://help.solidworks.com/2016/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.isldworks~opendoc6.html

 

Hello

It is the features of SW that dictate what type of file is open.

For APIs, it allows you to address the right features since each type of file allows different actions.

I understand that we have to specify what type of file we want to open but what I don't understand is that I have to:

  1. Set the PART type to open an ASSEMBLY
  2. Set the ASSEMBLY type to open a PART

 

Hello

Misread, strange.

Bug or bad declaration of SW doc types.

How is the type of document to be opened determined?

Normally it should be this:

' Determine type of SOLIDWORKS file based on file extension
    If InStr(LCase(sDocFileName), "sldprt") > 0 Then
        nDocType = swDocPART
    ElseIf InStr(LCase(sDocFileName), "sldasm") > 0 Then
        nDocType = swDocASSEMBLY
    ElseIf InStr(LCase(sDocFileName), "slddrw") > 0 Then
        nDocType = swDocDRAWING
    Else
        ' Probably not a SOLIDWORKS file
        nDocType = swDocNONE
        ' So cannot open the file
        Exit Sub
    End If   

It's the same as calling a custom property in a drawing message: $PRPSHEET if it's defined in the PRT/ASM, $PRP if it's defined in the DRW...