Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

API - ReferenceNotFoundNotify

Status
Not open for further replies.

Bouke

Mechanical
Jan 13, 2004
107
in the following example the FileOpenNotify works perfectly but the ReferencenotFoundNotify doesn't seem to work.

Does Anyone have a idea y??

Code:
Public WithEvents swApp As SldWorks.SldWorks

Sub init()
  Set swApp = CreateObject("SldWorks.Application")
  swApp.Visible = True
End Sub

Private Sub Form_Load()
  init
End Sub

Private Function swApp_FileOpenNotify2(ByVal Filename As String) As Long
  MsgBox "File Open Notify"
End Function

Private Function swApp_ReferenceNotFoundNotify(ByVal Filename As String) As Long
  MsgBox "Reference Not Found"
End Function

Regards,

Bouke
 
Replies continue below

Recommended for you

I'm assuming the reference was not found.

What kind of reference was missing when you tested this? Missing component? Missing in-context ref?

One possibility is that your options are not set to load referenced documents. SW is not going to fail to find something its not looking for.

[bat]I could be the world's greatest underachiever, if I could just learn to apply myself.[bat]
-SolidWorks API VB programming help
 
Ok, I will give some more information of the problem. I just got off the phone with my VAR and he couldn't help me so.

I want the macro to trigger when I open a drawings wich has lost its reference to the part/assembly (for example by renaming it) When you open such a drawing normally you get the "File not found, would you like to find it yourself"-dialog box.

Now when I let my macro listen for this event Solidworks wont respond. It doesn't pop up the dialog either. Instead it changes the drawings-views to empty crosses.

But when I open anything It will respond with the fileopen-event.


Me and my Var were able to get it working using VBA, but I really need this in VB6.0

Regards, Bouke
 
Bouke,
I wanted to do this also, but could not figure it out. What I did was put my code into code that most people already use every time they work on a drawing, assembly or part. If you figure this trigger out could you please post it? I would love to incorporate the trigger into my programs.


Bradley
 
I did some quick testing and it looks like (at least with the default installation settings), if SW cannot find the referenced file, it sets it to unresolved instead of triggering the notify flag. Then, when you set it to resolved, the flag is triggered.

Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...
 
I just tested using my own event monitor program. I opened a part drawing with the part file missing. The ReferenceNotFoundNotify triggered fine.

One thing I noticed about events:
If you have too much code responding to a single event, your program can miss other events. It's possible that your MsgBox is drowning out subsequent event calls.

One way around this is to start your code asynchronously. If your code is in a form, you can use a timer. Have the event enable a timer, then have the timer run some code after a minimal wait and then disable itself.

[bat]I could be the world's greatest underachiever, if I could just learn to apply myself.[bat]
-SolidWorks API VB programming help
 
The tick, The code you see above was all the code I used. I tried to change the msgbox's to debug.print but that doesn't change anything. Yesterday I did some more testing and I did sent the VB-project to Solidworks Api Support. Seems they've got it working and my VAR to. There was just 1 little differnence between them and me. They worked with SW2005-SP0.0 and I work with 0.1 so I'm guessing maybe the problem lies in the Service pack. I'm hoping it will be fixed in SP1.0

Bouke Brouwers
Mechanical Engineer
SW2005 SP0.1
 
Interesting - as of about 15 min prior to my post, I was using SP0.0, too. BUT, when I did my testing, I was now running SP0.1.

Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...
 
Then we just have to wait till service pack 1.0 Maybe there is someone with the early visibility Service pack who can test it??

Regards,

Bouke Brouwers
Mechanical Engineer
SW2005 SP0.1
 
OK - something else appears to be going on here. When I run the code against 0.1 and 0.0 with a drawing, it triggers properly (the reference not found flag is thrown instead of the file open). However, when it do it against an assy with a missing reference, I cannot get reference not found to go b/c it just makes the component unresolved.

Is this worth researching further?

Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...
 
Currently I have made a new install of SW2005 on my pc (I used to have one made with an administrative image) so I was able to put the SP1.0 RC over it.

The notify is working fine now. I even found a SPR, but it wasn't a general one so overlooked it the first time.


Bradley, do you still want to know how to use this??

Regards,


Bouke Brouwers
Mechanical Engineer
SW2005 SP0.1
 
Bouke,
Yes, I would like to know how to start a Visual Basic 6 exe program when SolidWorks starts. Currently, what I have to do is start a drawing, then my macro keys will work.


Bradley
 
Look up "ShellExecute" Windows API. This is the API command to kick off a program or open a file in its default app.

[bat]I could be the world's greatest underachiever, if I could just learn to apply myself.[bat]
-SolidWorks API VB programming help
 
This is the code that I tried to make a program start when starting a drawing.

Code:
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
' This program runs when I pushed Ctrl F12 

MyAppID = Shell("\\ServerName\Eng\Applications\SolidWorks\Executables\Titleblock.exe", 1)


Bradley
 
Bradley,

it sounds to me that you want the Titleblock.exe program to run automatically when you start SW.

You could add the following function to your program. Then put it into your init() or main()

Now when you start titleblock.exe it will look for Solidworks 2005. If its not there it will aumatically start SW2005.

So this way you dont need your SW-icon anymore

Code:
Private Function StartSolidWorksAndConnect()
On Error Resume Next
    ' start solidworks
    Set swApp = Nothing
    Set swApp = GetObject(, "SldWorks.Application.13")
    If swApp Is Nothing Then Set swApp = CreateObject("SldWorks.Application.13")
    If Not swApp Is Nothing Then
        swApp.Visible = True
        swApp.UserControl = True
        bReady = True
    End If
End Function

btw, If you work in 2004 you need to change the application number from 13 to 11. I think, I'm not sure on that one though. If its not working, experiment with other numbers below 13

Bouke Brouwers
Mechanical Engineer
SW2005 SP1.0
 
Thanks Bouke,
I will give this a try soon. I do use SolidWorks 2005. This will help a lot in setting the revision on our drawings to our standard. I read our “revision-version” in the format R01-01 and use VB to change it to R01 in our title block.
Thanks again


Bradley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor