Change type projection shots in batch

Hello

I stumbled upon a problem. In order to standardize drawing files from old studies for my client, I am trying to put all the plans back in "European" type projection, because unfortunately, for some reason I don't know, some plans are in USA projection.

It is a question of doing this for each project, because we almost always start from old studies.

I already use MyCadTools Integration to perform a lot of normalization operations, and I tried to change the option of the document " swDrawingProjectionType " to 1, which corresponds to the projection type "frist angle" (europe), see the API help page: https://help.solidworks.com/2021/English/api/swconst/SolidWorks.Interop.swconst~SolidWorks.Interop.swconst.swDrawingProjectionType_e.html

Unfortunately it doesn't seem to work, and the problem may come from the fact that it's not really an option related to the document, but to the sheet...

Does a good soul have a workaround, possibly a macro that I can have Integration run?

Thank you in advance!

Have a nice day


capture_decran_2022-09-08_105908.png

With copy option, the ability to copy options from one document to another.

You convert a plan manually and use it to copy the options to another to see if it works.

https://help.visiativ.com/mycadtools/2021/fr/CopyOptions5.html

Or else in integration you modify the standard of dressing by one that you save from an already modified plan.

 

Or else change the background map with another one that has already been modified. Via integration or if necessary macro attached (you have to modify the path of the basemaps) to be tested on a plan and then via + integration to launch the macro on each basemap.

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 = "U:\Entreprise\Service BE\1-Commun service\Solidworks\Configuration\Modèle de documents\Modèle SW 2020\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"



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
swModel.Save2 (True) 'Sauvegarde des changements
End Sub

 

Thank you very much sbadenis,

I just tried with CopyOption, it doesn't work on this projection type option.

In my procedure I already modify the basemap, and the dressing standard, (via Integration) but this has no effect on the type of projection either.

All this seems logical in the sense that this parameter is not linked to the baseline, nor to the document options, nor to the wrapping standard, but specifically to each sheet of a .slddrw.

So I think the only solution would be a macro that could change this setting recursively for each sheet. One could then consider running the macro via Integration. Unfortunately, my macro skills are way too weak for that...

After trying my solution with the macro works perfectly to change the background plan by one with Euro projection.

On the other hand, the views remain badly placed, they have to be placed manually on the right side, as when you do the manipulation manually by changing the type of projection.

So for me the problem is more complicated than expected and difficult to automate it. I'm afraid that human intervention is mandatory even if you decide to use my method for the change of projection (via my macro for changing the background)

For my macro attached the part to modify with the template paths (pre-saved basemap)

2 Likes

Thank you sbadenis, indeed it works perfectly with this macro. I hadn't looked closely at the code, and indeed, this method doesn't just change the background, but also forces the reload (useful when the filename is identical), and also redefines all the properties related to the sheet, including the type of projection.

On the other hand I struggled a little because I had the error message "The background map does not correspond to any known frame", and I didn't understand where the problem came from. By digging a little I understood that the macro tests the A4 format in vertical and not in horizontal:

If vSheetProps(0) = "7"

So you have to replace 7 by 6 to test the A4H format. Or add a condition.

I've built it into my Integration process, and it does the job.

On the other hand, it's true that you will always have to move the views by hand after the fact ... But frankly it's already good to know that all my shots will be with the right type of projection at the base. Anyway I go through them all one by one after the fact ..

So thank you very much for looking into it.

1 Like