Integration: Change of basemap + PDF creation

Hi all!

I could use a little help with the use of Integration.
I want to use it for my plans:

  • Change the background map of all sheets to suit my format
  • Create a PDF in the folder where the document is located

So far, so good, not too complicated. On the other hand, I would like my plan. SLDDRW is not saved with this new basemap. However, in the action settings, I did uncheck the save option.
image

I tried to change the background plan after saving the .pdf, but inevitably the execution takes twice as long.

Thank you for your help, have a nice day!

Hello c_vuillaume,
It may have nothing to do with it, but I found it on the web, hoping it could help. => https://www.youtube.com/watch?v=T7xHvbgzSOs
or maybe this =>https://help.solidworks.com/2022/french/SolidWorks/sldworks/r_customize_sheet_formats.htm
@+.
AR.

1 Like

we would need the details of the operations requested under Integration as well as the version of the MycadTools tools used (the one of Solidworks too):
Also pay attention to the visual in front of the operations...

image

It is not impossible that the registration is conditioned by the type of opening...

3 Likes

Thank you for your feedback, it doesn't solve my problem right now but it gives you avenues to explore despite everything =)

For the record, I am indeed reproducing the problem. (the change of background of the plan requires the opening of the document so not concerned)
For me this is a bug since the option not to save is checked, it should not be saved after the pdf the change of background in the MEP.
I'd be you, I'd make a ticket to the hotline.
image

On the other hand, I do something similar for my dxf via macro background replacement then export and no worries (hence the confirmed bug)

2 Likes

Thank you for your feedback. Here are my versions:
Mycadtools 2024 SP1.0 and SW2022 SP5.0

image
image

It's probably going to end in macro this story :slight_smile:

2 Likes

I'll probably do that, thanks for your answer :wink:

2 Likes

While waiting for an answer from Visiativ for the bug, here is a macro that replaces the basemaps, remains the pdf export and close the document without saving:

Option Explicit
'Site avec exemple: https://www.lynkoa.com/forum/mises-en-plan/modifier-une-note-sur-un-fond-de-plan-solidworks-avec-une-macro
Public Enum swDocumentTypes_e
    swDocNONE = 0       ' Used to be TYPE_NONE

    swDocPART = 1       ' Used to be TYPE_PART

    swDocASSEMBLY = 2   ' Used to be TYPE_ASSEMBLY

    swDocDRAWING = 3    ' Used to be TYPE_DRAWING
End Enum

Dim swSheet         As SldWorks.Sheet
Dim swApp           As Object
Dim swModel         As SldWorks.ModelDoc2
Dim swDraw          As SldWorks.DrawingDoc
Dim swModelDocExt   As ModelDocExtension
Dim sTemplate       As String
Dim stemplatepath   As String
Dim Count           As Integer
Dim vSheetNameArr   As Variant
Dim vSheetName      As Variant
Dim vSheetProps     As Variant
Dim bRet            As Boolean
Dim tolerie         As Boolean
Dim swView          As SldWorks.View
Dim userName        As String
Dim cDirTemplate    As String
Dim cTemplateA4     As String
Dim cTemplateA4_Laser As String
Dim cTemplateA3     As String
Dim cTemplateA2     As String
Dim cTemplateA1     As String
Dim cTemplateA0     As String
Dim cTemplateA0plus As String







Sub main()
'Variable à remplacer lors d'un changement de fond de plan
'Constantes à remplacer lors de changement de fond de plan
cDirTemplate = "C:\xxx\xxx\Fond de plan C\" 'Mettre le chemin d'accès aux fonds de plans sous ce format: C:\xxx\xxx\
cTemplateA4 = "a4-c.slddrt" 'A renommer si vos templates s'appelle autrement
cTemplateA4_Laser = "a4-DECOUPE-c.slddrt"
cTemplateA3 = "a3-c.slddrt"
cTemplateA2 = "a2-c.slddrt"
cTemplateA1 = "a1-c.slddrt"
cTemplateA0 = "A0-c.slddrt"
cTemplateA0plus = "A0+-c.slddrt"


'On récupère les infos sur le nom de session windows
'userName = Environ("USERNAME")
'userName = Replace(userName, ".", " ")
'userName = StrConv(userName, vbProperCase)
'Debug.Print "Nom de session windows:" & userName

