Jump to content

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

Link to comment

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

Link to comment

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!

Link to comment

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
Link to comment

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
Link to comment

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.

Link to comment

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.

Link to comment

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...

Important Information

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