Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Properties Issue

Status
Not open for further replies.

dogarila

Mechanical
Oct 28, 2001
594
0
0
CA
What should I do to make the custom properties "stick" to a SW file?

I have this issue since SW2007 SP2.2. I am using now SW2008 SP3.0

I use a VB6 macro to add the custom properties to assemblies and parts so they would show up in the BOM. For some unknown reason after I close the files their custom properties are sometimes deleted although I made sure they were properly saved. Sometimes they are saved. When I open the files next times their properties are not there and the drawing of the assembly shows just blank cells in the BOM.

I don't have this problem if I enter the properties manually in the custom properties window.

Did anyone experience something like this?
 
Replies continue below

Recommended for you

The add command does not overwrite existing properties. You need to use another command to change the property if it already exists.

Usually I hit a property change twice, once with add & once with change.
 
I am using SW since 2001. Prior to 2007 this macro was working flawlessly. I rewrote it in 2007 when it started to give me problems. I updated all obsoleted methods with the newest ones but it did not fix the problem. As I said most of the times it works. But sometimes it is just like this:

1. Open the part
2. Run the macro
3. Enter the custom properties
4. Exit the macro
5. Save the part
6. Close the part
7. Open the assembly drawing
8. Check the BOM. It is updated
9. Save the drawing
10. Close the drawing
11. Open the part
12. Check the properties. They are gone. Not just blank or empty but gone completely as if they were never there.

Funny, eh!
 
I am guessing here.
Are you reading the data?
e.g. Description = Part.CustomInfo("Description")
Are you deleting the data?
e.g. RetVal = Part.DeleteCustomInfo("Description")
Are you setting the data?
e.g. txtDescription.Text = Description
Are you then Adding the data?
e.g. RetVal = Part.AddCustomInfo("Description", "Text", UCase$(txtDescription.Text))

Bradley
SolidWorks Pro 2008 x64, SP4.0EV2
PDMWorks Workgroup, SolidWorks BOM,
Dell XPS Intel(R) Pentium(R) D CPU
3.00 GHz, 5 GB RAM, Virtual memory 10240 MB,
nVidia Quadro FX 3400
e-mail is Lotus Notes
 
It depends on how you are handling your custom properties within the macro. Your processes may not be robust enough. Bradley's questions are a guide to build a robust method to handling the values.

Heck, even your forms may be the issue. If you aren't closing our the form correctly, it could trigger your work not to be implemented.

One way to test how your macro is working is to msgbox's throughout the code to show you when a value for a custom property is set (real) and when it is not. Add label fields that allow you to see the evaluated value. Just ideas.

Here's a custom property macro that is working on 2007 (and presumably on 2008):
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
 
How are you attaching to SolidWorks with your "macro"? You say it is a "VB6 macro", but I believe "VB6" and "macro" are mutually exclusive. If you are using a separate VB6 program, could it be possible that the method you use to attach to SolidWorks (a GetObject or CreateObject type function) is not attaching properly? Like creating some new, non-visible instance of SW or something like that? Working on and saving the same file in two separate instances of SW could cause some weird stuff to happen.

-handleman, CSWP (The new, easy test)
 
handleman said:
You say it is a "VB6 macro", but I believe "VB6" and "macro" are mutually exclusive.
Then it is a exe file. The source is a VB6 program.
fcsuper said:
One way to test how your macro is working is to msgbox's throughout the code to show you when a value for a custom property is set (real) and when it is not. Add label fields that allow you to see the evaluated value. Just ideas.
The properties are set, they show in the BOM. They just don't save with the file.

I am attaching the program to this post. Please take a look at it. It may not be the nicest program out there but I am pretty sure my process is correct.
 
 http://files.engineering.com/getfile.aspx?folder=cc1517e8-ffb6-402a-a034-abb0e5297dbb&file=Custom_Properties.zip
I get
"Run-time error '62':

Input past end of file

It doesn't seem to do anything at all. I can put values in all the boxes, but Apply and Apply and Exit don't put any new custom properties into my file.

I can't really do any debug or anything because I don't have VB6.

Incidentally, any particular reason you used VB6 instead of a VBA macro? Just for curiosity's sake.

-handleman, CSWP (The new, easy test)
 
Oops,

I think I have a bug I never fixed and it gives errors with short file names. Rename your part something like 1111-11-11.

There is a data file I forgot to include in the zip file. Take it from here and put it in C:\

handleman said:
Incidentally, any particular reason you used VB6 instead of a VBA macro? Just for curiosity's sake.
I started seven years ago as an exercise in VB6. I kept using it over the years and adding more features. It was covenient because I could easily modify it to adapt it to the standard of the company I was working for. I changed five work places since then.

I want to transfer it to VBA but never got time to do it. I also want to get rid of the forms and use the property manager window.
 
 http://files.engineering.com/getfile.aspx?folder=6ff9f636-248d-446c-94e7-215c3658a8b9&file=CustomProperties.txt
No bother with the Property Manager. Forms is better. I use the property manager for rarely used/one time use custom properties. The properties used daily are better managed with a custom VBA macro or VB6 program with forms. The property manager has limitations that I could never understand. Like, why doesn't it allow you to enter nothing as a value? Why doesn't it allow you to copy properties and their values from document to document? Stuff like that.

Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
 
I believe he's talking about a custom Property Manager page. You know, like the kind that covers the design tree to allow you to make selections and enter parameters during feature creation. Not the File->Properties dialog.

-handleman, CSWP (The new, easy test)
 
Since many people can't see Visual Basic programs I am posting here the "Apply_Click" subroutines. Please let me know if you see anything wrong:

Code:
Private Sub cmd_Apply_Click()
Dim dblDensity As Double, strMassProp As String, strTemp As String
' on selection of Apply or Exit & Save button delete existing custom properties
' and recreate with new values

If chkStore.Value = 1 Then Call cmdStore_Click

'Deleting all custom properties to keep files clean

       'from part and assembly
        retval = swCustPropMgrPP.Delete("Title")
        retval = swCustPropMgr.Delete("Title")
        retval = swCustPropMgr.Delete("Machine")
        retval = swCustPropMgr.Delete("Description")
        retval = swCustPropMgr.Delete("Description_1")
        retval = swCustPropMgr.Delete("Vendor")
        retval = swCustPropMgrPP.Delete("Weight")

        retval = swCustPropMgr.Delete("Material")
        retval = swCustPropMgr.Delete("Finish")
        retval = swCustPropMgr.Delete("HeatTreatment")

        retval = swCustPropMgr.Delete("Designby")
        retval = swCustPropMgr.Delete("DesignDate")
        retval = swCustPropMgr.Delete("Design")
        retval = swCustPropMgr.Delete("Design_Date")
        retval = swCustPropMgr.Delete("CatName")
        retval = swCustPropMgr.Delete("Catno")
        retval = swCustPropMgr.Delete("O'Hara_PartNumber")
        'if $_Part_Type present delete it
        retval = swCustPropMgr.Delete("$_Part_Type")
        
        'from purchase part
        retval = swCustPropMgrPP.Delete("Supplier_No")
        retval = swCustPropMgrPP.Delete("VendorNo")
        retval = swCustPropMgr.Delete("Supplier")
        retval = swCustPropMgrPP.Delete("O'Hara_PartNumber")
Select Case sCatg
    Case "PART"
           
        'Adding new values to the part custom properties.
        strTitle = UCase(txtTitle.Text)
        retval = swCustPropMgr.Add2("Description", swCustomInfoText, strTitle)
        
        retval = Part.SetMaterialPropertyName(sMatDB, UCase(cboMaterial.Text))
        If Not retval Then retval = Part.SetMaterialPropertyName("solidworks materials.sldmat", UCase(cboMaterial.Text))
        If Not retval Then retval = Part.SetMaterialPropertyName("ss solidworks materials.sldmat", UCase(cboMaterial.Text))
        
        If retval Then
                strTemp = Chr(34) & "SW-Material@" & doctitle & Chr(34)
                   Else
                strTemp = UCase(cboMaterial.Text)
