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!

How to refresh the visibility of geometry being created in a sketch while the macro is running?

Status
Not open for further replies.

drewmumaw

Computer
May 20, 2013
288
US
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.

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
 
Replies continue below

Recommended for you

Try this

Code:
Sub CATMain()

    Dim sketches1 As Sketches
    Dim sketch1 As Sketch
    Dim factory2D1 As Factory2D

    Set sketches1 = CATIA.ActiveDocument.Part.HybridBodies.Item("Geometrical Set.1").HybridSketches
    Set sketch1 = sketches1.Add(CATIA.ActiveDocument.Part.OriginElements.PlaneYZ)
    Set sketch1Variant = sketch1
    sketch1Variant.SetAbsoluteAxisData Array(0#, 0#, 0#, 0#, 1#, 0#, 0#, 0#, 1#)
    
    CATIA.ActiveDocument.Part.InWorkObject = sketch1
    For ctr = 1 To 10
        Set factory2D1 = sketch1.OpenEdition
        factory2D1.CreatePoint(ctr, ctr).Construction = False
        sketch1.CloseEdition
        CATIA.ActiveDocument.Part.UpdateObject sketch1
    Next

End Sub

I hope it helps.

-GEL
Imposible is nothing.
 
@GELFS
drewmumaw said:
I don't want to have to exit the sketch and reopen it to create each point over and over again.
Thanks for the response. I guess I just don't like the idea of reopening the sketch over and over, although I think this is the only way to do what I'm trying to achieve without updating the entire part. Thanks for your response.

Regards,
Drew Mumaw
 
May I ask why you need to update the graphics area after each point insertion?

-GEL
Imposible is nothing.
 
Sure. Let's say I have a macro that creates 10,000+ geometric elements (not just points) in various sketches. Although I could use the CATIA.StatusBar property or some other message type display (which I might end up doing), I would like to give the user a visual aid for the macro's progression so they're not stuck wondering how much is complete. Make sense?

From all of my trial in error, I think I'll just have to close the sketch edition, update the sketch object, and then go back into the sketch to create the next object - basically what you recommended. Updating the entire part won't work for my specific case because it updates the entire part. I don't know, I might end up just having to settle for using CATIA.StatusBar. Again, thanks for your time looking into this.

Regards,
Drew Mumaw
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top