×
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 use GetTitle()

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

---------------

RE: SW API - How do I use GetTitle()

It's hard to tell from your code example and post how to best help you here.  Are you new to object-oriented programming?  It sort of looks like you might be.  Let me know if this is the case and I'll see what I can do to explain.  The API help is really good if you already understand VB/A.  However, if you've been working on this for days it sounds like you could really use an intro tutorial to VB or VBA.  I'm sure Google would turn up a few that could get you started.

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

Private Sub UserForm_initialize()

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

Are you trying to get the name of a part to show in a dwg, or a different type of doc?

Chris
SolidWorks 06 5.1/PDMWorks 06
AutoCAD 06
ctopher's home (updated 01-18-07)

RE: SW API - How do I use GetTitle()

It appears he's trying to put the name of the active document in a text box control on a user form somewhere.  It's not apparent from the code whether the form is part of a SW macro or another program.  The name of the text box (textAC) might indicate Access.

RE: SW API - How do I use GetTitle()

GetTitle returns a string.  You are trying to place the string into an object.  Try placing the result into a string or variant.

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 use GetTitle()

We probably should tell him to use swModelDoc.GetPathName rather than swModelDoc.GetTitle (since that one is dependant on a Windows setting.)

Ken

RE: SW API - How do I use GetTitle()

(OP)
Wow, a lot of you responded pretty quick, thank you. I was afraid no one would read my post.

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

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