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!

CATScript to take picture of annotation captures

Status
Not open for further replies.

ntweisen

Mechanical
Jul 12, 2010
94
I have a part with three captures under an annotation set called iso view, notes, and front view which I want the script to cycle through and take a screen shot of each. I can turn the background to white and text to black but I'm not sure the code to cycle through and take a picture of the captured views (not just the active viewer) and save them each as a bmp or png file. Here's what I have so far:

Language="VBSCRIPT"

Sub CATMain()

MsgBox "Must be a part file."

Dim oAnnotationSets As AnnotationSets
Dim oAnnotationSet As AnnotationSet
Dim oAnnotations As Annotations
Dim oAnnotation As Annotation
Dim oSel As Selection
Dim visProperties1 As INFITF.VisPropertySet

Set partDoc = CATIA.ActiveDocument
Set Part = partDoc.Part
Set oAnnotationSets = Part.AnnotationSets
Set oSel = CATIA.ActiveDocument.Selection

Dim ObjViewer3D As Viewer3D
Set objViewer3D = CATIA.ActiveWindow.ActiveViewer

'change background color to white
Dim DBLBackArray(2)
objViewer3D.GetBackgroundColor(dblBackArray)
Dim dblWhiteArray(2)
dblWhiteArray(0) = 1
dblWhiteArray(1) = 1
dblWhiteArray(2) = 1
objViewer3D.PutBackgroundColor(dblWhiteArray)

For IdxSet = 1 To oAnnotationSets.Count
Set oAnnotationSet = oAnnotationSets.Item(IdxSet)
Set oAnnotations = oAnnotationSet.Annotations
For IdxAnnot = 1 To oAnnotations.Count
Set oAnnotation = oAnnotations.Item(IdxAnnot)

If Not oAnnotation Is Nothing Then
With oSel
.Clear
.Add oAnnotation
Call .VisProperties.SetVisibleColor(0, 0, 0, 0)
End With
oAnnotation.ModifyVisu
End If
Next
Next

End Sub


 
Replies continue below

Recommended for you

This functions does exactly what you want. It's coded in VB on VS2010, so you'll have to make a few changes to get it working in VBA. It finds all the annotations sets, then individual annotations, then goes one level deeper and finds the captures. It will then cycle through all captures and take pics.

you'll need to point the oCapture.DisplayCapture at your method for taking pictures. It works beautifully, and is extremely fast.

Also, it is much faster to recolor all your annotations before you start taking pictures, rather than do it for every photo. It's even faster if you minimize the active veiwer too.
Code:
Public Sub switchcapture() Handles RecolorAnnotationBlackToolStripMenuItem.Click
        Dim partDocument1 As PartDocument = CATIA.ActiveDocument
        Dim oAnnotationSets As AnnotationSets = partDocument1.Product.GetTechnologicalObject("CATAnnotationSets")

        Dim viewer1 As Viewer = CATIA.ActiveWindow.ActiveViewer
        Dim viewpoint1 As Viewpoint3D = viewer1.Viewpoint3D

        partDocument1.Selection.Clear()
        If oAnnotationSets.Count > 0 Then
            For p = 1 To oAnnotationSets.Count
                Dim CurAnnoSet As AnnotationSet = oAnnotationSets.Item(oAnnotationSets.Item(p).Name.ToString())

                For i = 1 To CurAnnoSet.Captures.Count

                    Dim oCapture As Capture = CurAnnoSet.Captures.Item(i)
                    'MessageBox.Show(CurAnnoSet.Captures.Item(i).Name.ToString())
                    oCapture.DisplayCapture() <--outside method
                Next i
            Next p
        Else
            MsgBox("No Captured views")
        End If
    End Sub

Nice to see you on these boards too.

Bruce
 
Thanks for the post, it was very helpful. My script kinda sorta works now. There are still a few bugs. I change the text color to black at the beginning with the following code but am unsure how to change it back to white at the end:

'change text to black

'Dim oAnnotationSets As AnnotationSets
'Dim oAnnotationSet As AnnotationSet
'Dim oAnnotations As Annotations
'Dim oAnnotation As Annotation
Dim oSel As Selection
Dim visProperties1 As INFITF.VisPropertySet

Set partDoc = CATIA.ActiveDocument
Set Part = partDoc.Part
Set oAnnotationSets = Part.AnnotationSets
Set oSel = CATIA.ActiveDocument.Selection

'Dim ObjViewer3D As Viewer3D
Set objViewer3D = CATIA.ActiveWindow.ActiveViewer

For IdxSet = 1 To oAnnotationSets.Count
Set oAnnotationSet = oAnnotationSets.Item(IdxSet)
Set oAnnotations = oAnnotationSet.Annotations
For IdxAnnot = 1 To oAnnotations.Count
Set oAnnotation = oAnnotations.Item(IdxAnnot)

If Not oAnnotation Is Nothing Then
With oSel
.Clear
.Add oAnnotation
Call .VisProperties.SetVisibleColor(0, 0, 0, 0)
End With
oAnnotation.ModifyVisu
End If
Next
Next

Also, the script does not seem to be displaying the capture properly. For instance, one of the saved images is a back view of the part instead of the captured view. Any thoughts?

 
to change the text back, simly run your script again but change the color to white:

I think this is what it should be, but i could be wrong:

Call .VisProperties.SetVisibleColor(255, 255, 255, 255)

And double check the number of captures to the number of output images. I seem to recall the script crashing sometimes, and it would skip pictures. I couldn't figure out why it would crash, so i inserted a try/catch that forced it to take a picture anyway.

Dim partDocument1 As PartDocument = CATIA.ActiveDocument
Dim oAnnotationSets As AnnotationSets = partDocument1.Product.GetTechnologicalObject("CATAnnotationSets")
partDocument1.Selection.Clear()
If oAnnotationSets.Count > 0 Then
For p = 1 To oAnnotationSets.Count
Dim CurAnnoSet As AnnotationSet = oAnnotationSets.Item(oAnnotationSets.Item(p).Name.ToString())
For i = 1 To CurAnnoSet.Captures.Count
Dim oCapture As Capture = CurAnnoSet.Captures.Item(i)
Try
oCapture.DisplayCapture()
TakePicture()
PictureCount = PictureCount + 1
Catch
'Captures will randomly crash sometimes, but this forces a picture anyway. Pictures still turn out fine.
TakePicture()
PictureCount = PictureCount + 1
End Try

Next i
Next p
End If

That should hopefully get it sorted. If not, you can try this tip i got over at CATIA forums. Un checking this options stops CATIA from slowly panning to the next capture, and instead it instantly jumps.

"Dont know how to do it in code, but you can change a setting in tools > options > navigation > animation for viewpoint modification (tick for normal use, untick to jump between views when taking pictures automatically) "

I am currently running this script within a larger CATIA automation app i wrote and it works great. Huge time saver when a large amount of new parts come in.

Bruce
 
Thanks for your help! It works as expected now. Maybe you can help me with my next issue. I am exporting some properties and names to an Excel spreadsheet. There are a few cells with bodies named "FINAL_BODY" which I want to delete. I know in Excel I can run a macro which will delete an entire row in the spreadsheet based upon a given condition. Here's the macro which works in Excel:



Sub Delete_FINALBODY_Rows()

Dim r As Long

For r = Range("A" & Rows.Count).End(xlUp).Row to 1 Step -1

If UCase(Left(Cells(r, "A").Text, 10)) = "FINAL_BODY" Then Rows(r).Delete

Next r

End Sub


Is there a way to run this Excel macro directly inside my catscript at the end? So it would export a list to Excel of all of my parts, bodies, and desired properties as described before but would then delete any rows with "FINAL_BODY" in column A. Is it possible?

 
VBA and Catscripts are very similar, but there are key difference depending on which environment your running a script in.

In your case, instead of trying to figure out how to delete the rows that contain "FINAL_BODY", why don't you find a way to stop them from ever being written into your excel spreadsheet. Sadly, excel is not an area of expertise for me.
 
If I want to skip over the bodies named "FINAL_BODY" I assume I would add some sort of IF THEN statement to the section of code that loops through all the bodies inside of a part. Not sure of the correct syntax though.

 
I see others have automated the process of taking screenshots of each capture. I'm doing the same. However, has anyone figured out how to get the captures to change instantly? Otherwise, one will ultimately run into timing issues trying to wait for Catia to finish switching from one capture to another before taking the actual screenshot. Trying to hardcode specific wait times in the code opens up a can of worms and is unreliable if the code is run on different performing machines.

Someone mentioned there being a setting to turn off animation via Tools->Options>Display->Navigation. However, I don't see that setting anywhere in V5R18-R20 (at least the versions I have).

Ideally, I need a programmatic solution anyways.

Any ideas out there?
 
That's strange that you do not have that option, though I am still running R18 so maybe it has been moved?

I haven't had to use this in a few months, but i seem to recall that even though the screen slowly pans, the screen shots still came out the way you expect them too. It just took the script longer to run because it was displaying the animation versus quickly snapping to the next scene.

I think I'll need to use it again sometime next week, and I'll probably recode a few sections so I'll post any revisions I make here.

Bruce
 
R19, R20, R21

Tools - Options - General - Display - Navigation - Navigation.


Win XP64
R20/21, 3DVIA Composer 2012, ST R20
Dell T7400 16GB Ram
Quadro FX 4800 - 1.5GB
 
Yeah, no option to turn off animation in Tools-Options-General-Display-Navigation-Navigation. See attached screenshot. I'm not totally sure what the option I do have in that section does, but it certainly doesn't change the behavior when switching capture displays.
 
 http://files.engineering.com/getfile.aspx?folder=34ec2959-e807-4d7b-97a5-67639b78d7a2&file=missing_setting.png
Hey lharrison,

Did you ever start using your script again for this? If you're able to get screenshots to be right even though the Catia viewer can take a few seconds to switch from one capture to another, I would be interested in how you do it. I have messed with the timing between capture displays in my script and have not had any luck getting it to work nicely in generating a series of images that show the correct display for each capture.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor