How do I create an if statement macro that would take my custom property material and add a new custom property line named R/M with a material code.
Ex:
If material =16 CRS
Then R/M = 010132000
I would like the property R/M to be added by the Macro.
How do I create an if statement macro that would take my custom property material and add a new custom property line named R/M with a material code.
Ex:
If material =16 CRS
Then R/M = 010132000
I would like the property R/M to be added by the Macro.
, I don't have a macro answer for you, but this would be very easy to do in Excel. You could make the configuration controlled by a Design Table and then do your if statement there.
Hey Dennis thanks for the timely response
How would configurations work with EPDM?
Do you have an example?
<p>Dim cpm As SldWorks.CustomPropertyManager</p><p> Set cpm = swModelDoc.Extension.CustomPropertyManager("")</p><p>If cpm.Get("material") = "16 crs" Then </p><p> cpm.Add2 "rm", swCustomInfoText, "1234"</p><p>End If</p>When I debug the code I get an error at the (Set cpm = swModelDoc.Extension.CustomPropertyManager(""))
Do you know what I am doing wrong?
If you're using ePDM you could do a list with alias and then populate the data card variables with $token in the input formula.
you need to declare (set) the active document
Thanks so much for all the help. It is still getting hung up in the same spot and this is exactly what I have.
I'm not sure what is going on.
Here are the codes
<p>Option Explicit</p><p>Sub main()</p><p>Dim swApp As SldWorks.SldWorks</p><p>Dim swModel As SldWorks.ModelDoc2</p><p>Dim swCustProp As CustomPropertyManager</p><p>Dim ValOut As String</p><p>Dim ResolvedValOut As String</p><p>Dim wasResolved As Boolean</p><p></p><p>Set swApp = Application.SldWorks</p><p>Set swModel = swApp.ActiveDoc</p><p>Set swCustProp = swModel.Extension.CustomPropertyManager("")</p><p></p><p>swCustProp.Get5 "Material", False, ValOut, ResolvedValOut, wasResolved</p><p>If ResolvedValOut = "16 CRS" Then</p><p> swCustProp.Add3 "R/M", swCustomInfoText, "010132000", 1</p><p>End If</p><p></p><p>End Sub</p>I just tested and it works - see the full macro
<p>Dim swApp As Object</p><p>Dim swModelDoc As SldWorks.ModelDoc2</p><p>Sub main()</p><p></p><p></p><p>Set swApp = Application.SldWorks</p><p>Set swModelDoc = swApp.ActiveDoc</p><p>Dim cpm As SldWorks.CustomPropertyManager</p><p> Set cpm = swModelDoc.Extension.CustomPropertyManager("")</p><p>If cpm.Get("Revision") = "B-01+" Then</p><p> cpm.Add2 "Test", swCustomInfoText, "1234"</p><p>End If</p><p>End Sub</p>Deepak
You're quick !
I've updated the codes removing Obsolete variable and added updated one.
These codes may be fail for material as material is set to part material and your codes may not get the resolved values.
cool - Thx
it works thank you so much do you think i could use this macro on many different parts with different materials? so more if then statments in the same macro?
Yes. You can use something like this (changes as required, just added random values)