SldWorks 2003 Type Library help

Sep 02, 2003 5 Replies

Hi



I have linked to sldworks.tlb from VBA, and I have managed to retrieve named custom properties by using the method



Part.CustomInfo("Material")



where Part is my SolidWorksfile that I currently have open in SW.



Now I want to write to the custom property - and I try to use the method AddCustomInfo - but it doesn't work (I guess I do it wrong..) I also want to open a document by using the method OpenDoc6 - also without success.



Any help?



And where do I find a more detailed description of the methods in the SldWorks 2003 Type Library - like a Help file?



John


I could never get Opendoc 6 to quite work either. I use this successfully

swApp.OpenDoc4 FileName, 2, 0, ConfigName, longstatus

CustomInfo has been discussed many times in the past. If yousearch for it in this group @ Google you will find the answers you are looking for.

formatting link
if you go to this link you can search this usergroup for anything that has been discussed for the last couple of years even.

Here is a bit of code that should get you going Remember that custom info is case sensitive. If you have old drawings that case wasn't controlled in you might have to make provisions. What worked for me was to delete the custom prop that I wanted to replace and then start from scratch. This was the only way I could change a custom field that was already there.

'if you declare your swApp and Part variables like this it will help you know what options you have for each object.

Dim swApp As SldWorks.SldWorks Dim SetPart as SldWorks.ModelDoc2 Dim Description as String Dim Material As String

Set swApp = Application.SldWorks

Set SetPart = swApp.ActiveDoc

Description = "My Custom Description"

Material = "My Custom Material

partTitle = SetPart.GetTitle If Description = "" Then 'nothing Else 'delete the old description retval = SetPart.DeleteCustomInfo2("", "Description") 'Just incase it was set with caps on delete it that way too retval = SetPart.DeleteCustomInfo2("", "DESCRIPTION") 'add the new custom info 30 stands for the text type of field retval = SetPart.AddCustomInfo3("", "Description", 30, Description) 'delete custom info for configuration specific retval = SetPart.DeleteCustomInfo2("Default", "Description") 'just incase retval = SetPart.DeleteCustomInfo2("Default", "DESCRIPTION") 'set config specific custom info 30 stands for the text type of field retval = SetPart.AddCustomInfo3("Default", "Description", 30, Description) End If If MaterialNo = "" Then Else retval = SetPart.DeleteCustomInfo2("", "Material#") retval = SetPart.DeleteCustomInfo2("", "MATERIAL#") retval = SetPart.AddCustomInfo3("", "Material#", 30, MaterialNo) retval = SetPart.DeleteCustomInfo2("Default", "Material#") retval = SetPart.DeleteCustomInfo2("Default", "MATERIAL#") End If

'I found that if you wanted a custom info with multiple lines you could set a multiline string to it so I made a second description that could have 2 lines. This one I knew wouldn't have been set by anyone so I didn't have to worry about case. If Description2 = "" Then 'Nothing Else retval = SetPart.DeleteCustomInfo2("", "Description2") retval = SetPart.AddCustomInfo3("", "Description2", 30, Description2) End If

Corey It works! Thanks.

How do I know that "30" is the text type... and what if I want another type?

John

formatting link

C:\Program Files\SolidWorks\samples\appComm\swConst.bas

search for the word "Custom"

you can do one of 2 things you can import it into your project or search it for the value you want. In this case i didn't add it to my project I searched for the value.

' use the same call- one version GETS the property, one ver SETS the property Part.CustomInfo("","Material") = "4140" ' for all configs Part.CustomInfo("Default","Material") = "4140" ' for config named "Default"

exactly... use the help file! I use the Object browser to help FIND a command, but then back reference to the help file tp get the specifics of the command.

Join the Discussion

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

Didn't find your answer?

Ask the community — no account required