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!

Catia Macro programming Help

Status
Not open for further replies.

Alan Lowbands

Aerospace
May 17, 2017
274
GB
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
 
Replies continue below

Recommended for you

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
 
Hi ferdo
It's script.
I didn't check the Portable Script Centre chm file but I will now.

thanks
 
Think I found it.

CATIA.StartCommand "Update current sheet"

woo hoo :)

cheers
 
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
-----------------------------------------------------------



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

Also change your last condition to:

Code:
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:
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:
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
- Text along a curve for Catia V5
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top