×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How can a macro detect which sketch is in edition
3

How can a macro detect which sketch is in edition

How can a macro detect which sketch is in edition

(OP)
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

RE: How can a macro detect which sketch is in edition

(OP)
Anyone have tried this?

How can I detect in a macro wich sketch i'm editing.

Tiago Figueiredo
Tooling Engineer

RE: How can a macro detect which sketch is in edition

(OP)
drewmumaw, yes it's true.

But I want that my macro manage that sketch.

Tiago Figueiredo
Tooling Engineer

RE: How can a macro detect which sketch is in edition

(OP)
itsmyjob, many thanks. really good.
that's what I was looking for.

thanks

Tiago Figueiredo
Tooling Engineer

RE: How can a macro detect which sketch is in edition

(OP)
Just on more thing,

you change the background, to no Background.

CODE -->

CATIA.StartCommand ("No 3D Background") 

But sometimes we have sketches with background type usual and low light. With this macro we change it, but after the macro, i would like to go back to the previous background. So there is any way, that in the start of the macro, we "read" which background is active?

Tiago Figueiredo
Tooling Engineer

RE: How can a macro detect which sketch is in edition

i did not find any way of doing this, please post your solution when you have it.

Eric N.
indocti discant et ament meminisse periti

RE: How can a macro detect which sketch is in edition

you could take a screen grab then switch to each mode and take each time another screen grab, then compare picture (color count, kb size...) to find original settings.

Eric N.
indocti discant et ament meminisse periti

RE: How can a macro detect which sketch is in edition

(OP)
Sorry, can you explain to me better? I haven't understand your idea

Tiago Figueiredo
Tooling Engineer

RE: How can a macro detect which sketch is in edition

you take a picture of the screen, then you change the sketch background option and take another picture, and repeat for all background option. If you compare pictures you should be able to find what option was defined when you started the script.

Eric N.
indocti discant et ament meminisse periti

RE: How can a macro detect which sketch is in edition

Tiago,

Eric''s macro is really smart, you can do also something like this.

CODE --> CATScript

Sub CATMain()
CATIA.StartCommand ("No 3D Background")
CATIA.StartCommand ("Fit All In")

        Msgbox "Wait to fit all in"

Set oSel = CATIA.ActiveDocument.Selection
oSel.Search ("Sketcher.Origin,scr")
Set oSketch = oSel.Item(1).Value.Parent.Parent.Parent
oSel.Clear

            CATIA.StartCommand ("Usual")   ' put usual background, replacing "No 3D Background"
            '~ force refresh CATIA
            CATIA.RefreshDisplay = true
            dblWidth = CATIA.ActiveWindow.Width
            CATIA.ActiveWindow.Width = dblWidth - 1
            CATIA.ActiveWindow.Width = dblWidth

MsgBox ("the sketch is " & oSketch.Name)
End Sub 

What you really need is the waiting message, otherwise CATIA will throw an error. If you will put the waiting message you can also comment/ skip those two commands "No 3D Background" and "Usual". Or you can find another solution to give CATIA time to fit all in....

Still, if you will use "Usual " command, you will not notice immediately the change, but if you will exit from sketch and come back you will see the correct status.

PS. What a surprise, I can edit my post bigsmile

RE: How can a macro detect which sketch is in edition

maybe better than waiting for "Fit All In" to finish, we really need the Selection.Search to return something so maybe a loop until Selection.Count >0 would do

Eric N.
indocti discant et ament meminisse periti

RE: How can a macro detect which sketch is in edition

(OP)
Yes definitely it's a real smart macro. It was giving me, what I was looking for. Except the background.
I haven't understand why you made this, Ferdo. With this you are changing the widht of screen.

CODE -->

'~ force refresh CATIA
            CATIA.RefreshDisplay = true
            dblWidth = CATIA.ActiveWindow.Width
            CATIA.ActiveWindow.Width = dblWidth - 1
            CATIA.ActiveWindow.Width = dblWidth 


Let's imagine that i'm working the sketch, with "low light" background, and then I run the macro. After macro my sketch background is always "usual".


itsmyjob, your solution looks real reliable :)

CODE -->

Sub CATMain()

CATIA.StartCommand ("No 3D Background")

CATIA.StartCommand ("Fit All In")

Set oSel = CATIA.ActiveDocument.Selection

oSel.Clear

Do Until oSel.Count > 0

