Bonjour,
Je suis pas très bon dans la programmation, c'est pour cela que je viens vous voir.
J'essaye de compiler deux macros afin de pour créer des STEP à partir de la MEP donc j'ai une première macro qui ouvre la pièce de la mise en plan et une second qui enregistre la pièce en format STEP.
im swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Locatie As String
Dim Locatie_aangepast As String
Dim OpenDoc As Object
Dim Extensie_nieuw As String
Dim Extensie_oud As String
Dim retval As String
Dim Naam As String
Dim Naam_aangepast As String
Dim bRetVal As String
Dim swModel As SldWorks.ModelDoc2
Dim swDrawing As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim Errors As Long
Sub macro1()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swApp = CreateObject("SldWorks.Application")
Set OpenDoc = swApp.ActiveDoc()
Set Part = swApp.ActiveDoc
' Is document active?
If swModel Is Nothing Then
swApp.SendMsgToUser2 "A Drawing file must be open.", swMbWarning, swMbOk
Exit Sub
End If
' Is it a part document?
If swModel.GetType <> SwConst.swDocDRAWING Then
swApp.SendMsgToUser2 "A Drawing file must be open.", swMbWarning, swMbOk
Exit Sub
End If
Set swDrawing = swModel
Set swView = swDrawing.GetFirstView
Set swView = swView.GetNextView
If swView Is Nothing Then
MsgBox "Please insert a Model View first!"
End
Else
swApp.ActivateDoc3 swView.GetReferencedModelName, False, swRebuildOnActivation_e.swUserDecision, Errors
End If
Call macro2
End Sub
Sub macro2()
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set OpenDoc = swApp.ActiveDoc()
Set Part = swApp.ActiveDoc
boolstatus = swApp.SetUserPreferenceIntegerValue(swStepAP, 214) 'Force la version AP214
boolstatus = swApp.SetUserPreferenceIntegerValue(swStepExportPreference, swAcisOutputGeometryPreference_e.swAcisOutputAsSolidAndSurface) 'Force l'export en format Solid/Surface Geometry
Extensie_oud = ".SLDPRT"
Extensie_nieuw = ".STEP"
Locatie = OpenDoc.GetPathName
Locatie_aangepast = Left(Locatie, Len(Locatie) - 7)
retval = Dir$(Locatie_aangepast & Extensie_oud)
Naam = Dir$(Locatie)
Naam_aangepast = Left(Naam, Len(Naam) - 7)
Titel = OpenDoc.GetTitle <------ Erreur de compilation
Titel = Left(Titel, (Len(Titel)))
If retval = Naam Then
nRetval = swApp.SendMsgToUser2(Naam_aangepast & " .STEP Le fichier a été créé", swMbWarning, swMbOk)
End If
Set Part = swApp.ActiveDoc
longstatus = Part.SaveAs3(Naam_aangepast + Format(Now, " yyyy-mm-dd") & Extensie_nieuw, 0, 0)
swApp.CloseDoc Titel
End Sub
Les macros fonctionne quand elles sont seules mais des que je l'ai compil ca ne fonctionne plus. J'ai le message suivant qui s'affiche " Erreur compilation : variable non définie " (voir la ligne ci-dessus en gras)
Si quelqu'un peut m'aider.
Merci d'avance !