'                retval = Part.RemoveMaterialProperty()
        End If
        retval = swCustPropMgr.Add2("Material", swCustomInfoText, strTemp)
        retval = swCustPropMgr.Add2("Machine", swCustomInfoText, UCase(cboMachine.Text))
        retval = swCustPropMgr.Add2("Finish", swCustomInfoText, UCase(cboFinish.Text))
  
        retval = swCustPropMgr.Add2("Designby", swCustomInfoText, UCase(cboDesignBy.Text))
        retval = swCustPropMgr.Add2("DesignDate", swCustomInfoText, UCase(txtDesignDate.Text))
          
        retval = swCustPropMgr.Add2("O'Hara_PartNumber", swCustomInfoText, UCase(txtOHARAPN.Text))
'end of part processing
'start assembly
    Case "ASSEMBLY"
         
        'Adding new values to the part custom properties.
        strTitle = UCase(txtTitle.Text)
        retval = swCustPropMgr.Add2("Description", swCustomInfoText, strTitle)
        retval = swCustPropMgr.Add2("Machine", swCustomInfoText, UCase(cboMachine.Text))
 
        retval = swCustPropMgr.Add2("Material", swCustomInfoText, UCase(cboMaterial.Text))
        retval = swCustPropMgr.Add2("Finish", swCustomInfoText, UCase(cboFinish.Text))

        retval = swCustPropMgr.Add2("Designby", swCustomInfoText, UCase(cboDesignBy.Text))
        retval = swCustPropMgr.Add2("DesignDate", swCustomInfoText, UCase(txtDesignDate.Text))
        retval = swCustPropMgr.Add2("O'Hara_PartNumber", swCustomInfoText, UCase(txtOHARAPN.Text))
'end assembly processing

'start purchase part
    Case "PURCHASE"

        'Adding new values to the part custom properties.
        retval = swCustPropMgr.Add2("$_Part_Type", swCustomInfoText, "P")
        retval = swCustPropMgr.Add2("Supplier", swCustomInfoText, UCase(cboSupplier.Text))
        retval = swCustPropMgr.Add2("Description", swCustomInfoText, UCase(txtPartName.Text))
        retval = swCustPropMgrPP.Add2("VendorNo", swCustomInfoText, UCase(txtSuppPartNo.Text))
        retval = swCustPropMgrPP.Add2("O'Hara_PartNumber", swCustomInfoText, UCase(txtOHARAPNPP.Text))
        'add material if requested
        If chkAddMat.Value = 1 Then
        retval = Part.SetMaterialPropertyName(sMatDB, UCase(cboMatPP.Text))
        If Not retval Then retval = Part.SetMaterialPropertyName("solidworks materials.sldmat", UCase(cboMatPP.Text))
        If Not retval Then retval = Part.SetMaterialPropertyName("ss solidworks materials.sldmat", UCase(cboMatPP.Text))
        
        If retval Then
                strTemp = Chr(34) & "SW-Material@" & doctitle & Chr(34)
                   Else
                strTemp = UCase(cboMatPP.Text)
'                retval = Part.RemoveMaterialProperty()
        End If
        retval = swCustPropMgr.Add2("Material", swCustomInfoText, strTemp)
        End If
        
        Set Config = Part.GetActiveConfiguration()
        Config.AlternateName = UCase(txtSuppPartNo.Text)  ' make " " for blank in part no.
        Config.UseAlternateNameInBOM = True

        
'end processing purchase part

End Select
retval = Part.EditRebuild3

End Sub
 
Without looking indepth, just as structure, I wouldn't recommend putting all your eggs in one basket. There's a lot going on with the click of your apply button that I would prefer handling on form loading or even in the main module (some before loading of form, some after). This would be just my preference and may have nothing to do with why the code isn't work.

Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
 
Status
Not open for further replies.
Back
Top