Where you're getting the ToolNumber property for drawing?
What is the path you're saving the files to?
I always use the ampersand (&) to combine strings in VBA, so I checked to make sure the plus doesn't work. According to this link, the plus sign doesn't concatenate strings if the variable type isn't correct. The ampersand would be more robust.
To make sure your code always works, I would also build in a lot more checks to see if the custom property is read, if the output name is what you expect, if there aren't two dots before the extension. Those kind of things.
It would by the way be better / more modern to ditch the CustomInfo method and use a Custom Property Manager. The ModelDoc2 SaveAs function is also deprecated and replaced by the IModelDocExtension SaveAs
I believe 'CustomInfo' only works to get the document level custom property. You are trying to get configuration specific property. In this case, I would suggest you use 'ICustomPropertyManger', I would also use 'IModelDocExtension.SaveAs' method to save the documents as Peter Brinkhuis mentioned.
If you plan to save the document for each configurations (for part and assembly documents), then run the loop for each configuration.
Hope this helps.
Daniel, I've not tested these but you can try these.
Option Explicit Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swCustPropMgr As SldWorks.CustomPropertyManager Dim Path As String Dim ValOut As String Dim ResolvedValOut As String Dim wasResolved As Boolean Dim resolved As Variant Dim nErrors As Long Dim nWarnings As Long Sub Main() Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Path = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\")) If swModel.GetType = 3 Then Set swCustPropMgr = swModel.Extension.CustomPropertyManager("") swCustPropMgr.Get5 "ToolNumber", False, ValOut, ResolvedValOut, wasResolved swModel.Extension.SaveAs Path + "TN" + ResolvedValOut + ".slddrw", swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, nErrors, nWarnings Else Set swCustPropMgr = swModel.Extension.CustomPropertyManager(swModel.ConfigurationManager.ActiveConfiguration.Name) swCustPropMgr.Get5 "ToolNumber", False, ValOut, ResolvedValOut, wasResolved If swModel.GetType = 1 Then swModel.Extension.SaveAs Path + "TN" + ResolvedValOut + ".sldprt", swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, nErrors, nWarnings Else swModel.Extension.SaveAs Path + "TN" + ResolvedValOut + ".sldasm", swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, nErrors, nWarnings End If End If End Sub
I have tried Deepaks code and it worked, all that needed changing was after the Set swCustPropMgr = swModel.Extension.CustomPropertyManager("") I needed to add in ToolNumber in between the speech marks.
I' change all the +'s to &'s as said in Peters reply, but I cant get my head around what the CustomInfo method and the IModelDocExtension SaveAs control. I think I'm going to have to get myself booked in for an API training session with Solidworks.
Also it is all on one configuration so I would guess that I wouldn't need to loop it.
Just one question with that program Deepak, will it work with an assembly and a drawing?
Daniel, I was not sure if you have the property value in model or drawing, so made the codes such that if active file is drawing, it would pull the value from drawing and in case of model it would pull from the model.
But yes codes would work on all files.
If you need to pull model information while in drawing, then you need to get the referenced model configuration and pull information from there.