×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

SW API - How do I Remove All Properties in a Document?
2

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

RE: SW API - How do I Remove All Properties in a Document?

pyroclasm,

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?

pyroclasm,

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

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("")
            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?

I have a finished product that I never posted.  I will put it on my website freeware section immediately.  I will post back when ready.

batI could be the world's greatest underachiever, if I could just learn to apply myself.bat
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: SW API - How do I Remove All Properties in a Document?

(OP)
Thanks SolidAir. I put the Length property in only because I'm used to coding in Flash and really didn't know what VBA used to do the same thing. Now I know from your example. I commented out the code because it actually caused a conflict. I don't really understand why, but I think it has to do with the "GetCustomInfoNames2("")."

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?

(OP)
Hey TheTick, thanks for the download, but it didn't work. I got an error...

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?

Hmmm.... macro worked fine here.  Written in SW2003, used in SW2004, SW2005, and SW2007.  Never seen a "Run-time error '9'" before.

RE: SW API - How do I Remove All Properties in a Document?

pyroclasm,

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?

(OP)
Hey Guys,

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?

I have not actually tested the macro in SW2006.  I will have to check.

RE: SW API - How do I Remove All Properties in a Document?

TheTick's macro does what you want.  Have you tried Edit Macros (pick macro) > Tools > References > SLDWorks 2006 Type Library?

SW07 SP2.0

Flores

RE: SW API - How do I Remove All Properties in a Document?

(OP)
Hey guys, Some reason its workin' now at work. SolidAir your code works well, thanks. And TheTick, yours works too now, its a pretty neat macro you have there. The Checkbox is a good idea. I don't know why it had problems the other day.

Thanks again guys for all your help.

Pyroclasm

RE: SW API - How do I Remove All Properties in a Document?

While TheTick's program is really cool.  A star to SolidAir for answering pyroclasm's original question of why his program did not work.  Enjoy SolidAir.

Regards,

Regg

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources