Hello
I managed to combine existing macros that I gleaned from right and left.
Thanks to you, my job is much easier.
I managed to make this macro with an index management that avoids overwriting an existing index but I don't understand why the .step doesn't work for an overview plan and opens the first piece and does the . Step. I thought I would open the file from the first view of the plan.
I go around the problem without seeing it.
There must be small errors or inconsistencies in all this, but I feel that I am touching the solution.
The error is in the paragraph "preparing the 3D for STEP"
Thank you to those for whom VBA is a natural language. I admire you^^
saisissez ou collez d'PDF DXF & STEP indicé.swp - ------------10 / 11 / 2023'
Dim swApp           As SldWorks.SldWorks
Dim swModel         As SldWorks.ModelDoc2
Dim swDraw          As SldWorks.DrawingDoc
Dim swView          As SldWorks.View
Dim Filepath        As String
Dim FileName        As String
Dim boolstatus      As Boolean
Dim longstatus      As Long
Dim longwarnings    As Long
Dim swCustProp      As SldWorks.CustomPropertyManager
Dim Value           As String
Dim réponse         As Integer
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
' Vérifie si un plan est ouvert'
If (swModel Is Nothing) Or (swModel.GetType <> swDocDRAWING) Then
swApp.SendMsgToUser ("Seulement à partir d'un plan !!")
Exit Sub
End If
'-------------------------------------------------- Récupération de l'indice
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swView = swDraw.GetFirstView 'Active le fond de plan
Set swView = swView.GetNextView 'Active la première vue après le fond de plan
Set swModel = swView.ReferencedDocument 'Récupère le fichier associé à la première vue
Set swModelDocExt = swModel.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager("")
swCustProp.Get3 "Indice en cours", False, "", Value 'Récupération de la propriété "Indice en cours"
'-------------------------------------------------- Préparation du 3D pour STEP
Filepath = Left(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\"))
Set swModel = swApp.ActiveDoc
Set myModelView = swModel.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
swApp.ActivateDoc2 "", False, longstatus
Set swModel = swApp.ActiveDoc
swModel.ClearSelection2 True
Set myModelView = swModel.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
FileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)
FileName = Left(FileName, Len(FileName) - 7) & "-" & Value & ".step"
'--------------------------------------------------- Vérif avant écrasemant ou création'
If Len(Dir(Filepath & FileName)) = 0 Then
GoTo CréationEcrasement
Else
réponse = MsgBox("Ecraser l'existant", vbOKCancel + vbQuestion, "/!\ INDICE EXISTANT /!\")
If réponse = vbOK Then
GoTo CréationEcrasement
End If
If réponse = vbCancel Then
End If
Exit Sub
CréationEcrasement:
'-------------------------------------------------- Enregistrement du 3D en STEP
swModel.SaveAs3 Filepath & FileName & "", 0, 0
Set swModel = Nothing
swApp.CloseDoc ""
Set swModel = swApp.ActiveDoc
'-------------------------------------------------- Enregistrement du plan en PDF
Filepath = Left(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\"))
FileName = Mid(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\") + 1)
FileName = Left(FileName, Len(FileName) - 7) & "-" & Value & ".pdf"
swDraw.SaveAs3 Filepath & FileName & "", 0, 0
'-------------------------------------------------- Enregistrement du plan en DXF
Filepath = Left(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\"))
FileName = Mid(swDraw.GetPathName, InStrRev(swDraw.GetPathName, "\") + 1)
FileName = Left(FileName, Len(FileName) - 7) & "-" & Value & ".dxf"
swDraw.SaveAs3 Filepath & FileName & "", 0, 0
End If
End Sub
u code ici