Creating macro opening solidwork file macro help

Hello

Let me explain my problem, I currently have an excel file from which I want to open my 3D (which I manage to do)

then.... save them in . DXf in a specific folder with the path "G:\DAO\Iges-fao" and renaming them with the ERP code that appears in the data map as well as the index (Revision)

I started to write the beginning of the macro but I get stuck at the level of recording the 3D in DXF :-(

I attach the code as well as the printout of the data card

Can you help me

 
   Dim choix_liste As String     'type de pi?ce choisi dans la liste d?roulante pour l'ouverture des pi?ces
   Dim nb_de_piece As Integer    'nombre de lignes de la colonne F correspondant aux nombres de pi?ces
   Dim increment As Integer      'incr?ment de 1 pour effectuer la boucle de recherche ligne par ligne sur la colonne F
   Dim myCell As String          'variable pour fusionner l'incr?ment et la colonne F pour la plage de recherche
   Dim path As String            'chemin du dossier d'enregistrement de la pi?ce
   Dim nom As String             'nom de la pi?ce
   Dim path_complete As String   'chemin complet de la pi?ce
   Dim myBool As Boolean
   Dim myError As Long, myWarning As Long
   Dim swApp As Object
   Dim Part As Object
   Dim longstatus As Long
 
 
 'ouverture de SolidWorks :
 
   myBool = Shell("C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\SLDWORKS.exe", vbNormalFocus)
   Application.Wait Now + TimeValue("0:00:10")
 
Set swApp = CreateObject("SldWorks.Application")
 
 
 'Set swApp = Application.SldWorks

 
  Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.OpenDoc6("C:\_FICHETBAUCHE\03 projets\01 safes\pbz00371\technical file\02 cad\millium-newton feu, cadre modifi? caisse ext pop?e\SW00239874.sldprt", 1, 1, "", myError, myWarning)
    
    Set Part = swApp.ActiveDoc
  
    ' Named View
Part.ShowNamedView2 "*Dessus", 5
Part.ViewZoomtofit2

Set Part = swApp.ActiveDoc

' Save As
Set swModel = Part.SaveAs3("G:\DAO\Iges-fao\SW00246182.DXF", 0, 0)

' Save As
'swModel.SaveAs2 Left(path, (Len(path) - 6)) & "dxf", 0, True, False
 
' boucle a creer

'definition de la plage sur lequel va s'appliquer la macro :
 
'Initialisation de certaines variables:
 
   ' valeur de la conne x = "Nouveau" et Valeur de la colonne Y = " Fabriquée" et "Pièces/Opé panoplies"

   nb_de_piece = Application.WorksheetFunction.CountA(Feuil1.Range("$H:$H")) 'nombre de cellules non vide dans la colonne F, soit le nombre de pi?ces
   increment = 1
 

'For increment = 1 To der lign
 
  ' End If
 
'Next increment 'on passe ? la ligne suivante
 
End Sub

 

thank you in advance

 

 

 

 

 


image.docx

Hello

I see that you have an Epdm vault so to the remark "I want to open my 3D (which I can do)" I don't quite agree, your macro will only work if your files are in your local cache otherwise you have to use the Epdm APIs (EPDM. Interop.epdm_namespace) to connect to the vault, search for the file, repatriate it to the local cache and then load it (not to mention the extraction, backup and archiving functions if necessary).
Then, since your variables are exported from Epdm to SW properties, you can use the "Get6" function to retrieve their values.
And finally, to save a 3D model in DWG or DXF, you need to use the "ExportToDWG2" function.
Examples illustrating the uses of these different functions are available on the various links given above.

Kind regards

2 Likes

Hello d.Roger 

Thank you for the remarks and advice  me who thought I had found :-(  ....

Could you give me a little help to write just this part of the macro.... because I'm a beginner in VB and now I'm lost.....

basically I just want to go read only a SW00 file?????? which is in the following path: "C:\_FICHETBAUCHE\03 projects\01 safes\pbz00371\technical file\02 cad\millium-newton fire, modified framework?

and then save it in .dxf at this place "G:\DAO\Iges-fao and renaming it with the ERP code and the index of the data card

and close the open read-only file

thank you very much for your help hoping you can help me just for this part of the macro

Kind regards

Sebastian

 

Hello

Here is an example of connecting to an Epdm vault and uploading a file to SW, you need to indicate the name of your vault and the name of your file to upload to the macro. Don't forget to put the references "SldWorks xxxx Type Library" and "PDMWorks Enterprise xxxx Type Library" in your macro (Tools/References). 

Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim longstatus As Long
Dim longwarnings As Long
Dim Coffre as string
Dim Fichier as string

Sub main()

    myBool = Shell("C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\SLDWORKS.exe", vbNormalFocus)
    Application.Wait Now + TimeValue("0:00:10")
   
    Set swApp = CreateObject("SldWorks.Application")

    Dim Vault As New EdmVault5
    Dim File As IEdmFile5
    Dim Folder As IEdmFolder5

	Coffre = "x" 'Mettre le nom du coffre fort Epdm à la place du x
	Fichier = "x" 'Mettre le nom complet du fichier à la place du x

    Vault.LoginAuto Coffre, 0

    Set File = Vault.GetFileFromPath(Fichier, Folder)
    
    Set Part = swApp.OpenDoc6(Folder.LocalPath & "/" & File.Name, 1, 2, "", longstatus, longwarnings)
    
    Set Part = swApp.ActiveDoc
    
    Part.ViewZoomtofit2
    
    MsgBox Part.GetPathName

End Sub

 

For the other functions you have specific examples HERE for the Get6 function and HERE for the ExportToDWG2 function . To close the open file in Sw you have to use the CloseDoc function, there is an example of how to use it HERE .

Kind regards

 

1 Like