Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

VBScripts 3

Status
Not open for further replies.

kr7530

Automotive
Aug 9, 2011
130
US
Can anybody tell me what is required to write Macros and VB Reactions and what is required to run them?
I have Microsoft Visual Studio 2010 Tools for Office Runtime(x64) and Microsoft Visual Studio Tools for Applications 2013 SDK


Thanks,
Kevin
Catia V5R22
Windows 7
 
Replies continue below

Recommended for you

Hi,

First question which I would ask is "Do you really need macros ?"

Before starting to think to create a macro you should take in consideration if is really necessary to start to develop something. Macros are useful when you have a lot of users running them with different purposes: data quality controlling, repetitive time consuming tasks or just some tasks which you want to be very sure that your users will not missed them and you want to be executed in a correct manner.

You have to take in consideration the time of the developer to understand the task and develop the macro/application and how many users will run that, in which CATIA versions, if you plan to use the macro for different versions and if you have installed all the need it components of the automation (including some specific licenses for Knowledge workbenches).

Coming back to your question, Visual Studio will help you to create nice applications but not all companies will allow to have on their computers such kind of external applications. I saw cases when they don't have even install the VBA package which is coming with CATIA installation kit.

In this case you have to live with CATScript and catvbs files, which will allow you to do pretty much things. If you have the VBA package installed (no special license, same case for what I mentioned before) you can do nice, friendly user forms and more sophisticated catvba files.

Definitely, more powerful applications can be done with Visual Studio (even the free version). Depending on how CATIA is installed, you can handle a lot of things with external applications done with VS. You can check on DS web sites which version is recommended for different CATIA versions (personally I worked with VS 2005, 2008 and 2010).

What I can tell is automation in CATIA is completely different in v6 then in v5. For me it was a simple curiosity if I can automate my work, I'm a simple CATIA user and not a programmer, when I start a job I'm not tinging first at a macro, I'm thinking "Does CATIA have a command to do that?".

I'm curios to see what other users will say about VBScripts and when and how they should be used.


Regards
Fernando

- Romania
- EU
 
Fernando,
Thank you, I am also curious to see what others have to say.
"Do you really need macros ?" No, there is a very small group of catia users. We are surfacing only so there is no need for drawings with custom title blocks and such. Most of what I currently do is with powercopies for surface features such as draw beads. Whenever we get slow I try to automate things to try to reduce human error, decrease mouse/keyboard clicks and increase uniformity between users. I am by no means a programmer but I do enjoy trying.

An example - Whenever we convert a step file the file name and part number do not match. Below is a macro I am working on to help with this. My thought is to try to have this as a reaction that could run in an assembly structure.

Going back to my original question, one of the issues i am having is that I can not Dim "this" As "that". Whether in a reaction or a macro they fail on the first "Dim" line. I am unsure if it is me or a lack of needed software. I will be checking to see if the VBA package is installed.


Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument
count = InStrRev(partDocument1.Name, ".")
partName = Left(partDocument1.Name,(count-1))


If InStr(CATIA.ActiveDocument.Name, ".CATPart") < 1 Then
MsgBox "This only works on CATParts"
Else
Set product1 = partDocument1.GetItem("")
MsgBox partName
product1.PartNumber = partName
End If


End Sub

Thanks,
Kevin
 
i also use a lot of power copies and design tables..but macros are helpful in some cases. i do a lot of tooling design so i use macro to create 10 or 20 parameters like tooling hole diameter ans stuff. also custom titleblock or export point for laser projector. you can not do that without macro. but as i said power copies and design tables are more preferred to me when it comes to modeling.
 
I found this on a forum (can't remember which one) and I believe can explain some things.

You are probably confusing Visual Basic (VB) or VBA (Visual Basic for Applications) with VBScript (Visual Basic Scripting Edition).
In VBScript, there's no such thing as a "String" object as there is in VBA, so you can't do a Dim strMyString As String.

Additionally, VBScript does not syntactically allow for performing both a declaration(Dim) and an assignment(=) in the same statement.

So, while in VBA you can do Dim strMyString As string = "qwert", in VBScript this "As String" followed by the assignment to "qwert" will result in a syntax error. In VBScript, you would simply do this:

Dim strMyString
strMyString = "qwert"

If you really want to both declare(Dim) and assign(=) a variable to a value all on one line with VBScript code, you'd need to string both statements together with a colon character (a colon character can be used to string multiple statements together on a single line... it's sort-of the opposite of an underscore):

Dim strMyString : strMyString = "qwert"

For more information about VBScript, including some of the major differences between VBScript vs. VBA, you can read more online here:
Also, for some good foundational reading about VBScript in general, the online VBScript User's Guide provides a wealth of information:
Almost everything applied in vbs files can be done in catvbs and catvba in CATIA is somehow like VBA in MSOffice, so, you can find a lot of good info on-line.

Regards
Fernando

- Romania
- EU
 
Thanks Fernando, that's a big help!

Kevin
 
@kr7530
To write VB Reactions you will need the KWA license for CATIA. More info on KWA can be found on the 3ds.com site here.

You do not need the KWA license to run a VB Reaction. In other words, one user can create the reaction and it will execute when other users trigger the reaction even if they don't have the KWA license pulled (under Tools > Options > Shareable Products tab).

For more info on developing Visual Basic plug-ins for CATIA using Microsoft Visual Studio 2010 take a look at this thread:
[URL unfurl="true"]http://www.eng-tips.com/viewthread.cfm?qid=345694[/url]

Regards,
Drew Mumaw
 
Fernando,

I tried using the links you provided but the page is not found, I will continue to search the Microsoft site.
I am currently trying to convert an integer value to a string value and I am not having any luck.
Below is the code if you have time to look at it.

Thanks,
Kevin



Language="VBSCRIPT"

Sub CATMain()

Dim sName
sName = InputBox ("Enter Job#: ", " ")
Dim NumberofForms
NumberofForms = InputBox("How many form stations?"," ")



Set documents1 = CATIA.Documents

Set productDocument1 = documents1.Add("Product")

Set product1 = productDocument1.Product

product1.PartNumber = sName+"_Sim_000"

Set products1 = product1.Products

For X = 1 To NumberofForms

MsgBox X

strX = X

Set product2 = products1.AddNewComponent("Product", "")

Set productDocument2 = documents1.Item("Product1.CATProduct")

Set product3 = productDocument2.Product

product3.PartNumber =sName+"_Form0"+strX+"_Asm"

product2.Name = sName+"_Form0"+strX+"_Asm.1"

Set products2 = product2.Products

Set product4 = products2.AddNewComponent("Part", "")

Set partDocument1 = documents1.Item("Part1.CATPart")

Set product5 = partDocument1.GetItem("Part1")

product5.PartNumber = sName+"_Form0"+strX+"_Try01"

Set products3 = product3.Products

Set product6 = products3.Item("Part"+strX+".1")

product6.Name = sName+"_Form0"+X+"_Try01.1"

Next

End Sub
 
Figured it out, needed "CStr" to convert it to a string
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top