Um ein neues Blatt zu erstellen, habe ich diesen Code:
(swmodel.getpathname muss natürlich auf Ihr konfiguriertes Teile- oder Baugruppenmodell verweisen)
Set swDraw = swApp.NewDocument(sDrTemplateLaser, 0, 0, 0)
Dim swSheet As SldWorks.Sheet
Set swSheet = swDraw.GetCurrentSheet
bRet = swSheet.SetScale(1, 1, True, False)
Debug.Print "Modèle:" & swModel.GetPathName
Set swView = swDraw.CreateFlatPatternViewFromModelView3(swModel.GetPathName, "", 0.105, 0.184, 0#, False, False)
Dim swDrawModel As SldWorks.ModelDoc2
Set swDrawModel = swDraw
swDrawModel.ForceRebuild3 False
swDrawModel.Extension.SaveAs file, swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, 0, 0
Andernfalls, um ein Blatt zu kopieren und umzubenennen und dann die Referenzen (Konfigurationen) zu ändern, habe ich dieses Stück Code (ich muss schießen, aber nicht zu viel Zeit dafür)
Option Explicit
Const suffixFeuille As String = "-SYM"
Const suffixNomFichier As String = "-SYM"
Dim swApp As SldWorks.SldWorks
Dim swDraw As DrawingDoc
Dim swModel As ModelDoc2
Dim swModel2 As ModelDoc2
Dim bRet As Boolean
Dim swView As SldWorks.View
Dim swRefModel As SldWorks.ModelDoc2
Dim longstatus As Long
Dim longwarnings As Long
Sub copyDrawingSheetSYM()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
If (swDraw Is Nothing) Then
MsgBox "ouvrir une MEP"
End
End If
Dim sheetCount As Integer
sheetCount = swDraw.GetSheetCount
Dim vSheetName As Variant
'vSheet = swDraw.GetSheetNames
Dim sheetName As String
Dim i As Integer
'1-) PARTIE SUPPRESSION FEUILLES SYM EXISTANTE
Debug.Print "1-) PARTIE SUPPRESSION FEUILLES SYM EXISTANTE"
Dim selection As Boolean
selection = False
'swModel.Extension.ClearSelection2 False
vSheetName = swDraw.GetSheetNames
'On boucle sur les feuilles
For i = 0 To UBound(vSheetName)
sheetName = vSheetName(i)
'Debug.Print "Nom de feuille:" & sheetName
If sheetName Like "*" & suffixFeuille & "*" Then
'Debug.Print "On entre dans la partie suppression"
selection = True
'Sélection des feuilles Sym
bRet = swModel.Extension.SelectByID2(sheetName, "SHEET", 0, 0, 0, True, 0, Nothing, 0)
End If
Next i
If selection = True Then
'On demande si on supprime la feuille
If MsgBox("Voulez vous supprimer les feuilles Sym?", vbYesNo + vbDefaultButton1, "Basculer la vue de découpe?") = vbYes Then 'Si le bouton Oui est cliqué
'Suppression des feuilles
bRet = swModel.Extension.DeleteSelection2(0)
'Debug.Print "Feuilles supprimées"
Else
MsgBox "On quitte la macro"
Exit Sub
End If
End If
'2-) PARTIE CREATION FEUILLES SYM
Debug.Print "2-) PARTIE CREATION FEUILLES SYM"
sheetCount = swDraw.GetSheetCount
vSheetName = swDraw.GetSheetNames
'On boucle sur les feuilles
For i = 1 To sheetCount
sheetName = vSheetName(i - 1)
'Debug.Print "Nom de feuille:" & sheetName
If i = 1 Then
Set swView = swDraw.GetFirstView().GetNextView
Set swRefModel = swView.ReferencedDocument
Dim sModelName As String
sModelName = swView.GetReferencedModelName
Debug.Print "File = " & swModel.GetPathName
Debug.Print " View = " & swView.Name
Debug.Print " Referenced model name = " & sModelName
Debug.Print " Model path = " & swDraw.GetPathName
Dim vConfs As Variant
vConfs = swRefModel.GetConfigurationNames
Dim confSymName As String
confSymName = ""
Dim j As Integer
'On boucle sur les config
For j = 0 To UBound(vConfs)
Dim confName As String
confName = vConfs(j)
If confName Like "*Sym*" And Not confName Like "*Sym*Sym*" Then
confSymName = confName
Dim saveJ As String
saveJ = j
End If
'Debug.Print confName
swModel.ForceRebuild3 False
Next j
End If
If confSymName <> "" Then
'On lance la macro pour ajouter le suffix au model auquel la MEP fait référence
'On active le model
Debug.Print sModelName
Set swModel2 = swApp.OpenDoc6(sModelName, 3, 0, "", longstatus, longwarnings)
'ici rendre le model actif
Set swModel2 = swApp.ActivateDoc3(sModelName, swRebuildOnActivation_e.swDontRebuildActiveDoc = 1, 0, 0)
'On lance le code pour modifier la propriété du modèle référencé
zSmartCat_SYM1.smartCat_SYM
'On active la mise en plan
Set swModel = swApp.OpenDoc6(swDraw.GetPathName, 3, 0, "", longstatus, longwarnings)
Set swModel = swApp.ActivateDoc3(swDraw.GetPathName, swRebuildOnActivation_e.swDontRebuildActiveDoc = 1, 0, 0)
'Set swDraw = swModel
swDraw.ActivateSheet sheetName
'Debug.Print "Feuille active:" & sheetName
bRet = swDraw.Extension.SelectByID2(sheetName, "SHEET", 0, 0, 0, False, 0, Nothing, 0)
swModel.EditCopy
bRet = swDraw.PasteSheet(swInsertOption_AfterSelectedSheet, swRenameOption_No)
swDraw.GetCurrentSheet.SetName sheetName & suffixFeuille
'On parcourt toute les vue de la feuille et on change la config
Set swView = swDraw.GetFirstView.GetNextView
Do While Not swView Is Nothing
'Debug.Print " Drawing view = " + swView.Name
'Debug.Print " Referenced model name = " & swView.GetReferencedModelName
'Debug.Print " Referenced configuration name = " & swView.ReferencedConfiguration
'Debug.Print " Referenced configuration persistent reference ID = " & swView.ReferencedConfigurationID
'Changement de configuration (Symétrique) si la vue d'est pas une vue déplié (Flat-Pattern)
If Not swView.ReferencedConfiguration Like "*PATTERN*" Then
'Debug.Print "On change la config"
swView.ReferencedConfiguration = vConfs(saveJ)
Else
'On retourne la vue
'Debug.Print "On retourne la vue"
swView.FlipView = True
End If
'Get next drawing view
Set swView = swView.GetNextView
Loop
End If
Next
'3-) PARTIE CREATION ANNOTATION AJOUT DU SUFFIX NOM DE FICHIER POUR SYM
Debug.Print "3-) PARTIE CREATION FEUILLES SYM"
sheetCount = swDraw.GetSheetCount
vSheetName = swDraw.GetSheetNames
'On boucle sur les feuilles
For i = 1 To sheetCount
sheetName = vSheetName(i - 1)
Debug.Print i & "-Nom de feuille:" & sheetName
If sheetName Like "*" & suffixFeuille & "*" Then
swDraw.ActivateSheet sheetName
Set swView = swDraw.GetFirstView()
'On boucle sur les notes
Dim swNote As Note
Dim swAnn As SldWorks.Annotation
Dim sValue As String
Set swNote = swView.GetFirstNote
swModel.ClearSelection2 (True)
Do While Not swNote Is Nothing
Set swAnn = swNote.GetAnnotation
sValue = "$PRP:""SW-Nom de fichier(File Name)""" 'Mettre le nom de la propriété recherchée
Debug.Print swNote.PropertyLinkedText
If swNote.PropertyLinkedText = sValue Then
Debug.Print "Propriété trouvé"
swNote.PropertyLinkedText = sValue & suffixNomFichier
Exit Do
End If
swModel.ClearSelection2 (True)
Set swNote = swNote.GetNext
Loop
End If
Next i
zBomMaterials.bomMaterials
'swModel.EditRebuild3
'swModel.Save
Set swApp = Nothing
Set swModel = Nothing
Set swDraw = Nothing
Set swRefModel = Nothing
End Sub
Der Zweck dieses 2. Makros besteht darin, alle Blätter eines MEp zu kopieren (Beispiel: Blatt1 und Blatt2)
Fügen Sie -SYM zu den neuen Blättern hinzu (z. B. Tabelle1-SYM, Tabelle2-SYM), und ändern Sie dann die Referenzen aller Ansichten für die symmetrische Konfiguration.
Dieser Code sollte einige Ihrer Fragen zum Ändern von Konfigurationen beantworten. Es liegt an Ihnen, zu suchen und zu sortieren.