SW API - How do I Remove All Properties in a Document?
SW API - How do I Remove All Properties in a Document?
(OP)
Hey Guys,
I need some help. I have a form with 3 Radio buttons.
Radio Buttions:
1. Document Properties
2. Configuration Properties
3. Both
And one CommandButton, "removeButton" all on a form. My aim is to be able to remove all properties from either Document Properties, Configuration Properties, or all Properties in Document. I am kinda new to programming and have tried looking through the Help Document, but can't figure this one out. Guys, please, can you help me figure this one out... what is wrong with my code?
Private Sub removeButton_Click()
Dim strConfiguration As String
Set swApp = Application.SldWorks
Set swModelDoc = swApp.ActiveDoc
strConfiguration = GetActiveConfiguration(swModelDoc)
If optDocPrp = True Then
' 'REMOVE DOC PROPERTIES LOOP
' Dim arDocPrpNames As Variant
'
' arDocPrpNames = swModelDoc.GetCustomInfoNames2("")
' MsgBox (arDocPrpNames(0))
'
' For i = 0 To arDocPrpNames.Length
' swModelDoc.DeleteCustomInfo2 "", arDocPrpNames(i)
' MsgBox i & " Document Properties Deleted"
' Next
ElseIf optConfigPrp = True Then
'REMOVE CONFIG PROPERTIES LOOP
Dim arConfigPrpNames As Variant
arConfigPrpNames = swModelDoc.GetCustomInfoNames2(strConfiguration)
MsgBox (arConfigPrpNames(0))
For i = 0 To arConfigPrpNames.Length
swModelDoc.DeleteCustomInfo2 "", arConfigPrpNames(i)
MsgBox i & " Configuration Properties Deleted"
Next
Else
'Remove Both Configuration and Document Properties
End If
End Sub
I need some help. I have a form with 3 Radio buttons.
Radio Buttions:
1. Document Properties
2. Configuration Properties
3. Both
And one CommandButton, "removeButton" all on a form. My aim is to be able to remove all properties from either Document Properties, Configuration Properties, or all Properties in Document. I am kinda new to programming and have tried looking through the Help Document, but can't figure this one out. Guys, please, can you help me figure this one out... what is wrong with my code?
Private Sub removeButton_Click()
Dim strConfiguration As String
Set swApp = Application.SldWorks
Set swModelDoc = swApp.ActiveDoc
strConfiguration = GetActiveConfiguration(swModelDoc)
If optDocPrp = True Then
' 'REMOVE DOC PROPERTIES LOOP
' Dim arDocPrpNames As Variant
'
' arDocPrpNames = swModelDoc.GetCustomInfoNames2("")
' MsgBox (arDocPrpNames(0))
'
' For i = 0 To arDocPrpNames.Length
' swModelDoc.DeleteCustomInfo2 "", arDocPrpNames(i)
' MsgBox i & " Document Properties Deleted"
' Next
ElseIf optConfigPrp = True Then
'REMOVE CONFIG PROPERTIES LOOP
Dim arConfigPrpNames As Variant
arConfigPrpNames = swModelDoc.GetCustomInfoNames2(strConfiguration)
MsgBox (arConfigPrpNames(0))
For i = 0 To arConfigPrpNames.Length
swModelDoc.DeleteCustomInfo2 "", arConfigPrpNames(i)
MsgBox i & " Configuration Properties Deleted"
Next
Else
'Remove Both Configuration and Document Properties
End If
End Sub






