Jump to content
Zyga

Using SolidWorks API

Recommended Posts

Hi Everyone.
As in topic, i try to use SolidWoks API, but I cannot proper open reference to any object (via constructor node and creating static ref).
Im getting error: "Error 1172 occurred at Property Node (Arg :1) Error accessing property SolidWorks.Interop.sldworks.ISldWorks.ActiveDoc, (System.ArgumentNullException: Key cannot be null.
Parameter name: key)"

It's no matter if i load assembly from GAC or directly from project directory. Always the same.
I've tried every idea i had.
Can anyone help me with this?
I enclose API (.net 4.0) for those, who want to help.
Thanks a lot!
Zyga

SW_API.zip

Share this post


Link to post
Share on other sites

Accessing .NET components without any documentation is like looking for a needle in a haystack...

My guess is that you try to access a property which requires you to do something beforehand (like loading a document, or assigning that mysterious 'key')

Could you provide your current implementation?

Maybe even an example of what you are trying to do in a .NET language (some sort of example code)?

Share this post


Link to post
Share on other sites

There is online documentation under this adress.
For now i just want to create top-level object ISldWorks from SolidWorks.Interop.sldworks.dll and for example, simply call RevNumber() method. Same action in Visual Studio works fine.

 

Sub Main()
        Dim app As SldWorks = CreateObject("SldWorks.Application")
        Dim revNmb As String = app.RevisionNumber
    End Sub

Only thing i did is to add SolidWorks.Interop.sldworks.dll to a reference library.

In LabView i acces to a ISldWorks class by creating .net referece and manually browsing to dll (static class? Not sure that is proper naming). As a result is empty reference.
xjzcDxTO.png

By the way, thanks for reply!

Share this post


Link to post
Share on other sites

For now i just want to create top-level object ISldWorks from SolidWorks.Interop.sldworks.dll and for example, simply call RevNumber() method. Same action in Visual Studio works fine.

ISldWorks is an interface that does not actually implement any code and therefore has no functionality. You would have to implement that interface yourself in order to provide any functionality. Since that is the case, an implementation in LabVIEW is impossible (you cannot implement .NET interfaces in LabVIEW)

 

Sub Main()

        Dim app As SldWorks = CreateObject("SldWorks.Application")

        Dim revNmb As String = app.RevisionNumber

End Sub

This is an example in VB where you create an instance from SldWorks.Application which is an ActiveX object!

In order to create an ActiveX instance use the function from following palette: Connectivity >> ActiveX >> Automation Open

Create a constant as input and choose 'Select ActiveX Object'. You'll get a list of available ActiveX-Objects (this of course requires you to actually have them installed)

You should definately look into that, but this has absolutely nothing to do with your .NET assemblies!

 

Only thing i did is to add SolidWorks.Interop.sldworks.dll to a reference library.

In LabView i acces to a ISldWorks class by creating .net referece and manually browsing to dll (static class? Not sure that is proper naming). As a result is empty reference.

xjzcDxTO.png

By the way, thanks for reply!

Your basic approach is okay, but whenever you want to use an object, you have to create an instance of it (or have a function return it). You only provided a constant that defines the type and no instance. This is very difficult for me to describe, so here is an example:

 

post-17453-0-23802900-1406223871_thumb.p

Try this out, it works :D

 

EDIT: Before I forget, I found a link to a document which describes some detailes to the interface mentioned ealier: http://sw.fcsuper.com/index.php?name=UpDownload&req=getit&lid=157

Edited by LogMAN
  • Like 1

Share this post


Link to post
Share on other sites

Right, but Constructor Node says that ISldWorks class has no public constructors. I assume that IsldWorks class is an abstract class. A Few weeks ago I faced the same problem. How to use .net abstract class in LV and I did that just by creating .net reference and pointinting that specific class. Im not real OO developer so my reasoning and might be wrong but it worked.

 

Thanks to your tips i came across on information that i can create some wrapper in c# that could return proper reference. Do you think it is possible and it could work?

 

 

Edited by Zyga

Share this post


Link to post
Share on other sites

Yes, interfaces cannot be instanciated. You can find a good explaination on interfaces & abstract classes here: http://stackoverflow.com/a/1913185

Anyways, you could create your own implementation of ISldWorks in C#, build the .NET assembly and call it from LabVIEW. Depending on what you try to archive it might be easier to stick to C# entirely.

Share this post


Link to post
Share on other sites

Stick to C# entirely is nat an option for me (at least for now). I don't know c#. But i'm familiar enough with labview to do things i want to do. I'll do some test and we will see.
Thanks for help and for useful references. If I handle with this I'll post my solution.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Similar Content

    • By studiobods
      Hello,
      Does anyone know how to get progress when building an EXE with Application Builder API?
      I am using the code below to automate my work and it would be nice to see a progress bar like when you build your application from the LV Project.
       

       
       
      I've found a VI called "Create progressbar events.vi" but I don't know what it does and how to use it.
           
      Thanks a lot for help.
       
      Matthias.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.