API: Edit basemap and save as

Hello

 

I'm looking for a way to delete an element from my basemap (whatever the format) and save the MEP in PDF format and close without saving.

For opening the file it's ok.

To save in PDF format it's ok: "longstatus = Part.SaveAs3(Path & "\" & sfilename & "OUTSIDE", 0, 0)"

To close without saving I think I know: "instance. QuitDoc (Name)"

 

But on the other hand, to remove an element from my background plan, on all the sheets and on all the paper sizes, I'm lost. I tried the macro recorder. Without success. Here is the code it gives me:

 

Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Sheet2", "SHEET", 0.189279289501591, 0.128100540827147, 0, False, 0, Nothing, 0)
Part.EditTemplate
Part.EditSketch
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Plan détail20@Fond object2", "NOTE", 0.244213266171792, 4.26476882290562E-02, 0, False, 0, Nothing, 0)
Part.EditDelete
Part.EditSheet
Part.EditSketch

 

 

Does anyone have a solution?

 

Thank you

Gautier.

 

Hello

What's this mysterious thing to remove from the basemap? An annotation?

Is it exactly the same on each basemap?

Wouldn't it be easier to reload another basemap?

To change the basemap, see this link:

https://forum.solidworks.com/thread/38707?tstart=0

Otherwise, the MyCAD utilities (paid) are able to change a document template in bulk as well (for a folder for example).

Or see this link which contains several macros:

https://forum.solidworks.com/thread/59487

I want to remove our client's name.

It's always the same, it's true that changing the background plan would be easier. I hadn't thought about it.

 

On the other hand, I don't know how to change the format of my background. And I also don't know how to know the type of format (A4, A3, A2, A1, A0).

1 Like
The answer is probably here: https://forum.solidworks.com/thread/60953

Here is the solution I found:

As I was advised, I created basemaps by removing the data that I am not interested in.

Then I save as a PDF and finally I close the file without saving:

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDrawing = swModel

'Test if file opened
If swModel Is Nothing Then

    MsgBox ("Open a document")

Else

    Set swSheet = swDrawing.GetCurrentSheet
    'Retrieves name without extension
    nom_Fichier = Strings.Left(swModel.GetPathName, Strings.Len(swModel.GetPathName) - 7)
    nom_Ouvrir = swModel.GetPathName
    'Retrieve the extension
    extension = Strings.Right(swModel.GetPathName, 7)

    'Retrieves all the names of the sheets
    vSheets = swDrawing.GetSheetNames
    nb_Feuil = swDrawing.GetSheetCount

    If (Not (IsEmpty(vSheets))) Then
    
        nom_Quitter = swModel.GetTitle
        length = Len(vSheets(0))
    
        'For all leaves
        For i = 0 To UBound(vSheets)
            'Function to retrieve sheet formats
            swDrawing.ActivateSheet (vSheets(i))
            
            Set swSheet = swDrawing.GetCurrentSheet
            sheetProperties = swSheet.GetProperties
            
            sheetScale = sheetProperties(2) / sheetProperties(3)
            paperSize = swSheet.GetSize(width, height)
        
            'According to the format change by another format
            Select Case paperSize
        
            Box 7
        
                boolstatus = swModel.SetupSheet5(vSheets(i), 12, 12, sheetProperties(2), sheetProperties(3), True, sheetformatpath(4), width, height, "Default", True)
        
            Box 8
        
                boolstatus = swModel.SetupSheet5(vSheets(i), 12, 12, sheetProperties(2), sheetProperties(3), True, sheetformatpath(3), width, height, "Default", True)
            
            Box 9
        
                boolstatus = swModel.SetupSheet5(vSheets(i), 12, 12, sheetProperties(2), sheetProperties(3), True, sheetformatpath(2), width, height, "Default", True)
        
            Box 10
        
                boolstatus = swModel.SetupSheet5(vSheets(i), 12, 12, sheetProperties(2), sheetProperties(3), True, sheetformatpath(1), width, height, "Default", True)
        
            Box 11
        
                boolstatus = swModel.SetupSheet5(vSheets(i), 12, 12, sheetProperties(2), sheetProperties(3), True, sheetformatpath(0), width, height, "Default", True)
        
            End Select
        
        
    Next i
    
    Saved as PDF with the EXT extension
    longstatus = swModel.SaveAs(nom_Fichier & " EXT.PDF")
    DoEvents
    'Closed without saving
    swApp.QuitDoc (nom_Quitter)
    DoEvents
    
End If
End If

 

Here is the code that allows me to change all the sheets of a drawing with a new basemap, save it as a PDF and close it without saving:

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDrawing = swModel

'Test if file opened
If swModel Is Nothing Then

    MsgBox ("Open a document")

Else

    Set swSheet = swDrawing.GetCurrentSheet
    'Retrieves name without extension
    nom_Fichier = Strings.Left(swModel.GetPathName, Strings.Len(swModel.GetPathName) - 7)
    nom_Ouvrir = swModel.GetPathName
    'Retrieve the extension
    extension = Strings.Right(swModel.GetPathName, 7)

    'Retrieves all the names of the sheets
    vSheets = swDrawing.GetSheetNames
    nb_Feuil = swDrawing.GetSheetCount

    If (Not (IsEmpty(vSheets))) Then
    
        nom_Quitter = swModel.GetTitle
        length = Len(vSheets(0))
    
        'For all leaves
        For i = 0 To UBound(vSheets)
            'Function to retrieve sheet formats
            swDrawing.ActivateSheet (vSheets(i))
            
            Set swSheet = swDrawing.GetCurrentSheet
            sheetProperties = swSheet.GetProperties
            
            sheetScale = sheetProperties(2) / sheetProperties(3)
            paperSize = swSheet.GetSize(width, height)
        
            'According to the format change by another format
            Select Case paperSize
        
            Box 7
        
                boolstatus = swModel.SetupSheet5(vSheets(i), 12, 12, sheetProperties(2), sheetProperties(3), True, sheetformatpath(4), width, height, "Default", True)
        
            Box 8
        
                boolstatus = swModel.SetupSheet5(vSheets(i), 12, 12, sheetProperties(2), sheetProperties(3), True, sheetformatpath(3), width, height, "Default", True)
            
            Box 9
        
                boolstatus = swModel.SetupSheet5(vSheets(i), 12, 12, sheetProperties(2), sheetProperties(3), True, sheetformatpath(2), width, height, "Default", True)
        
            Box 10
        
                boolstatus = swModel.SetupSheet5(vSheets(i), 12, 12, sheetProperties(2), sheetProperties(3), True, sheetformatpath(1), width, height, "Default", True)
        
            Box 11
        
                boolstatus = swModel.SetupSheet5(vSheets(i), 12, 12, sheetProperties(2), sheetProperties(3), True, sheetformatpath(0), width, height, "Default", True)
        
            End Select
        
        
    Next i
    
    Saved as PDF with the EXT extension
    longstatus = swModel.SaveAs(nom_Fichier & " EXT.PDF")
    DoEvents
    'Closed without saving
    swApp.QuitDoc (nom_Quitter)
    DoEvents
    
End If
End If