This question has been asked many times. Have you done a search in the forum on custom properties?
I don't believe that is the correct answers, unless I'm not following something. The properties are already created, just need to be added to the custom properties via the pull down list. I have these properties added to my new templates. The macro is to automate the process of updating old files to be used on our new template drawings.
Did you see the video?
I do see this question (or similar questions) asked a lot on the forum. I was looking for help on my exact problem to save a lot learning that that won't be used but once.
Can maybe point me to exact links or code?
I watched your video and that is why I made the suggestion I did. You can update or add all those properties with Property Tab Builder. I created a template with the SW-Material and a couple other fields. All I have to do is select the parts I want to push those properties to in an assembly and click "Apply"... That appears what you were trying to do... But, I guess I misinterpreted your video.
The codes you've in those macro are for creating sketches and not updating properties. Did you attached the correct macro?
I just added the sketch at the end of the macro to prove out the macro. I proved it was not recording the actions of changing the properties, but it did create the sketch at the end. I did attach another macro with out the sketch at the end.
For some reason your video doesn't play full for me. Anyways macro recorder doesn't captures everything. So try the macro codes from this macro and update as needed https://forum.solidworks.com/message/437072#comment-437072
Have you tried using #TASK? If not then give it a try, it is a free tool with lot of inbuilt macros like tool and you ca use them to update the properties as needed. No additional macro would be required.
I've never gotten the macro recorder to work, if you are interested in learning VBA, then definitely go through CAD Sharp's website, if not, and all you care about is quickly creating custom properties, then do take a loot at the Property Tab Builder.
Basically, you would need to cast the custom prop manager object, then you can use the add and get methods to work with properties. In my experience, you can fully automate the custom property process for assigning stuff like BOM information to parts, and not have to worry about data entry/mistakes associated with the property tab builder.
I still need help, I've got a lot of hours into this chasing in circles. I've looked at all the free videos on CADSharp, YouTube, Online Help, API help. While I did learn a lot, code is so form and syntax senvitve. Once someone shows me how to get this code working to change one custom properity, I think it's all down hill from there. Deepak, I did look at your example. This is where I currently am, still can't get the custom properity populated. Yes, it's avalible in the pull down choices. Sorry for all the interation, but I also have 10 more I did not copy in. BTW, API help stated AddCustomInfo2 Method is obsoleted by CustomPropertyManager Property , which is even more confusing me. I'll run the risk of using the old code for now.
I would hazourd the a guess, this is the question everyone else is asking as well. I feel if you help me with this, it would answer the question for grate many users.
This is the line that won't run "'swModel.AddCustomInfo2 "Mass", swCustomInfoText, Chr(34) & "SW-Mass" & "@" & swModel.GetTitle & ".sldprt" & Chr(34)"
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swModelDocExt As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Dim sFileName As String, Path As String
Dim Longstatus As Long, longwarnings As Long
Dim Val As String, nProp As String
Dim ValOut As String
Dim retVal As String
'Dim Part As SldWorks.ModelDoc2
'Dim instance As ICustomPropertyManager
'Dim FieldName As System.String
'Dim FieldType As System.Integer
'Dim FieldValue As System.String
'Dim OverwriteExisting As System.Integer
'Dim value As System.Integer
'Set FieldName = "Materail-Presto"
'value = instance.Add3(FieldName, FieldType, FieldValue, OverwriteExisting)
'swModel.AddCustomInfo2 "Mass", swCustomInfoText, Chr(34) & "SW-Mass" & "@" & swModel.GetTitle & ".sldprt" & Chr(34)
swModel.AddCustomInfo2 ("Mass", swCustomInfoText, "SW-Mass" & "@" & swModel.GetTitle & ".sldprt")
'Set swApp = Application.SldWorks
First, I do not see in your code where you get the SolidWorks or Model objects; a must before you can use AddCustomInfo2. But like you found out, it is an obsoleted call. Below is an example from from the API help using Add3. Of course since you are trying to write to the custom tab and not the configuration specific tab, you will need to alter the code to get the custom property manager.
' 1. Open a part document.
' 2. Open the Immediate
' 1. Adds a date custom property to the
' 2. Deletes the custom property from the
' 3. Examine the Immediate
Dim swApp As SldWorks.SldWorks
Dim swModel As
Dim config As SldWorks.Configuration
Dim cusPropMgr As
Dim lRetVal As Long
Dim vPropNames As
Dim vPropTypes As Variant
Dim vPropValues As Variant
Dim ResolvedValOut As String
Dim wasResolved As Boolean
resolved As Variant
Dim nNbrProps As Long
Dim j As Long
custPropType As Long
Set swApp = Application.SldWorks
Set config =
Set cusPropMgr = config.CustomPropertyManager
lRetVal = cusPropMgr.Add3("ADATE",
cusPropMgr.Get5("ADATE", False, ValOut, ResolvedValOut,
lRetVal = cusPropMgr.Set2("ADATE", "4-13-89")
' Get the number of custom properties for this
nNbrProps = cusPropMgr.Count
"Number of properties for this configuration: " &
' Get the names of the custom properties
cusPropMgr.GetAll2(vPropNames, vPropTypes, vPropValues, resolved)
' For each custom property, print its type, value, and
For j = 0 To nNbrProps - 1
Debug.Print " Name,
swCustomInfoType_e value, and resolved value: " & vPropNames(j) & ", ";
custPropType & ", " & ResolvedValOut
lRetVal = cusPropMgr.Delete2("ADATE")
the number of custom properties for this configuration
Debug.Print "Number of properties for this
configuration: " & nNbrProps