'If userName = "xxx" Or userName = "xxx1" Then
        'Constantes à remplacer lors de changement de fond de plan
        'cDirTemplate = "C:\xxx\xxx\Test\Fond de plan C\" 'Mettre le chemin d'accès aux fonds de plans sous ce format: C:\xxx\xxx\
        'cTemplateA4 = "a4-c.slddrt" 'A renommer si vos templates s'appelle autrement
        'cTemplateA4_Laser = "a4-DECOUPE-c.slddrt"
        'cTemplateA3 = "a3-c.slddrt"
        'cTemplateA2 = "a2-c.slddrt"
        'cTemplateA1 = "a1-c.slddrt"
        'cTemplateA0 = "A0-c.slddrt"
        'cTemplateA0plus = "A0+-c.slddrt"
'End If


Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

If swModel Is Nothing Then
    MsgBox ("Pas de document ouvert")
    Else
        If swModel.GetType <> 3 Then
            MsgBox ("Il ne s'agît pas d'une mise en plan")
        Else
        Set swDraw = swModel
                Set swModelDocExt = swModel.Extension

        vSheetNameArr = swDraw.GetSheetNames
                For Each vSheetName In vSheetNameArr
                Debug.Print vSheetName
                
                        bRet = swDraw.ActivateSheet(vSheetName): Debug.Assert bRet
                        Set swSheet = swDraw.GetCurrentSheet
                        
                        'Ajout SD test nom template pas utile dans la macro (pour version future?):
                        Set swSheet = swDraw.GetCurrentSheet
                        sTemplate = Mid(swSheet.GetTemplateName, InStrRev(swSheet.GetTemplateName, "\") + 1)
                        Debug.Print sTemplate
                        
                        Set swView = swDraw.GetFirstView
                        Set swView = swView.GetNextView
                        'On récupère le nom de la config de la vue
                        Debug.Print "Nom de la vue" & swView.Name
                        Debug.Print "Configuration" & swView.ReferencedConfiguration
                        
                        
                        
                        vSheetProps = swSheet.GetProperties
                        Debug.Print "vSheetProps(0)=" & vSheetProps(0)
                        If vSheetProps(0) = "7" And swView.ReferencedConfiguration Like "*FLAT-PATTERN" Then 'A4
                            stemplatepath = cDirTemplate & cTemplateA3
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            stemplatepath = cDirTemplate & cTemplateA4_Laser
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            swModel.ForceRebuild3 (False)
                        ElseIf vSheetProps(0) = "7" Then 'A4
                            stemplatepath = cDirTemplate & cTemplateA3
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            stemplatepath = cDirTemplate & cTemplateA4
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            swModel.ForceRebuild3 (False) 'A2
                        ElseIf vSheetProps(0) = "8" Then 'A3
                            stemplatepath = cDirTemplate & cTemplateA4
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            stemplatepath = cDirTemplate & cTemplateA3
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            swModel.ForceRebuild3 (False) 'A2
                        ElseIf vSheetProps(0) = "9" Then
                            stemplatepath = cDirTemplate & cTemplateA4
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            stemplatepath = cDirTemplate & cTemplateA2
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            swModel.ForceRebuild3 (False)
                        ElseIf vSheetProps(0) = "10" Then 'A1
                            stemplatepath = cDirTemplate & cTemplateA4
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            stemplatepath = cDirTemplate & cTemplateA1
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            swModel.ForceRebuild3 (False)
                        ElseIf vSheetProps(0) = "11" Then 'A0
                            stemplatepath = cDirTemplate & cTemplateA4
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            stemplatepath = cDirTemplate & cTemplateA0
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            swModel.ForceRebuild3 (False)
                        ElseIf vSheetProps(0) = "11" Then 'A0+
                            stemplatepath = cDirTemplate & cTemplateA4
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            stemplatepath = cDirTemplate & cTemplateA0plus
                            bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
                            swModel.ForceRebuild3 (False)
            ElseIf vSheetProps(0) <> "7" Then 'Pour les formats un peu exotiques non gérés
                            If vSheetProps(0) <> "8" Then
                            If vSheetProps(0) <> "9" Then
                            If vSheetProps(0) <> "10" Then
                            If vSheetProps(0) <> "11" Then
                            If vSheetProps(0) <> "12" Then
                                MsgBox "Le fond de plan ne correspond à aucune trame connue" & vbCrLf & "Aucun changement appliqué"
                                Exit Sub
                            End If: End If: End If: End If: End If
                        End If
                    Next
    End If
End If
'Remplacer ici par l'export pdf et fermeture du document sans sauvegarder
'swModel.Save2 (True) 'Sauvegarde des changements
End Sub


3 Likes