SW API - How do I use GetTitle()
SW API - How do I use GetTitle()
(OP)
Can some one please help me, I am new to SW API. I want to be able to Get the File Name of an Active Document in SW to appear in a TextBox. I've tried multiple different variations of the code below, I've been at it for days, but can't figure out why it won't work. What am I overlooking?
Robert
--------------------------------
Private Sub UserForm_initialize()
Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.ModelDoc2
Dim swDocTitle As String
Dim swActiveComponent As String
Set swModelDoc = GetTitle(swDocTitle)
swActiveComponent = swModelDoc
txtAC.Text = swActiveComponent
End Sub
---------------
Robert
--------------------------------
Private Sub UserForm_initialize()
Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.ModelDoc2
Dim swDocTitle As String
Dim swActiveComponent As String
Set swModelDoc = GetTitle(swDocTitle)
swActiveComponent = swModelDoc
txtAC.Text = swActiveComponent
End Sub
---------------






RE: SW API - How do I use GetTitle()
Here are the lines you'll need to add (in bold) in order for this to work. I'm assuming this code is supposed to run inside SolidWorks.
CODE
Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.ModelDoc2
Dim swDocTitle As String
Dim swActiveComponent As String
Set swApp = Application.SldWorks
'If you are running this from Access or some other
'application, you will need to replace the line above with:
'Set swApp = CreateObject("SldWorks.Application")
Set swModelDoc = swApp.ActiveDoc
swDocTitle = swModelDoc.GetTitle
txtAC.Text = swDocTitle
'Set swModelDoc = GetTitle(swDocTitle) 'This line will not work
'swActiveComponent = swModelDoc 'This line will not work
'txtAC.Text = swActiveComponent 'This line will not work
End Sub
RE: SW API - How do I use GetTitle()
Chris
SolidWorks 06 5.1/PDMWorks 06
AutoCAD 06
ctopher's home (updated 01-18-07)
RE: SW API - How do I use GetTitle()
RE: SW API - How do I use GetTitle()
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: SW API - How do I use GetTitle()
Ken
RE: SW API - How do I use GetTitle()
handleman, the code worked perfectly. Sorry for the confusion, I guess I was a little broad. I'm working on making a form for my work that gets/sets information for any component (ASM or PRT) in Solidworks. So idealy I would press a button on the User Interface and the form pops up with the info.
I am new to Visual Basic and had actually bought a really good(expensive) book, but Solidworks API code seems so different. I wondered if reading the book would help. I did some online training at http://www.myigetit.com/ and thought it would be enough to get crack'n with the code.
Thanks everyone for your help.
Robert