Macro change background

Hello

I'm looking for a macro to change the background of an SLDDRW, no matter the original basemap, which opens the properties of the sheet or the pop-up of the attached image and then selects the desired format.

It seems simple but I can't find the trick...

Thank you for your possible answers.


capture.jpg
1 Like

Hello

Attached is a macro that changes the existing background plan by one of the same format located in a defined directory... if it can give a track of progress!


changefonddeplans.swp
4 Likes

Hello

See the SetupSheet6 (IDrawingDoc) function: http://help.solidworks.com/2017/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IDrawingDoc~SetupSheet6.html?verRedirect=1

Kind regards

1 Like

Hello

I don't think that meets his request. If I understand correctly, he wants to be able to select a basemap without knowing in advance which one and therefore be able to access the configurator of the sheet.

To my knowledge, not accessible via the API (which in general allows you to do without this display window), you have to develop your own interface by listing the different basemaps available.

1 Like

No solution to open the desired window, but if it suits you can change the background according to the rules with the mycad Integration tool.

If the basemap =A4 replace with If A3 replace with A3.sldprt...

See even if background = has a certain name...

See attached screenshot.

Maybe it will meet your needs even if it is not the initial request.


remplacer_fond_de_plan.png

I believe it is not feasible via "API".

 

Thank you fgauvrau for the macro, it's not exactly what I was looking for but it's even better since it takes the format that already exists!!

Hi all
I take the liberty of relaunching the subject with my small problem of macro change of plan format and scale through a selection window.

It works wonderfully as long as I change the background file. But! If I just want to change the scale, I lose the sheet, and I have to go to the sheet properties and reload.
I can't integrate this "Recharge" into my macro.

Here is the code part for an A3 detail plan
I have the same thing for the other backgrounds. It's probably something to add at the very end of my macro but I'm crashing...

@sbadenis ! You who have often illuminated the grey areas of my beginner's codes^^

Here is once I have made my choices:

Private Sub CommandValidation_Click()

Unload Window

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Sheet1", "SHEET", 0, 0, 0, False, 0, Nothing, 0)

‹ A3 - Details ›
If OptionButton3.Value = True And OptionButtonPrt.Value = True Then
boolstatus = Part.SetupSheet5(swSheet.GetName, 12, 12, TextBox1.Value, TextBox2.Value, True, "Basemap prt-A3h.slddrt", 0, 0, "Default", True)
Part.EditTemplate
Part.EditSheet

Else
End If'

Hello

Maybe Attempt a Reload : ReloadTemplate Method (ISheet) - 2022 - SOLIDWORKS API Help

1 Like

Hello
I found the dumpling. Quite simple. In the line of code:
Part.SetupSheet5(swSheet.GetName, 12, 12, TextBox1.Value, TextBox2.Value, True, "A3h.slddrt", 0, 0, "Default", True)

The first 12 does not correspond to my A3 format. So conflict. It takes 8 for A3, 9 for A2, 10 for A1 and 11 for A0
Weird that it works with 12 for each format by the way!!

And at the end of the code:

Part.EditTemplate
Part.EditSheet
Part.ViewZoomtofit2

Hello
To avoid other bugs, in this case you would have to recover the format of the sheet. I think it will be more robust in case of a change of version of SW and cleaner especially than letting the function be based on a UserDefined parameter.


swDwgPaperSizes_e Enumeration - 2022 - SOLIDWORKS API Help

1 Like