Macro pdf 3D

Hi all

Here I am looking for a bit of macro to automate the recording in 3D pdf on the one hand. The problem is that in this same part I have several configs. I already have a macro to save all the sheets of a plan independently in pdf but I can't transcribe this code for the configurations. Maybe someone knows the line(s) that would have to be changed for it to work. I'll send you my code.

For me, all sheet functions should be replaced by config functions, but I don't know the lines for that. If a good charitable soul is bored, and can help me, I'm a taker;)

 

Thank you

Kind regards


macro-export-pdf-zpf.swp
1 Like

Hello;

Try something like this.

'Option Explicit

Sub main()

'Sauvegarde en PDF3D toutes les configurations.

    Dim swApp                       As SldWorks.SldWorks
    Dim swModel                     As SldWorks.ModelDoc2
    Dim swConfigMgr                 As SldWorks.ConfigurationManager
    Dim swConfig                    As SldWorks.Configuration
    Dim vConfigName                 As Variant
    Dim stnameConfig                As String
    Dim vConfigNameArr              As Variant
    Dim ConfCount                   As Variant
    Dim X                           As Variant
    Dim i                           As Integer
    Dim Chemin                      As String
    Dim PDF3dPath                   As String
    Dim status                      As Boolean
    Dim swExportPDFData             As SldWorks.ExportPdfData
    Dim ExportAs3D                  As Boolean
    Dim lErrors                     As Long
    Dim lWarnings                   As Long
   
    Set swApp = Application.SldWorks
    'on récupére le document actif
    Set swModel = swApp.ActiveDoc
    
    Set swConfigMgr = swModel.ConfigurationManager
    'on récupére la configuration active
    Set swConfig = swConfigMgr.ActiveConfiguration
    'on récupére de nom de la configation active
    stnameConfig = swConfig.Name
    'on récupére le nom de toutes les configurations
    vConfigNameArr = swModel.GetConfigurationNames
    
    ConfCount = UBound(vConfigNameArr)

    If ConfCount = 0 Then Exit Sub

    If ConfCount > 0 Then
       
        i = 1
        'on boucle
        For Each vConfigName In vConfigNameArr
    
            'on affiche la configuration
            swModel.ShowConfiguration2 vConfigName
        
            swModel.ShowNamedView2 "*Isometric", -1
            swModel.ViewZoomtofit2
        
            'on force la reconstruction
            swModel.ForceRebuild3 False
                
            'Creation du Chemin et du Nom des fichiers PDF3D
            Chemin = swModel.GetPathName
            X = Split(Chemin, ".")
            Chemin = X(LBound(X))
            PDF3dPath = UCase(Chemin & "Config_" & i) & ".PDF"
            
            'Sauvegarde en PDF 3D de cette configuration
            
            'Verouillage de l'option Saveas PDF 3D
            ExportAs3D = True
            Set swExportPDFData = swApp.GetExportFileData(1)
            swExportPDFData.ExportAs3D = True

            'Sauvegarde du document en PDF 3D
            Dim swModelDocExt      As SldWorks.ModelDocExtension
            Set swModelDocExt = swModel.Extension
            status = swModelDocExt.SaveAs(PDF3dPath, 0, 2, swExportPDFData, lErrors, lWarnings)
 
            i = i + 1
        Next vConfigName
        
    End If
        
    'on Retourne sur la configuration active avant le traitement
    swModel.ShowConfiguration2 stnameConfig
    swModel.ShowNamedView2 "*Isometric", -1
    swModel.ViewZoomtofit2
    
    'on force la reconstruction
    swModel.ForceRebuild3 False
    'on sauvegarde le document
    swModel.Save3 swSaveAsOptions_e.swSaveAsOptions_Silent, 0, 0

End Sub

 

The PDF3D are saved in the same directory as the Solidworks file (under the Name: "NomdufichierSolidworks_NumeroDeLaConfiguration.PDF")
It's up to you to modify these values according to your desires.

Kind regards

 

 

3 Likes

Thanks for the frame, unfortunately the code does not record in 3D, it saves in simple pdf. Anyone have an idea??

Kind regards

Yes, I noticed it... I had trouble locking the "PDF3D" checkbox of "Save As".... (Sorry)
I updated my previous post, it should work now. Well, normally.
Kind regards

No still not, it still records in pdf and not in 3D, but I think it's not far, I'm testing some modification on my side too. Thank you for the quick response;)

Good night

Kind regards

  Hello quentin.fouillouse;

Strange, the latest version of my macro works very well on my computer (Even after a PC restart).
I am waiting for the results of your changes.

Kind regards.

Does your code require Document Manager? Because if so, maybe that's my problem

Kind regards

 

Edit: It's all good it works thank you, it's just me who didn't delete a line of the old code (the stupid error ^^'). Thank you for your help in any case 

Have a nice day

Kind regards

2 Likes

Hello;

Well no, this macro has nothing to do with "Document Manager" at all. But glad it's right for you.
Please remember to close this discussion if you are satisfied with the answers provided.

Kind regards.

3 Likes

Hello 

I took the liberty of retrieving the first code that saves each sheet in PDF, but it does not repeat the operation, it just creates a pdf of the current page, could you guide me, my skills in VBA are very limited. 

Thank you in advance.

Update: after a restart of the PC the program is running correctly thank you!