Detached, attached macro shots?

Hello

All our plan files are in detached mode in SolidWorks and I have dimensions that jump.

I want to make sure that the shots are solid.

Do you know if there is a macro to make the plan files detached, attached?

en masse would be a + (4000 plans)

1 Like

At the moment I don't know of anything exsistant that would do it.

I'll leave it to the API pro to provide a more complete answer

2 Likes

Hello

 

I had the same problem 2 years ago, solved using the Update utility version of MyCADServices.

 

You have to uncheck the option "do not convert files already in the version to be converted" and check the option "save drawings in non-detached format".

3 Likes

What is detached mode?

 

Edit: a little research allowed me to see what it was.

 

If you don't have the MyCAD utilities, it's not very complicated with a macro, but you need to know a little about VBA!

 

You can start with a macro by learning to see what code is behind what you do when you convert to MEP attached.

Hello

 

To change a drawing from the detached type to the attached type, you must use the SaveAs Method API (IModelDocExtension) with the swSaveAsVersion option equal to 3.

 

Below is a sample code snippet that works for open drawing as a replacement for the "backup path+name"

  Dim swApp As Object

  Dim swModel As SldWorks.ModelDoc2

  Dim swModelExt As SldWorks.ModelDocExtension

  Dim boolstatus As Boolean

  Dim ExportData as Object

  Dim Warnings As Long, Errors As Long

 

  Sub main()

 

  Set swApp = Application.SldWorks

  Set swModel = swApp.ActiveDoc

  Set swModelExt = swModel.Extension

  boolstatus = swModelExt.SaveAs("path+savename", 3, 1, ExportData, Errors, Warnings)

 

  End Sub

 

For mass processing, I don't have any code on hand to loop over all the files in a folder. Someone else perhaps?

 

1 Like

According to your answers it seems easy, unfortunately I don't have My cad services.fgirard you seem to master programming. I've never done that kind of thing. Is the script part enough to convert a file into attached? Should I place a macro in each file? (I have 4000 shots I might as well open them 1 by 1 and save as... it will be less complicated?)

Are all 4000 plans in the same directory?

I'm looking for the full macro that processes all the files in 1 directory.

I'll come back as soon as it's done.

Thank you Fgirard. even if the macro deals with a bunch of shots, it would still be interesting.

I've finished the macro to process all the drawings of a directory.

The macro opens a dialog box to select a file to open.

It then retrieves the location of the file and processes all drawings in it.

Here's the code:

 

Dim swApp As Object

Dim swModel As SldWorks.ModelDoc2

Dim swModelExt As SldWorks.ModelDocExtension

Dim boolstatus As Boolean

Dim ExportData As Object

Dim Warnings As Long, Errors As Long

Dim oFSO As Scripting.FileSystemObject

Dim oFld As Scripting.Folder

Dim oFile As Scripting.File

Dim Path As String

Dim Filter                      As String

Dim fileName                    As String

Dim fileConfig                  As String

Dim fileDispName                as String

Dim fileOptions                 As Long

 

 

Sub main()

 

Set swApp = Application.SldWorks

 

Filter on drawing

Filter = "Drawing (*.slddrw)|*.slddrw|"

 

Opening dialog box

fileName = swApp.GetOpenFileName("Select File", "", Filter, fileOptions, fileConfig, fileDispName)

 

'Check selected file

If fileName = "" Then Exit Sub

 

Path recovery

path = Left(fileName, InStrRev(fileName, "\"))

 

'FSO Statement'

Set oFSO = New Scripting.FileSystemObject

Set oFld = oFSO.GetFolder(path)

'looping on the files in the "path" directory

For Each oFile In oFld.Files

    'Test file type = drawing

    If oFile.Type = "SolidWorks Drawing Document" Then

        Opening of the drawing

        Set swModel = swApp.OpenDoc6(oFile.Path, swDocDRAWING, 1, "", Errors, Warnings)

        Set swModelExt = swModel.Extension

        'Backup version attached

        boolstatus = swModelExt.SaveAs(oFile.Path, 3, 1, ExportData, Errors, Warnings)

        Closing the file

        swApp.CloseDoc swModel.GetTitle

    End If

Next oFile

 

End Sub

 

 

 

3 Likes

Thank you Fgirard, having never done macro I will try your program. Have a nice day.

 

With the Integration tool of myCADtools you can run a batch macro using the operations available in integration.

 

This quickly allows you to create a simple macro and run it in bulk on a large number of files.

 

Philou

3 Likes

Thank you prossignol, this will be the solution if I can't create the macro.

I couldn't get the macro to run.

Fgirard, you say that you created the macro. If I could abuse it, could you send me any file with an associated plan integrating the macro? Happy Holidays

Attached is the swp file of the macro.

You save it on your PC.

Then you do "tool/macro/execute"

You select the file "Dettach.swp"

A window will open, you select the first slddrw file in the folder where your plans to convert are located.

You watch the software open and save your plans on its own like a grown-up.

 

That's the theory. In practice you may have problems with references to non-active .dll and problems with the code itself.

 

Launch the macro once and if you get an error message, take a screenshot and post it. I'll see what I can do.

 

Otherwise, as the signal, Prossignol Integration is a very powerful tool that can do the job.

 

Happy holidays to all.

 


detach.swp
1 Like