Fixing the sketches
Fixing the sketches
(OP)
Hi everyone,
Instead of constraing the sketch using dimensions I want to fix the sketches using fix together and I thought of doing this using a macro which will count the number of sketches in a part and fix them. After some googling I came up with a code, however it is working at the last it is deleting the fix together. I can't able to figure out what is wrong in the code. Please help me finding that.
Here is the code:
Sub CATMain()
Dim parRoot As PartDocument
Set prtRoot = CATIA.ActiveDocument
Dim sel As Selection
Set sel = prtRoot.Selection
sel.Search ("Name = Sketch.*")
C = sel.Count
For i = 1 To C
sel.Search ("Name = Sketch." & i)
CATIA.StartCommand ("Sketch")
sel.Search ("Type = point")
sel.Search ("Type = Line")
sel.Search ("Type = curve")
CATIA.StartCommand ("Fix Together")
sel.Search ("Name = HDirection")
sel.Search ("Name = VDirection")
Dim objShell
Set objShell = CreateObject("WScript.Shell")
CATIA.RefreshDisplay = True
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{ENTER}"
CATIA.StartCommand ("Exit workbench")
Next i
End Sub
Thanks in advance
Instead of constraing the sketch using dimensions I want to fix the sketches using fix together and I thought of doing this using a macro which will count the number of sketches in a part and fix them. After some googling I came up with a code, however it is working at the last it is deleting the fix together. I can't able to figure out what is wrong in the code. Please help me finding that.
Here is the code:
Sub CATMain()
Dim parRoot As PartDocument
Set prtRoot = CATIA.ActiveDocument
Dim sel As Selection
Set sel = prtRoot.Selection
sel.Search ("Name = Sketch.*")
C = sel.Count
For i = 1 To C
sel.Search ("Name = Sketch." & i)
CATIA.StartCommand ("Sketch")
sel.Search ("Type = point")
sel.Search ("Type = Line")
sel.Search ("Type = curve")
CATIA.StartCommand ("Fix Together")
sel.Search ("Name = HDirection")
sel.Search ("Name = VDirection")
Dim objShell
Set objShell = CreateObject("WScript.Shell")
CATIA.RefreshDisplay = True
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{ENTER}"
CATIA.StartCommand ("Exit workbench")
Next i
End Sub
Thanks in advance





RE: Fixing the sketches
I suggest you to run the code in vba editor step by step and watch in the same time on CATIA screen (expand the sketch tree on geometry and see what is going on).
But before this, try to fix another issue, what is happening if a user delete a sketch before and never recreated ? For example sketch.1 and sketch.2 are not existing in spec tree....
I suggest also to use sel.Search ("Type = point + line + curve")
Then check how good is working SendKeys method because I suppose there you have the problem. I suspect that CATIA is exiting from Sketch faster then SendKeys method and thats why the Fix Toghether is not created.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: Fixing the sketches
Thank you Fernando,
As you said the problem is with send keys. Is there any other way to activate Fix Together window and press OK button?
regards,
Sriram
RE: Fixing the sketches
Regards
Fernando
https://picasaweb.google.com/102257836106335725208