I'm trying to find a way to refresh the display of geometry that's being created in a sketch from a catvba macro. Currently, the script will run, but the viewer won't update until I mouse over the CATIA window after the script has run. I'm well aware that I could just add CATIA.Interactive = True to the end of the script to get it to update both the spec tree and the geometry in the viewer, however I am trying to get the geometry in the sketch to be visible in the viewer while the macro is still running and before I've exited the sketcher edition.
For example, take a look at the code below. It has a loop to create a thousand points. I've already commented out all of the things that I've tried thus far. While updating the entire part will work, this is highly undesirable because many 3D modelers work on large parts that have various bodies and geometrical elements not updated while they're working on other areas. In other words, they wouldn't want a script to create geometry and try to update the entire part.
Here's what it looks like when the script is done: 1scriptIsDone.jpg
And here's what it looks like when I mouse over the viewer area: 2mouseOverViewer.jpg
Again, I'm well aware that I can put CATIA.Interactive = True at the end of the script to make the viewer update when the loop is finished and I've exited the sketch edition with sketch1.CloseEdition, but I'm trying to get the viewer to update after each point is created in the sketch. Also, I don't want to have to exit the sketch and reopen it to create each point over and over again.
Any clever ideas? btw, I've already read through the items suggested in this thread (277360). Thank you very much for your time.
Regards,
Drew Mumaw
For example, take a look at the code below. It has a loop to create a thousand points. I've already commented out all of the things that I've tried thus far. While updating the entire part will work, this is highly undesirable because many 3D modelers work on large parts that have various bodies and geometrical elements not updated while they're working on other areas. In other words, they wouldn't want a script to create geometry and try to update the entire part.
Here's what it looks like when the script is done: 1scriptIsDone.jpg
And here's what it looks like when I mouse over the viewer area: 2mouseOverViewer.jpg
Again, I'm well aware that I can put CATIA.Interactive = True at the end of the script to make the viewer update when the loop is finished and I've exited the sketch edition with sketch1.CloseEdition, but I'm trying to get the viewer to update after each point is created in the sketch. Also, I don't want to have to exit the sketch and reopen it to create each point over and over again.
Any clever ideas? btw, I've already read through the items suggested in this thread (277360). Thank you very much for your time.
Code:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub CATMain()
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item("Geometrical Set.1")
Dim sketches1 As Sketches
Set sketches1 = hybridBody1.HybridSketches
Dim originElements1 As OriginElements
Set originElements1 = part1.OriginElements
Dim reference1 As Reference
Set reference1 = originElements1.PlaneYZ
Dim sketch1 As Sketch
Set sketch1 = sketches1.Add(reference1)
Dim arrayOfVariantOfDouble1(8)
arrayOfVariantOfDouble1(0) = 0#
arrayOfVariantOfDouble1(1) = 0#
arrayOfVariantOfDouble1(2) = 0#
arrayOfVariantOfDouble1(3) = 0#
arrayOfVariantOfDouble1(4) = 1#
arrayOfVariantOfDouble1(5) = 0#
arrayOfVariantOfDouble1(6) = 0#
arrayOfVariantOfDouble1(7) = 0#
arrayOfVariantOfDouble1(8) = 1#
Set sketch1Variant = sketch1
sketch1Variant.SetAbsoluteAxisData arrayOfVariantOfDouble1
part1.InWorkObject = sketch1
Dim factory2D1 As Factory2D
Set factory2D1 = sketch1.OpenEdition()
Dim geometricElements1 As GeometricElements
Set geometricElements1 = sketch1.GeometricElements
Dim axis2D1 As Axis2D
Set axis2D1 = geometricElements1.Item("AbsoluteAxis")
Dim line2D1 As Line2D
Set line2D1 = axis2D1.GetItem("HDirection")
Dim line2D2 As Line2D
Set line2D2 = axis2D1.GetItem("VDirection")
Dim point2D1 As Point2D
For ctr = 1 To 1000
Set point2D1 = factory2D1.CreatePoint(ctr, ctr)
point2D1.Construction = False
'things I 've tried already in order to get the geometry visible from inside the loop:
'CATIA.Windows.Item(1).WindowState = catWindowStateNormal 'doesn't work & adjusts the window which is undesirable
'part1.UpdateObject sketch1 'doesn't work
'CATIA.Visible = True 'doesn't work & adjusts the window which is undesirable
'CATIA.ActiveDocument.Activate 'doesn't work
'CATIA.RefreshDisplay = True 'doesn't work
'CATIA.ActiveWindow.Viewers.Item(1).Update 'doesn't work
'CATIA.Interactive = True 'doesn't work
'part1.Update 'THIS WORKS!, but is undesirable because it tries to update the entire part
'Sleep (100) 'pause for .1 second (used for testing low qty of points because they're created almost immediately)
Next
sketch1.CloseEdition
part1.UpdateObject sketch1
End Sub
Regards,
Drew Mumaw