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
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
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
Drew Mumaw
www.textsketcher.com
www.drewmumaw.com
RE: How can a macro detect which sketch is in edition
But I want that my macro manage that sketch.
Tiago Figueiredo
Tooling Engineer
RE: How can a macro detect which sketch is in edition
indocti discant et ament meminisse periti
RE: How can a macro detect which sketch is in edition
that's what I was looking for.
thanks
Tiago Figueiredo
Tooling Engineer
RE: How can a macro detect which sketch is in edition
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
indocti discant et ament meminisse periti
RE: How can a macro detect which sketch is in edition
indocti discant et ament meminisse periti
RE: How can a macro detect which sketch is in edition
Tiago Figueiredo
Tooling Engineer
RE: How can a macro detect which sketch is in edition
indocti discant et ament meminisse periti
RE: How can a macro detect which sketch is in edition
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 SubWhat 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
RE: How can a macro detect which sketch is in edition
indocti discant et ament meminisse periti
RE: How can a macro detect which sketch is in edition
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 = dblWidthLet'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 SubTiago Figueiredo
Tooling Engineer
RE: How can a macro detect which sketch is in edition
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
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
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 SubMany 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
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
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 SubTiago Figueiredo
Tooling Engineer
RE: How can a macro detect which sketch is in edition
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 0indocti discant et ament meminisse periti
RE: How can a macro detect which sketch is in edition
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 SubTiago Figueiredo
Tooling Engineer
RE: How can a macro detect which sketch is in edition
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 Subindocti discant et ament meminisse periti
RE: How can a macro detect which sketch is in edition
indocti discant et ament meminisse periti
RE: How can a macro detect which sketch is in edition
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
Really thank you guys, from your support.
Tiago Figueiredo
Tooling Engineer