×
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

VBA CATIA Help: Complex Macro

VBA CATIA Help: Complex Macro

VBA CATIA Help: Complex Macro

(OP)
Hi there,

I have next to no experience with VBA and creating macros in CATIA. I've been given the task of creating a method that can calculated the area of empty space in a CATIA Part using image processing software. The macro will involve finding an overall dimension of the part, the outer diameter for instance, creating a sketch involving two circles, one of which corresponds to the diameter measured. After which the sketch will be padded, the view rotated to the front and a screenshot taken. The macro is then required to launch an external image processing program and insert the screenshot. The image is then analyzed using another macro I've created. The software calculates the area of interest and pastes the results in an excel spread sheet. It is then necessary to insert the final value from excel back into CATIA and display it somewhere.

I've already made a macro to create the sketch and pad it but I'm not sure how I can create a macro that measures the overall dimension, this dimension changes for different parts. This is something I can probably figure out but I was wondering if someone could help me with changing the view to the left orientation and taking a screen shot. I recorded a macro for rotatig the view but I get an error when I attempt to run it, I've underlined the area of interest:

Sub CATMain()

Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument

Dim cameras1 As Cameras
Set cameras1 = partDocument1.Cameras

Dim camera3D1 As Camera3D
Set camera3D1 = cameras1.Item("* left")

Dim viewpoint3D1 As Viewpoint3D
Set viewpoint3D1 = camera3D1.Viewpoint3D

Dim specsAndGeomWindow1 As SpecsAndGeomWindow
Set specsAndGeomWindow1 = CATIA.ActiveWindow

Dim viewer3D1 As Viewer3D
Set viewer3D1 = specsAndGeomWindow1.ActiveViewer

viewer3D1.Viewpoint3D = viewpoint3D1

Set viewpoint3D1 = camera3D1.Viewpoint3D

viewer3D1.Viewpoint3D = viewpoint3D1

End Sub

As for the screen shot, I found a macro but it only works when VBA is open in the background and it takes a screen shot of the wrong window:

Option Explicit

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_SNAPSHOT = &H2C
Private Const VK_MENU = &H12

Sub AltPrintScreen()
keybd_event VK_MENU, 0, 0, 0
keybd_event VK_SNAPSHOT, 0, 0, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
End Sub

Any help, suggestions, or areas you think cannot be done using a macro will be appreciated,

Dave

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