×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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

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

(OP)
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

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

Did you reference the Solidworks API (TLB)? or please write down the error so we can help

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

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.
 

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

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

"An object at rest can not be stopped."
http://www.EsoxRepublic.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources