Tutaj używamy o określonych numerach. te są przechowywane zgodnie z ich numerem w sieci. Próbuję zrobić makro, które pobiera liczbę w Excelu, a następnie wstawia wspomnianą do aktywnego zespołu. Do tej pory udaje mi się otworzyć, ale nie da się jej włożyć, czy możesz mi pomóc?
Dziękuję
Sub ouvrirdanssolidworks()
'
'Option Explicit
Dim swApp As Object, swModel As Object
Dim myError As Long, myWarning As Long
Dim swAssembly As Object
Set swApp = CreateObject("SldWorks.Application")
If swApp.GetDocumentCount = 0 Then
MsgBox "Aucun fichier ouvert"
Set swApp = Nothing
End If
Set swModel = swApp.ActiveDoc
'If swModel.GetType <> swDocASSEMBLY Then
'MsgBox "Le document actif n'est pas un assemblage"
'End
'End If
a = ActiveCell.Value
b = "C:\EPDM_VAULT1\1 000 00x-Fournitures\"
c = 1
d = Val(Right(ActiveCell.Value, 3))
e = Left(ActiveCell.Value, 6)
If Val(Right(ActiveCell.Value, 3)) > 499 Then c = 2
AssemblyTitle = swModel.GetTitle
Set swAssembly = swModel
If c = 1 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "000-" & e & "499\" & a & ".sldprt"
If c = 2 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "500-" & e & "999\" & a & ".sldprt"
Set swModel = swApp.OpenDoc6(fichier, 1, 0, "", myError, myWarning)
If c = 1 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "000-" & e & "499\" & a & ".prt"
If c = 2 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "500-" & e & "999\" & a & ".prt"
Set swModel = swApp.OpenDoc6(fichier, 1, 0, "", myError, myWarning)
'insérer
swApp.ActivateDoc2 AssemblyTitle, False, longstatus
'Set Part = swApp.ActiveDoc
'Set swComponent = swAssembly.AddComponent(AssemblyTitle, "", 0, 0, 0)
End Sub
W przeciwnym razie, ponieważ Addcomponent jest przestarzały z punktu widzenia API, spójrz na metodę AddComponent5 (SW2016 możliwe, że nie istnieje w Twojej wersji)
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim myError As Long
Dim myWarning As Long
Dim swAssembly As SldWorks.ModelDoc2
Dim fichier As String
Dim swcomponent As SldWorks.Component2
Sub ouvrirdanssolidworks()
Set swApp = CreateObject("SldWorks.Application")
If swApp.GetDocumentCount = 0 Then
MsgBox "Aucun fichier ouvert"
Set swApp = Nothing
End If
Set swModel = swApp.ActiveDoc
AssemblyTitle = swModel.GetTitle
fichier = "C:\xxx\xxx.sldprt"
Set swModel = swApp.OpenDoc6(fichier, 1, 0, "", myError, myWarning)
Set swModel = swApp.ActivateDoc3(AssemblyTitle, True, swUserDecision, myError)
Set swAssembly = swModel
' Add the part to the assembly document
Set swcomponent = swAssembly.AddComponent5(fichier, swAddComponentConfigOptions_CurrentSelectedConfig, "", False, "", 0, 0, 0)
End Sub
to działa, ale musiałem zamienić "SldWorks.ModelDoc2" na "object"
Czy myślisz, że mógłbym zrobić to samo, ale z tego, co jest zapisane w gazecie prasowej? Na przykład, jeśli skopiuję liczbę, otworzy ją z makrem (jeśli oczywiście istnieje)? Gdzie mogę uzyskać wartość schowka?
Sub ouvrirdanssolidworks()
Dim swApp As Object 'ici
Dim swModel As Object 'ici SldWorks.ModelDoc2
Dim myError As Long
Dim myWarning As Long
Dim swAssembly As Object 'ici SldWorks.ModelDoc2
Dim fichier As String
Dim swcomponent As Object 'ici SldWorks.Component2
Set swApp = CreateObject("SldWorks.Application")
If swApp.GetDocumentCount = 0 Then
MsgBox "Aucun fichier ouvert"
Set swApp = Nothing
End If
Set swModel = swApp.ActiveDoc
AssemblyTitle = swModel.GetTitle
a = ActiveCell.Value
b = "C:\EPDM_VAULT1\1 000 00x-Fournitures\"
c = 1
d = Val(Right(ActiveCell.Value, 3))
e = Left(ActiveCell.Value, 6)
If Val(Right(ActiveCell.Value, 3)) > 499 Then c = 2
If c = 1 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "000-" & e & "499\" & a & ".sldprt"
If c = 2 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "500-" & e & "999\" & a & ".sldprt"
Set swModel = swApp.OpenDoc6(fichier, 1, 0, "", myError, myWarning)
'If c = 1 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "000-" & e & "499\" & a & ".prt"
'If c = 2 Then fichier = "C:\EPDM_VAULT1\1 000 00x-Fournitures\" & e & "500-" & e & "999\" & a & ".prt"
'Set swModel = swApp.OpenDoc6(fichier, 1, 0, "", myError, myWarning)
extensionTitle = swApp.ActiveDoc.GetTitle
Set swModel = swApp.ActivateDoc3(AssemblyTitle, True, swUserDecision, myError)
Set swAssembly = swModel
' Add the part to the assembly document
Set swcomponent = swAssembly.AddComponent5(extensionTitle, swAddComponentConfigOptions_CurrentSelectedConfig, "", False, "", 0, 0, 0)
End Sub