RE: SW API - How do I Remove All Properties in a Document?
What kind of error message are you getting? That may help you figure it out!
SA
RE: SW API - How do I Remove All Properties in a Document?
Now that it is later in the day, I had a chance to look over (and run) your code. One question to first: What version of VB are you programming with as I am not familar with the .Length after the arDocPrpNames and arConfigPrpNames?
First, because I could not use the .Length with VBA, I had to change your code to use the UBOUND function. Next, since you did not supply the code for the GetActiveConfiguration procedure, I had to write my own routine. I also un-commented the code under If optDocPrp = True Then to see if that worked (although I assume you commented it out because you knew that this code worked as is). Now to answer your question. The problem with the code is that under ElseIf optConfigPrp = True Then you did not specify the configuration name for the configuration parameter in the swModelDoc.DeleteCustomInfo2 line. It was trying to delete the custom properties under the Custom tab and not the Configuration Specific tab. Below is your code with my changes in red. I tested it a couple of times with no problems.
SA
CODE
Dim strConfiguration As String
Set swApp = Application.SldWorks
Set swModelDoc = swApp.ActiveDoc
'strConfiguration = GetActiveConfiguration(swModelDoc)
strConfiguration = swApp.GetActiveConfigurationName(swModelDoc.GetPathName)
If optDocPrp = True Then
'REMOVE DOC PROPERTIES LOOP
Dim arDocPrpNames As Variant
arDocPrpNames = swModelDoc.GetCustomInfoNames2("")
MsgBox (arDocPrpNames(0))
For i = 0 To UBound(arDocPrpNames)
swModelDoc.DeleteCustomInfo2 "", arDocPrpNames(i)
MsgBox i & " Document Properties Deleted"
Next
ElseIf optConfigPrp = True Then
'REMOVE CONFIG PROPERTIES LOOP
Dim arConfigPrpNames As Variant
arConfigPrpNames = swModelDoc.GetCustomInfoNames2(strConfiguration)
MsgBox (arConfigPrpNames(0))
For i = 0 To UBound(arConfigPrpNames)
swModelDoc.DeleteCustomInfo2 strConfiguration, arConfigPrpNames(i)
MsgBox i & " Configuration Properties Deleted"
Next
Else
'Remove Both Configuration and Document Properties
End If
End Sub
RE: SW API - How do I Remove All Properties in a Document?
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: SW API - How do I Remove All Properties in a Document?
RE: SW API - How do I Remove All Properties in a Document?
I am slightly confused because when I check the Help Doc for that Method it states this:
===============================
Description
This method returns the names of the custom information defined in the document OR a specified configuration.
Syntax (OLE Automation)
retval = ModelDoc2.GetCustomInfoNames2 ( configuration )
Input:
(BSTR) configuration
Name of the configuration
Return:
(VARIANT) retval
SafeArray containing the names of the custom information
=============================
There was another Method I used to a get property and it said that to select the Custom Document Property, for the Configuration area, simply put double quotes "" and it will know. But with that method, I would already have to know the property name in order to get it. But that is not what I want.
Thanks again for the code, it works for the Configuration Removal, but the Doc one has problems.
RE: SW API - How do I Remove All Properties in a Document?
Run-time error '9': Subscript out of range!
I'll sift through and study your code later. I like your web site, very useful.
Thanks,
Pyroclasm
RE: SW API - How do I Remove All Properties in a Document?
RE: SW API - How do I Remove All Properties in a Document?
What kind of error message were you getting when you ran my revised code? Like with Tick's program, I did not have a problem running my code. It deleted the custom properties in both the custom and configuration tabs.
SA
RE: SW API - How do I Remove All Properties in a Document?
Ok, there must be something wrong with my computer at work. SolidAir, your code works perfectly at home. But at work I get an error, I don't remeber the exact error, but I'll post it tomarrow when I am in the office. Other than that it works well.
Heres my finished code:
---------------------------------------------
Private Sub removeButton_Click()
Dim strConfiguration As String
Set swApp = Application.SldWorks
Set swModelDoc = swApp.ActiveDoc
'strConfiguration = GetActiveConfiguration(swModelDoc)
strConfiguration = swApp.GetActiveConfigurationName(swModelDoc.GetPathName)
If optDocPrp = True Then
'REMOVE DOC PROPERTIES LOOP
Dim arDocPrpNames As Variant
arDocPrpNames = swModelDoc.GetCustomInfoNames2("")
For i = 0 To UBound(arDocPrpNames)
swModelDoc.DeleteCustomInfo2 "", arDocPrpNames(i)
MsgBox arDocPrpNames(i) & " - Document Property Deleted"
Next
ElseIf optConfigPrp = True Then
'REMOVE CONFIG PROPERTIES LOOP
Dim arConfigPrpNames As Variant
arConfigPrpNames = swModelDoc.GetCustomInfoNames2(strConfiguration)
For i = 0 To UBound(arConfigPrpNames)
swModelDoc.DeleteCustomInfo2 strConfiguration, arConfigPrpNames(i)
MsgBox arConfigPrpNames(i) & " Configuration Properties Deleted"
Next
Else
'Remove Both Configuration and Document Properties
'REMOVE DOC PROPERTIES LOOP
Dim arDocPrpNames1 As Variant
arDocPrpNames1 = swModelDoc.GetCustomInfoNames2("")
For i = 0 To UBound(arDocPrpNames1)
swModelDoc.DeleteCustomInfo2 "", arDocPrpNames1(i)
MsgBox arDocPrpNames1(i) & " - Document Property Deleted"
Next
'REMOVE CONFIG PROPERTIES LOOP
Dim arConfigPrpNames1 As Variant
arConfigPrpNames1 = swModelDoc.GetCustomInfoNames2(strConfiguration)
For i = 0 To UBound(arConfigPrpNames1)
swModelDoc.DeleteCustomInfo2 strConfiguration, arConfigPrpNames1(i)
MsgBox arConfigPrpNames1(i) & " - Configuration Property Deleted"
Next
End If
End Sub
------------------------------------
As for TheTick, I dunno, I tried your form on my computer at home too and I got the same error message. I am running SolidWorks 2006 with the VB that comes with the program. :(
Thanks guys, you really know your coding.
RE: SW API - How do I Remove All Properties in a Document?
RE: SW API - How do I Remove All Properties in a Document?
SW07 SP2.0
Flores
RE: SW API - How do I Remove All Properties in a Document?
Thanks again guys for all your help.
Pyroclasm
RE: SW API - How do I Remove All Properties in a Document?
Regards,
Regg