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 can a macro detect which sketch is in edition 3

Status
Not open for further replies.

TiagoFigueiredo

Industrial
May 22, 2013
494
PT
I,

I want to create a macro that needs to detect wich sketch is open in edition. My idea is to change something in that sketch. Any idea?

Tiago Figueiredo
Tooling Engineer
 
Replies continue below

Recommended for you

i had the feeling searching for sketch origin on screen would give me the origin of all sketches but it seems it return only the origin of the open sketch.

so why did I spend some time to check the screengrab image?
Code:
Sub CATMain()

    tempfolder = Environ("Temp")
    
    filenames = Array(tempfolder & "\initial.jpg", tempfolder & "\usual.jpg", tempfolder & "\lowlight.jpg", tempfolder & "\no3d.jpg")
    
    Set oViewer = CATIA.ActiveWindow.ActiveViewer
    oViewer.CaptureToFile catCaptureFormatJPEG, filenames(0)
    
    CATIA.StartCommand ("Usual")
    oViewer.CaptureToFile catCaptureFormatJPEG, filenames(1)
    
    CATIA.StartCommand ("Low light")
    oViewer.CaptureToFile catCaptureFormatJPEG, filenames(2)
    
    CATIA.StartCommand ("No 3D Background")
    oViewer.CaptureToFile catCaptureFormatJPEG, filenames(3)
    
    initvalue = FileLen(filenames(0))
    usualvalue = FileLen(filenames(1))
    lowlightvalue = FileLen(filenames(2))
    no3dvalue = FileLen(filenames(3))
    
    ' checking which file is the same as the initial state
    
    solution = 0
    
    If initvalue = usualvalue Then solution = solution + 1
    
    If initvalue = lowlightvalue Then solution = solution + 2
    
    If initvalue = no3dvalue Then solution = solution + 4
    
    
    CATIA.StartCommand ("Fit All In")
    
    Set oSel = CATIA.ActiveDocument.Selection
    
    oSel.Clear
    
    On Error Resume Next
    
    While oSel.Count = 0
    CATIA.RefreshDisplay = True
    oSel.Search ("Sketcher.Origin,scr")
    Wend
    
    On Error GoTo 0
    
    Set oSketch = oSel.Item(1).Value.Parent.Parent.Parent
    
    oSel.Clear
    
    MsgBox (" the sketch is " & oSketch.Name)
    
    
    ' restoring initial visu
    
    Select Case solution
    
        Case 1
        CATIA.StartCommand ("Usual")
    
        Case 2
        CATIA.StartCommand ("Low light")
    
        Case 4
        CATIA.StartCommand ("No 3D Background")
    
        Case Else
        MsgBox ("Can't be sure about initial sketch visu setting")
    
    End Select

    For i = 0 To 3
    Kill filename(i)
    Next
    

End Sub

Eric N.
indocti discant et ament meminisse periti
 
Fernando can you add this to Catia Portable Script Center next version?

Eric N.
indocti discant et ament meminisse periti
 
whow... I'm feeling so little near you guys... You are really far away from my level. I really have a loooottttt to learn...

Really thank you guys, from your support.

Tiago Figueiredo
Tooling Engineer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top