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!

IÆm almost embarrassed to ask (SW API and VB6)

Status
Not open for further replies.

charbroil

Aerospace
Jul 23, 2004
29
I need to pose a simple question about API programming with VB6.

I want to write a larger macro, but am so rusty with VB programming that I am inching through, recording only snippets at a time and analyzing the code. When I record a macro and try to play it back, I get errors that I don’t expect.

For instance, I have a blank drawing and I record a macro that creates a new sheet. Then I delete the new sheet and play the macro. I get Run Time Error 450 (Wrong number of arguments or invalid property assignment) on the line I bolded:


Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim FeatureData As Object
Dim Feature As Object
Dim Component As Object
Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("###", "SHEET", 0.02101312365445, 0.1932208491231, 0, False, 0, Nothing, 0)
Part.ClearSelection2 True
Part.NewSheet3 "Sheet2", 12, 12, 1, 1, False, "npi_title-block_sizeA.slddrt", 0.2794, 0.2159, "Default", True
End Sub


What exactly is wrong with that and why wouldn’t it be correctly structured straight from the recorder?

I’m sorry if this is soooo basic. I have put in for an API training class, but it may not happen for months.


System: Dell Precision 650—Intel Xeo @ 2.66 GHz with 1/2G RAM
OS: Windows 2000 SP3
Graphics: NVidia Quadro FX 500 128Mb (OpenGL set to Solidworks)
Version: Solidworks 2005, SP0
 
Replies continue below

Recommended for you

I’m no stranger to programming languages and am not intimidated by tackling something new. A few years ago, I learned VB just long enough to complete a project for a friend, then promptly forgot most of the basics.

Here’s the reasoning behind that question above, without getting too bogged down in details:

I have an Assembly with 10 configurations.
I will eventually make a Drawing file that has 10 sheets, one for each configuration.

This can get rather tedious, adding the sheet, inserting the view(s), and changing the configuration in the view property (or switching to the Assembly and changing config, then changing back to add the sheet).

It’s tailor made for automation because I work with files like this daily.

From the looks of things, I need to:

Get the Assembly name
Use GetConfigurationCount (for use as a stop value in a loop)
Use GetConfigurationNames to store my configs in an array

Pass these three pieces of info to a function that will do the following in a loop:

Create a drawing sheet with the same name as the corresponding configuration
Drop in 3 standard views (of that configuration)
Change to the next configuration and repeat the loop.


My pride tells me I can write this on my own, no matter how many hours it takes. But my business instincts tell me to gratefully acknowledge anyone who has similar code and is willing to share it.


System: Dell Precision 650—Intel Xeo @ 2.66 GHz with 1/2G RAM
OS: Windows 2000 SP3
Graphics: NVidia Quadro FX 500 128Mb (OpenGL set to Solidworks)
Version: Solidworks 2005, SP0
 
Did you reference the Solidworks API (TLB)? or please write down the error so we can help
 
Sorry i didn't read the error message:

You are passing 11 arguments to that functions and the prototype of the function needs only 10 arguments.

retval = DrawingDoc.NewSheet3 ( name, paperSize, templateIn, scale1, scale2, firstAngle, templateName, width, height, propertyViewName )



Input:
(BSTR) name
Name to be given to the new sheet

Input:
(short) paperSize
Size of paper if using swDwgTemplateNone as defined in swDwgPaperSizes_e

Input:
(short) templateIn
Template index as defined in swDwgTemplates_e

Input:
(double) scale1
Scale numerator

Input:
(double) scale2
Scale denominator

Input:
(BOOL) firstAngle
TRUE for first angle projection, FALSE otherwise

Input:
(BSTR) templateName
Name of custom template with full directory path if templateIn is set to swDwgTemplateCustom

Input:
(double) width
Paper width if templateIn is set to swDwgTemplateNone or swDwgPapersUserDefined

Input:
(double) height
Paper height if templateIn is set to swDwgTemplateNone or swDwgPapersUserDefined

Input:
(BSTR) propertyViewName
Name of the view containing the model to get custom property values from

Return:
(BOOL) retval
TRUE sheet creation was successful, FALSE if not

What it seems is that the last arguments that is a TRUE is not valid, probably you get confuse with the matter that the C++ function prototype shows the retval but that is only on COM; on VB you don't get the retval from the function arguments.

 
I think you are at a point where recording macros is not enough. Recording macros has limited value. Some commands don't get picked up. Others, especially selections, are recorded in a fashion you would not want to replicate in a program.

If you are rusty at VB programming, here's a couple things to explore:

SelectionManager object to manage selections.

ctrl-J: this brings up a list of available commands

early binding: define objects as their specific type, i.e.
Code:
 Dim swApp as SldWorks.SldWorks
rahter than
Code:
Dim swApp As Object
See what happens when you type a dot when typing
Code:
Set Doc =swApp.ActiveDoc

[bat]"An object at rest can not be stopped."[bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor