×
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

Catia Macro programming Help

Catia Macro programming Help

Catia Macro programming Help

(OP)
Hi again,
I have recently needed some macro's or scripts and have managed to botch a few together, Frankenstien code made from bits of others I found here and on the web.
I would like to learn how to compile the odd thing myself and was hoping someone may be able to point me in the direction of some tutorials.
If anyone has a guide to how to use the information in the V5Automation file it would be a big help as I don't understand exactly what it is telling me :(
Sorry for being a bit thick
Any help would be greatly appreciated.

regards
Alan

RE: Catia Macro programming Help

Hi Alan,

In order to compile your code, you need to use another language than VBA or CATScrpit, the closest one would be VB.

So get MS visual studio and read some stuff like that

If you want to understand the chm file, you need to have more understanding on OO coding. Object Oriented in case you wonder. You can start with google or youtube (for easy access video). You should also be able to find many course online... (invest some time now)

now my question, why do you want to compile your code?

Eric N.
indocti discant et ament meminisse periti

RE: Catia Macro programming Help

(OP)
Thanks for the reply.
Basically I would like to automate some boring tasks.
I work in tool design but much of the work is bringing drawings up to customer specifications.
Going over sometimes hundreds of drawings and changing how things like how a hole is dimensioned can be a bit monotonous and time consuming.
Even changing a dimension line type requires multiple mouse clicks so being able to write a little bit off code to do it with one or two could save me a lot of time.
And it looks interesting :)

regards
Alan

RE: Catia Macro programming Help

To change dimensions style you can use following command T:Dim*. Just enter this in the start command

Regards,
Jenia Ladkov

RE: Catia Macro programming Help

(OP)
Thanks Jenia,
The problem I have is that I wouldn't know what a T:Dim start command looked like.
I have a lot to learn :)

regards
Alan

RE: Catia Macro programming Help

Eric N.
indocti discant et ament meminisse periti

RE: Catia Macro programming Help

(OP)
Thanks Itsmyjob,
Can you use that command inside vb script?
The only thing holding me up at the moment is changing a one part dimension line to 2 parts.
I've searched the web but come up with nothing
I did managed to botch together a bit of code to standardise some fastener parts. Just to save me the time filling in properties, adding an axis system, changing colour and material.
I think I'm going to enjoy learning this stuff :)

Regards
Alan

RE: Catia Macro programming Help

(OP)
Thanks Ferdo, I'll take a look

RE: Catia Macro programming Help

(OP)
Hi Guys,
I've struggled with this now for about a week and haven't got any further.
The Automation help file is Double Dutch to me, I just don't understand what its telling me. I need a 'Dummy's guide to Automation help files'
Could someone give me a pointer with the 'changing a dimension line to 2-parts' problem I'm having.
It would be really appreciated.

I also found a macro that creates rough stock dimensions called 'e3roughStock'
Does anyone know if the code is available anywhere to see?
It seems to be encoded so I don't know if it is.

Thanks Gents

regards
Alan

RE: Catia Macro programming Help

plz contact radek for the source code

if the chm file is Double Ductch to you then go read VBA for Dummys, it won't take long before you can actually do something with CATIA script and the chm file.

please help me understand: changing a dimension line to 2-parts a picture could help (post using the upload image function plz)

Eric N.
indocti discant et ament meminisse periti

RE: Catia Macro programming Help

(OP)
Hi itsmyjob,
Thanks for the reply,
I'll get a copy of VBA for Dummy's, I think I need it.
I'll also contact Radek and see if he will let me take a look at the code.

The 2-part dim line is basically the dimension reads horizontally.
I have attached a jpeg, cant see the upload image function? If you can point me to where it is ill upload it.

regards
Alan

RE: Catia Macro programming Help

(OP)
sorry, found it.



RE: Catia Macro programming Help

CODE --> code

Dim myDim As DrawingDimension
Set myDim = CATIA.ActiveDocument.Selection.Item(1).Value

Dim myDimLine As DrawingDimLine
Set myDimLine = myDim.GetDimLine

myDimLine.DimLineGraphRep = catDimLine2Parts 

within 2 minutes of reading the chm file...

Eric N.
indocti discant et ament meminisse periti

RE: Catia Macro programming Help

(OP)
Thank you :)
I can take a hint and will be reading the VBA for Dummy's.

best regards
Alan

RE: Catia Macro programming Help

(OP)
Hi again itsmyjob,
Last questions I hope.

I've been looking for VBA for Dummies but most of the ones I can see are saying VBA for Excell or other specific software.
Could you tell me the best one to get?
also
How can I get a message to Radek to see if he will let me take a look at the roughstock code.

your help has been much appreciated

regards
Alan

RE: Catia Macro programming Help

VBA for dummies will be with Excel... this book is here to give you some basic of VBA and the interface (and excel VBA knowledge can't hurt too much)

You can find book on catia programming if you search but I have the feeling this will do just as fine. What is in the other book is on this forum or the coe forum or some other web blog. no need more book.

for CATIA oriented question, check chm file or thread560-251808: CATIA Portable Script Center and if you don't get it search the forum, if still in trouble ask the question here.

for general VBA question, search stackoverflow.com

Eric N.
indocti discant et ament meminisse periti

RE: Catia Macro programming Help

(OP)
Thanks you :)

RE: Catia Macro programming Help

There's BASIC, Beginners' All-purpose Symbolic Instruction Code circa. 1964, that's been enhanced over the decades. Visual Basic is Microsoft's contribution to the Basic language. Visual Basic for Applications, also Microsoft, refers to the basic that is packaged in Microsoft applications like Word, Excel, Access, Power Point, Outlook. Each of these VBA's contain extensions of VB with object properties and methods that are only applicable to that application: Word has Document object properties and methods where Excel has Workbook object properties and methods; each with an application object model.

So there are things that an Excel VBA reference would have in common with a Word VBA reference and other things that it would not.

Finally, if you understand how VB works in general and you have some understanding of an application's object model and have access to a decent VB editor like the one in Excel and a HELP reference for your application's VBA, you can figure out how to program another application that you know very little about. For instance, from the Excel VBA editor, I've learned how to code for an Attachmate terminal emulator that interfaces a mainframe computer and also manipulate MS Project that I have a very rudimentary knowledge of.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Catia Macro programming Help

(OP)
Thanks for the reply, most of that went right over my head and hurt my tiny brain though :)

Had a dozen or so drawings today to tidy up.
Mostly missed dims and silly GD&T tolerances.
So I thought, I'll do some little scripts that change the contents of the GD&T box too what I want.
A few easy little scripts, one for dowel holes, one for clearance holes, one for surface tolerance. double click and presto the box is filled in.
Fell over at the first hurdle. Where the hell is the GD&T in the automation file.

I'm sure the person/persons that wrote that did it to annoy me.......................
I will find it if it kills me

alan :(

RE: Catia Macro programming Help

(OP)
Hi Gents,

Could anyone give me a poke please.
I really have tried but can't get it to update the views.
I'm trying to go through a directory of drawings, open each one, unlock the views (if there locked)
then update the views and save the file.
I've botched this up from other bits of code and also found some info in the automation file but it just wont update.
Don't laugh to hard :(
Any help would be appreciated.

regards
Alan


*********************************************************************

Sub CATMain()
on error resume next

Set FileSys = CATIA.FileSystem

Dim FoldObj 'As Folder

Dim FileObj 'As File

Dim files1 'As Files

FPath = CATIA.FileSelectionBox("Select a Drawing File.", "*.CATDrawing", CatFileSelectionModeOpen)

Set FileObj = FileSys.GetFile(FPath)

Set FoldObj = FileObj.ParentFolder

Set files1 = FoldObj.Files

Dim i 'As Interger
Dim j

'Dim partDocument1 'As Document

'Dim product1 'As CATBaseDispatch

For i=1 To files1.Count '* this loops through each file in the folder

Set Doc = CATIA.Documents.Open(files1.Item(i).Path)
if err.number = 0 then

end if

'Set product1 = partDocument1.Product
Set drawingDocument1 = CATIA.ActiveDocument

'---------------------------------------------------------------


Set Sheets = drawingDocument1.Sheets

Set activeSheet = Sheets.ActiveSheet

Set views = activeSheet.Views

Dim sSel 'As Selection

Set sSel = drawingDocument1.Selection

sSel.Search "CATDrwSearch.DrwView,all"

For j = 1 To sSel.Count

If sSel.Count = 0 Then MsgBox "Select one view!", vbCritical, "Lock/Unlock": Exit Sub

If TypeName(sSel.Item(j).Value) <> "DrawingView" Then MsgBox "Selected element is not a drawing view!", vbCritical, "Lock/Unlock": Exit Sub

Dim drwView 'As DrawingView

Set drwView = sSel.Item(j).Value

drwView.LockStatus = False


'sSel.Item(j).ForceUpdate '******************
'DrwView.Sheets.Item(j).ForceUpdate 'can't get to work tried all sorts
'DrwView.Sheets.Item(j).Update '******************

Next

CATIA.ActiveDocument.Save()

CATIA.ActiveDocument.Close()

'Next

'End Sub

Next

END SUB

RE: Catia Macro programming Help

(OP)
Hi ferdo
It's script.
I didn't check the Portable Script Centre chm file but I will now.

thanks

RE: Catia Macro programming Help

(OP)
Think I found it.

CATIA.StartCommand "Update current sheet"

woo hoo :)

cheers

RE: Catia Macro programming Help

(OP)
Hi Gents,
Could anyone tell me where i'm going wrong with this.
I've been making a few little bits of script to just try and cut down on mouse click.
Most seem to work but I end up with two ie Show view frames & hide View frames.
I've tried to make one that will toggle either on or off but I cant get it to work.
This isn't my code, I have pinched bits from other scripts but i'm missing something

any help would be appreciated

cheers
Alan

------------------------------------------------

Sub CATMain()
Set drawingDocument1 = CATIA.ActiveDocument
Set Sheets = drawingDocument1.Sheets
Set activeSheet = Sheets.ActiveSheet
Set views = activeSheet.Views
Dim sSel 'As Selection
Set sSel = drawingDocument1.Selection
sSel.Search "CATDrwSearch.DrwView,all"
For i = 1 To sSel.Count
If sSel.Count = 0 Then MsgBox "Select one view!", vbCritical, "Lock/Unlock": Exit Sub
If TypeName(sSel.Item(i).Value) <> "DrawingView" Then MsgBox "Selected element is not a drawing view!", vbCritical, "Lock/Unlock": Exit Sub
Dim drwView ' As DrawingView
Set drwView = sSel.Item(i).Value
if drwView.FrameVisualization = True Then
drwView.FrameVisualization = False
ElseIf drwView.FrameVisualization = False Then
drwView.FrameVisualization = True

Next

End Sub
-----------------------------------------------------------



RE: Catia Macro programming Help

There is a mistake in last "If - ElseIf" condition, you miss "End if".

Also change your last condition to:

CODE --> vba

If drwView.FrameVisualization Then
    drwView.FrameVisualization = False
Else
    drwView.FrameVisualization = True
End If 

It seems that there is a strange incompatibility between CATIA (drwView.FrameVisualization) boolean and VBA boolean type, because both conditions

CODE --> vba

Debug.Print drwView.FrameVisualization = True
Debug.Print drwView.FrameVisualization = False 

are in your case evaluated as False. Quick fix is to change it as shown above.

As listed in CATIA Automation help file:

CODE --> vba

Support of boolean type in CATVBA

There is a known limitation concerning the usage of the Boolean type 
in the V5 Automation methods invoked from VBA. In V5 applications, 
the Boolean type is defined as an 'unsigned char' where the VBA definition
is a short. When a V5 method returns True, the returned integer value is 1, 
though VBA is expecting -1. Because of this difference, the following VBA 
code will not work as expected (the method boolMethod returns True):

If myObj.boolMethod() = True Then // This test will fail
...
End If 

to correct this limitation, you have to write some code like this :

If myObj.boolMethod() Then End If 

or

If myObj.boolMethod() != False Then 
...
End If 

For the same reason, the 'Not' operator cannot be applied directly on the 
returned value of such method:

Not(myObj.boolMethod())

will return True instead of returning False. To use correctly the 'Not' operator
you have to use a variable to store the boolean value before applying the operator: 

Dim myBool
myBool = myObj.boolMethod()
Not(myBool) 

will correctly return False


Note that this limitation is specific to VBA and is not concerning VBScript. 



Tesak
http://scripts4all.eu/txtoncurve/ - Text along a curve for Catia V5

RE: Catia Macro programming Help

(OP)
Many thanks,
that worked to toggle the lock views but doesn't seem to work on the view frames.
It's probably me being half asleep.
Will try again tomorrow

regards
Alan

RE: Catia Macro programming Help

(OP)
Hi again,
I've tried this with the drawing views and it does either hide or show the view frames.
For some reason when you look in the properties the check box doesn't change?
Is this just me?

Cheers
Alan

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