oSel.Search ("Sketcher.Origin,scr")

Loop

Set oSketch = oSel.Item(1).Value.Parent.Parent.Parent

oSel.Clear

CATIA.StartCommand ("Usual")

CATIA.RefreshDisplay = true

MsgBox ("the sketch is " & oSketch.Name)

End Sub 

Tiago Figueiredo
Tooling Engineer

RE: How can a macro detect which sketch is in edition

Quote (Me smile)


If you will put the waiting message you can also comment/ skip those two commands "No 3D Background" and "Usual". Or you can find another solution to give CATIA time to fit all in....

Solution was given by Eric, I believe you don't need now to manipulate the sketcher background. Did you tried?
CATIA is throwing error if the sketcher is not visible on screen, that's why you need time to execute Fit All In. Also, it will be good to be sure that you are indeed in sketch edition, otherwise you will stay for ever waiting CATIA to execute the macro.

Star for Eric, I've learned something these days bigsmile .

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: How can a macro detect which sketch is in edition

(OP)
You are right Ferdo, i don't need to change the background.

I have made some modifications.

try this:

CODE -->

Sub CATMain()

'CATIA.StartCommand ("No 3D Background")

CATIA.StartCommand ("Fit All In")
' force refresh CATIA
            CATIA.RefreshDisplay = True

'Timer
Dim time1, time2

time1 = Now
time2 = Now + TimeValue("0:00:01")
    Do Until time1 >= time2
        DoEvents
        time1 = Now()
    Loop

Set oSel = CATIA.ActiveDocument.Selection

oSel.Clear

'Condition if sketch is on edition

Workbench = CATIA.GetWorkbenchId

If Workbench = "CS0WKS" Then

Do Until oSel.Count > 0

oSel.Search ("Sketcher.Origin,scr")

Loop
Set oSketch = oSel.Item(1).Value.Parent.Parent.Parent

MsgBox ("the sketch is " & oSketch.Name)

Else

MsgBox ("There is no sketch in edition")

End If

oSel.Clear

'CATIA.StartCommand ("Usual")

End Sub 

Many thanks by your Help itsmyjob, really clever solution.

With all of our inputs, we can build really impressive things.

Many thanks to all.

Tiago Figueiredo
Tooling Engineer

RE: How can a macro detect which sketch is in edition

(OP)
One small update. Return the fit to the previous zoom.

CODE -->

Sub CATMain()

CATIA.StartCommand ("Fit All In")
' force refresh CATIA
            CATIA.RefreshDisplay = True

'Timer
Dim time1, time2

time1 = Now
time2 = Now + TimeValue("0:00:01")
    Do Until time1 >= time2
        DoEvents
        time1 = Now()
    Loop

Set oSel = CATIA.ActiveDocument.Selection

oSel.Clear

'Condition if sketch is on edition

Workbench = CATIA.GetWorkbenchId

If Workbench = "CS0WKS" Then

Do Until oSel.Count > 0

oSel.Search ("Sketcher.Origin,scr")

Loop
Set oSketch = oSel.Item(1).Value.Parent.Parent.Parent

MsgBox ("the sketch is " & oSketch.Name)


CATIA.StartCommand ("Previous View")

Else

MsgBox ("There is no sketch in edition")

End If

oSel.Clear


End Sub 


Tiago Figueiredo
Tooling Engineer

RE: How can a macro detect which sketch is in edition

no need to wait... the loop will resume when something is found:

CODE --> vba

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 

Eric N.
indocti discant et ament meminisse periti

RE: How can a macro detect which sketch is in edition

(OP)
Amazing itsmyjob. really impressive.
So final code, like this:

CODE -->

Sub CATMain()

CATIA.StartCommand ("Fit All In")

Set oSel = CATIA.ActiveDocument.Selection
'Condition if sketch is on edition

Workbench = CATIA.GetWorkbenchId

If Workbench = "CS0WKS" Then

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

MsgBox ("the sketch is " & oSketch.Name)

Else

MsgBox ("There is no sketch in edition")

End If

oSel.Clear

End Sub 

Tiago Figueiredo
Tooling Engineer

RE: How can a macro detect which sketch is in edition

2
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 --> not_best_solution

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

RE: How can a macro detect which sketch is in edition

Fernando can you add this to Catia Portable Script Center next version?

Eric N.
indocti discant et ament meminisse periti

RE: How can a macro detect which sketch is in edition

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources