Hello everyone,
I created a macro to export my nomenclature in CSV file that works well.
Now I want to improve it by formatting the output filename.
To do this, I need to retrieve the value of a property of the part called "DRAWING_NUM" to put it in a variable, while I am in the drawing and this property does not exist in the drawing.
Do any of you have an idea to make this happen?
I have already found several examples of property recovery on this forum but none of them correspond to my case
Thank you in advance
Hello
It would be enough to add it to your plan template and it will be called a part of it
1 Like
Hello
Is it always a piece in the plan and is there only one model called in these shots?
1 Like
Yes there are already views in the plan, and the part properties are retrieved for the filling of the cartridge
Re
Basically, the code below allows from the first "scanned" view to retrieve the DRAWING_NUM property of the file attached to the view.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swCustProp As CustomPropertyManager
Dim bRet As Boolean
Dim ResolvedValOut As String
Dim sValout As String
Dim WasResolved As Boolean
Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swView = swDraw.GetFirstView 'Active le fond de plan
Set swView = swView.GetNextView 'Active la première vue après le fond de plan
Set swModel = swView.ReferencedDocument 'Récupère le fichier associé à la première vue
Set swModelDocExt = swModel.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager("")
bRet = swCustProp.Get5("DRAWING_NUM", False, sValout, ResolvedValOut, WasResolved) 'Récupération de la propriété "DRAWIND_NUM"
Debug.Print ResolvedValOut 'Utiliser ResolvedValout ou sValout, tout dépend si c'est une valeur calculée ou une valeur fixe
Set swModel = Nothing
Set swApp = Nothing
End Sub
2 Likes
Thank you Cyril.f it works perfectly!
1 Like