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

Anyone have tried this?

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

Tiago Figueiredo
Tooling Engineer
 
drewmumaw, yes it's true.

But I want that my macro manage that sketch.

Tiago Figueiredo
Tooling Engineer
 
thread560-415451

Eric N.
indocti discant et ament meminisse periti
 
itsmyjob, many thanks. really good.
that's what I was looking for.

thanks

Tiago Figueiredo
Tooling Engineer
 
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
 
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
 
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
 
Sorry, can you explain to me better? I haven't understand your idea

Tiago Figueiredo
Tooling Engineer
 
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
 
Tiago,

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

Code:
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]
 
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
 
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
 
Me :-) said:
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

- Romania
- EU
 
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
 
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
 
no need to wait... the loop will resume when something is found:
Code:
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top