Try these codes:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel.CustomInfo2("", "Weight") = "" Then
retval = swModel.AddCustomInfo3("", "Weight", swCustomInfoText, Chr(34) & "SW-Mass" & Chr(34))
swModel.CustomInfo2("", "Weight") = Chr(34) & "SW-Mass" & Chr(34)
If swModel.CustomInfo2("", "Area") = "" Then
retval = swModel.AddCustomInfo3("", "Area", swCustomInfoText, Chr(34) & "SW-SurfaceArea" & Chr(34))
swModel.CustomInfo2("", "Area") = Chr(34) & "SW-SurfaceArea" & Chr(34)
Deepek, thanks again. It is working.
assembly part Quantity I fail to create a macro that adds more Quantity precisely, How can i do this? Can someone help me?
I fail to create a macro that adds more Quantity precisely, How can i do this? Can someone help me?
Please can you send me the actual macro, which is ready to use?
or a link to download it.
I simply want to add the mass title and the actual mass of the part into the custom properties for all the parts in a folder.
Xavier how about I provide a procedure to cut and paste the code that Deepak posted.
- Start SolidWorks
- From the SolidWorks menu select Tools, Macro, New.
- In the SaveAs dialog:
- The Microsoft Visual Basic for Applications windows opens.
- Highlight all the code (shown in yellow on my screen shot) and press the delete key.
- Copy the code posted by Deepak and paste into the window you just deleted the code in.
- Since you are only interested in the code for mass, delete the code that pertains to area (code highlighted in yellow below).
- Click the save button then close the VBA window.
- Macro is all set to run on any open file.
Solid Air, Great, thanks that did the trick.
Please can you also assist with some tweaking of the code? or refer me to another discussion which answers.
A. How can I make this a batch process? ie. select folder and apply code to all parts in that folder.
B. I want the info to be in the configuration specific tab, which lines of the code should I change?
C. Also, if the UNITS of mass & area would also show up, that would be awesome. It must actually show up the units that are being used in each particular part and Same for area units.
Add the configuration name here
Also want to state that this is an old method. So look for Add3 in the API help files and use that.
Use the macro in this post for batch processing: change document property mass unit of all part files to common unit
Units can be added but they won't be dynamic and macro has to be run again in case units are changed.