API - Access the User Specified Name

Jun 17, 2004 4 Replies

We have a fairly involved program here that allows the user to select a particular material from a cascading type of list structure and go all the way to a unique ASI part number. Then if in SW, the info such as part number, description, etc can be inserted into the currently open part. As it was written years ago, it puts that info into the custom properties area of the SW part, and at this time I want to change it so it puts it into config specific areas instead. I can get it to access the config specific properties, but can't seem to figure out how to get & write to the User Specified Name in the properties box under the Part number displayed when used in a bill of materials.



I have pasted in my test code here so you can see what I have tried. Anybody see my error and can offer some assistance, please?



Dim swApp As Object Dim Part As Object Dim boolstatus As Boolean Dim SwConfig As SldWorks.Configuration Dim ConfigName As String Dim AltName As Variant Dim ConfigDesc, ConfigLength As String



Sub main() Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc



Set SwConfig = Part.GetActiveConfiguration ConfigName = Part.GetActiveConfiguration.Name



boolstatus = True SwConfig.UseAlternateNameInBOM = boolstatus ....This next line is the bad line. AltName = Part.SwConfig.alternateName ConfigDesc = Part.CustomInfo2(ConfigName, "Description") ConfigLength = Part.CustomInfo2(ConfigName, "Length")



End Sub


WT


for some reason, you have to create the property first with Part.AddCustomInfo3 ( ConfigName, "Description", swCustomInfoText, FieldValue )

then you can read/write it with CustomInfo2 the way you did.

I figured out my error to actually access the property (remove the Part from the line AltName = Part.SwConfig.alternateName) but now I can't get the UseAlternateNameInBOM to toggle on. If it's off in the part, then regardless of my setting in the code, it stays false. Here's my line:

SwConfig.UseAlternateNameInBOM = True

What am I missing?

WT

Wouldn't this just add another custom property, rather than writing to the User Specified Name so it shows up in the BOM? Also, see my second post . Thanks.

WT

Next installment. I sort of got it to work, but not sure why - here is the relevant line.

Part.EditConfiguration ConfigName, ConfigName, "", AltName, 1, 0, 0, 1, 385

"ConfigName" is the variable used to pass the name of the current config. "AltName" is the string (our ASI part number) I am putting in the User Specified Name position to be used in the BOM. I have figured out that the first 1 checks the box for suppressing features. The other 1's & 0's I can't see making any changes. The last number appears to need to be 385 in order to enable the User Specified Name option.

I got this by recording a macro and changing the variables. EditConfiguration doesn't come up in the help - only EditConfiguration3, but that didn't work because of wrong number of arguments as I had recorded. Also note no retval at the beginning & no () around the parameters. I can put in the retval & the () to get a return, but still can't use the EditConfiguration3, and so I still don't really know what the parameters are. The syntax is close, but not quite the same.

Anyone have any insight into this command and anything that would help me?

WT

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required