In a macro, how to switch the view to a scene I created?
In a macro, how to switch the view to a scene I created?
(OP)
Hello!
I'm using Catia V5 and I did a macro in CATScript creating scenes and I would like also the macro to switch the view to one of my created scenes.
Here is my macro : it's creating 1 scene per product of the "first row" of the product tree :
I would like for example to switch programmatically to the last scene (or the first, whatever).
Thank you for your help!
Emilie
I'm using Catia V5 and I did a macro in CATScript creating scenes and I would like also the macro to switch the view to one of my created scenes.
Here is my macro : it's creating 1 scene per product of the "first row" of the product tree :
CODE -->
Sub CATMain()
Dim i As Integer
Dim products As Products
Dim product As Product
Dim px(1)
Dim ProductCountName As String
Dim TheScenes
Dim oScene1 As ProductScene
Dim RootProduct 'As Product
' Get the root of the CATProduct
Set RootProduct = CATIA.ActiveDocument.Product
Set products = RootProduct.Products
docCount=products.Count
For i=1 to docCount
Set product = products.Item(i)
ProductCountName = product.Name
Set px(0) = products.Item(ProductCountName)
' Retrieve the ProductScenes collection
Set TheScenes = RootProduct.GetTechnologicalObject("ScenesCollection")
Set oScene1 = TheScenes.AddProductSceneFull (ProductCountName, px)
Next
End Sub I would like for example to switch programmatically to the last scene (or the first, whatever).
Thank you for your help!

Emilie





RE: In a macro, how to switch the view to a scene I created?
One method is to use a search criteria by name and then Activate (up to now I found it can be done by SendKeys method...) if someone knows other method it would be great to find it.
selection.Search "CATDMUSearchInformation.DMUSceneType.Name='CHASSIS ASSEMBLY.1',all"
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: In a macro, how to switch the view to a scene I created?
I manage to have the scene selected (I see it is highlighted in catia) but I have one question : what do you activate? The scene's SceneProductData?
I'll also try in parallel the sendkey method.
:)
best regards,
Emilie
RE: In a macro, how to switch the view to a scene I created?
If you will select one scene then you will type C:Activate in Power Input and hit Enter, CATIA will switch to that scene (activate). Thats why I said to use SendKeys.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: In a macro, how to switch the view to a scene I created?
Thanks you Ferdo for your help! :)
I tried this but it doesn't activate the scene... Could you help me please?
This scrip is creating a scene with the rootProduct. I would like to activate this scene so I put it in a selection, I see it is highlighted in CATIA but it is not activated.
Sub CATMain()
Dim product As Product
Dim px(1)
Dim ProductCountName As String
Dim TheScenes 'As ProductScenes
Dim oScene1 As ProductScene
Dim RootProduct 'As Product
' Get the root of the CATProduct
Set RootProduct = CATIA.ActiveDocument.Product
ProductCountName = RootProduct.Name
Set px(0) = RootProduct
' Retrieve the ProductScenes collection
Set TheScenes = RootProduct.GetTechnologicalObject("ScenesCollection")
Set oScene1 = TheScenes.AddProductScenePartial (ProductCountName, px)
'Do my selection
Dim selection As Selection
Set selection = CATIA.ActiveDocument.Selection
selection.Add oScene1
search = "CATDMUSearchInformation.DMUSceneType.Name='" + ProductCountName + "',all"
selection.Search search
CATIA.StartCommand "Activate"
End Sub
I really appreciate your help :)
Kind regards,
Emilie
RE: In a macro, how to switch the view to a scene I created?
Is not working with CATIA.StartCommand "Activate" , thats why I said to use SendKeys, you need to create an external vbs file and call it from CATScript or use catvba and all can be done inside catvba.
In this thread (second post) you can find something or use Search function for this forum with SendKeys as keyword to find more examples.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: In a macro, how to switch the view to a scene I created?
I ask this cause I had a look at the example :
I copied the SendEnter.vbs script in my c: folder and I wrote my CATScript like this :
Sub CATMain()
Dim product As Product
Dim px(1)
Dim ProductCountName As String
Dim TheScenes 'As ProductScenes
Dim oScene1 As ProductScene
Dim RootProduct 'As Product
' Get the root of the CATProduct
Set RootProduct = CATIA.ActiveDocument.Product
ProductCountName = RootProduct.Name
Set px(0) = RootProduct
' Retrieve the ProductScenes collection
Set TheScenes = RootProduct.GetTechnologicalObject("ScenesCollection")
Set oScene1 = TheScenes.AddProductScenePartial (ProductCountName, px)
'Do my selection
Dim selection As Selection
Set selection = CATIA.ActiveDocument.Selection
selection.Add oScene1
search = "CATDMUSearchInformation.DMUSceneType.Name='" + ProductCountName + "',all"
selection.Search search
Call CATIA.SystemService.ExecuteBackGroundProcessus("WScript.exe c:\SendEnter.vbs")
End Sub
...and nothing is happening when I launch my CATScript (no error).
RE: In a macro, how to switch the view to a scene I created?
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: In a macro, how to switch the view to a scene I created?
You're the best!
What was missing was in my SendEnter.vbs . I didn't get all about this file.
I really appreciate your help !
I copy the SendEnter.vbs file in case it helps someone else too :
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.sleep 200
WshShell.SendKeys "c:Activate"
WScript.sleep 200
WshShell.SendKeys "{ENTER}"
best regards,
Emilie
RE: In a macro, how to switch the view to a scene I created?
I'm having the same problem as Milie. The SendEnter.vbs file is in c:\ and I'm trying writing in CATScript. The Scene is created but not activated, and this is my main interest.
It's strange because if I write directly in Power Input the c:Activate nothing happens. Other StartCommands work but not the Activate one.
If I use VBA I just write in the VBAProject the code given in the SendEnter file and when I execute "c:Activate" is written where the cursor is.
Could you help me with this problem?
Best regards,
Antonio
RE: In a macro, how to switch the view to a scene I created?
However, I'm still trying to do it in a VBA. Is it possible to do it without calling to other file (sendkeys)?
Best regards,
Antonio
RE: In a macro, how to switch the view to a scene I created?
http://www.eng-tips.com/viewthread.cfm?qid=350504
Thanks to ntweisen, he did it without the SendEnter.vbs file:
"
CATIA.RefreshDisplay = True
AppActivate "CATIA V5"
SendKeys "c:Activate" + Chr(13), True
Application.Wait Now + TimeValue("00:00:05")
"