VBA.In a drawing, how do you get the (CONFIGURATION-SPECIFIC) properties of the part?

Hello


I made a macro to save 3D SolidWorks parts, as a ".step" file, in a folder on my desktop, using 2 values of the part property to name the resulting file.

I also made a macro to do the same thing in order to export, the active page (only), of a drawing, in ".pdf", naming the file in the same way, with the difference that you have to look for the 2 custom properties on the 3D part attached to the first view of the page of my drawing

 

Thank you by the way for all the indications I could find on different posts of this forum that allowed me to do this.

In particular the answer of .PL of this page:
http://www.lynkoa.com//forum/3d/vbadans-une-mise-en-plan-comment-obtenir-les-proprietes-de-la-piece


I come to my question which is noted in the title because I have not been able to find or understand how to go and find the same two desired properties to name the file obtained but (SPECIFIC TO THE CONFIGURATION) of the part this time.
 

 

The naming part of the file of my macros for the pdf :
fileName = swRefDoc.Extension.CustomPropertyManager(confName). Get("PART #") & " - " & swRefDoc.Extension.CustomPropertyManager(confName). Get("DESIGNATION") & ".pdf"

 

For the step :

fileName = swModel.Extension.CustomPropertyManager(confName). Get("PART #") & " - " & swModel.Extension.CustomPropertyManager(confName). Get("DESIGNATION") & ".step"

 

Could someone please help me change this last detail?
Thank you in advance
Greeting.

Hello

We don't have all of your code, but you currently need to fill in your confName  variable with "Document". In order to obtain the properties related to the document.

All you have to do is put the name of your configuration in your confName variable and you're done.

1 Like

Hello

Thank you for your answer.
However I apologize for me, I've tried some things but it doesn't work. I think I've understood but I'm still missing a little something.


My code and the following:

 

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swExportPDFData     As SldWorks.ExportPdfData
Dim fileName As String
Dim nErrors             As Long
Dim nWarnings           As Long


Sub main()

Set swApp = Application.SldWorks


'Retrieves the active document
Set CurrentDOC = swApp.ActiveDoc
Set swModel = swApp.ActiveDoc
Set swConfigMgr = swModel.ConfigurationManager
Set swDraw = swModel

Set swView = swDraw.GetFirstView

Set swView = swView.GetNextView 'enables/retrieves the first view for custom properties

Set swRefDoc = swView.ReferencedDocument  ' We now have swRefDoc the 3D of the drawing

Set swExportPDFData = swApp.GetExportFileData(1)


fileName = swRefDoc.Extension.CustomPropertyManager(confName). Get("PART #") & " - " & swRefDoc.Extension.CustomPropertyManager(confName). Get("DESIGNATION") & ".pdf"
swExportPDFData.SetSheets swExportData_ExportCurrentSheet, ""
swExportPDFData.ViewPdfAfterSaving = False
 
swModel.Extension.SaveAs "C:\Users\CASTELL\Desktop\SldW-Export\" & fileName, 0, 0, swExportPDFData, nErrors, nWarnings

End Sub