CATScript to take picture of annotation captures
CATScript to take picture of annotation captures
(OP)
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
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





RE: CATScript to take picture of annotation captures
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
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
RE: CATScript to take picture of annotation captures
'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?
http://excelspreadsheetshelp.blogspot.com
RE: CATScript to take picture of annotation captures
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
RE: CATScript to take picture of annotation captures
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?
http://excelspreadsheetshelp.blogspot.com
RE: CATScript to take picture of annotation captures
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.
RE: CATScript to take picture of annotation captures
http://excelspreadsheetshelp.blogspot.com
RE: CATScript to take picture of annotation captures
If bodyname<> "FINAL_BODY" Then
excel.bodyname
row+1
Else
row=1
End If
http://excelspreadsheetshelp.blogspot.com
RE: CATScript to take picture of annotation captures
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?
RE: CATScript to take picture of annotation captures
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
RE: CATScript to take picture of annotation captures
Tools - Options - General - Display - Navigation - Navigation.
Win XP64
R20/21, 3DVIA Composer 2012, ST R20
Dell T7400 16GB Ram
Quadro FX 4800 - 1.5GB
RE: CATScript to take picture of annotation captures
RE: CATScript to take picture of annotation captures
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.