Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Is it possible to use APIs... in VBScript

Status
Not open for further replies.

CubeE101

Programmer
Nov 19, 2002
1,492
US
Is it possible to use APIs to connect to other programs in VBScript?

such as the following code for VB:

Dim swApp As Object
Dim Model As Object, Drawing As Object, Sheet As Object
Const swDocPART = 1, swDocASSEMBLY = 2, swDocDRAWING = 3
Set swApp = CreateObject("SldWorks.Application")
Set Model = swApp.ActiveDoc
Set Drawing = Model
Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
how???
HOW DO YOU SET OBJECTS???
THERE IS NO OBJECT TYPE... IS THERE? Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
It seems to all be done through late binding - I have only tested this with Microsoft applications but this little bit of code interacts with Word 9.0 object model.

Set MyWord = CreateObject("word.application")
Set MyDocument = MyWord.Documents.Open("c:\A.doc")
MsgBox MyDocument.FullName

I personally don't bother with DIMs in any of my VBScripts.

-Sunny
 
VBScript does not directly support API's. It utilizes COM objects instead. The office calls work because they are calling the office COM object.

For example, you cannot call the NETAPI32.dll because this is strictly an API with no COM equivelant.

The only way to get API's to work with VBScript is to create an activex dll in VB or C/C++ that uses the API calls. Another tread you might try is
There's some good information in here on how to go about doing this.

Dana Hallenbeck
 
Ok...
Solidworks API includes
OLE (VB5/6) support
-AND-
COM support (for VC++)

so you all are saying to use the COM side of the API interface?

And forget about the Dim ... as Object?

clip from Solidworks API help...
COM vs. Dispatch
SolidWorks exposes its API functionality through standard COM objects. For OLE automation, the API is exposed using IDispatch.

The Dispatch interface accepts and returns arguments as Variants and IDispatch pointers so they can be handled by languages such as Basic. All Visual Basic, VBA, or VC++ executable (.exe) implementations should use the Dispatch interface.

A COM implementation gives your application direct access to the underlying objects or arrays, and, subsequently, increased performance. COM implementations provide slightly more functionality, with operations such as enumeration, and also return an HRESULT value for each API function call. The COM interface is currently only available to VC++ add-in DLL implementations.

The COM interface is recommended for all VC++ add-in DLL projects. If your product will be an .exe implementation, then you are required to use the Dispatch interface because custom marshaling is not provided.


Does that tell you anything? Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
I would say try using the COM interface and see where you get. I don't know what objects, properties, or methods are available to SolidWorks...so you may have to get this information from the documentation or from a SolidWorks forum somewhere.

I am unfamiliar with the "Dispatch" interface, so don't really have any constructive input as far as that goes. I have not had to use OLE in a very long time.

Good Luck.

Dana Hallenbeck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top