Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

In a macro, how to switch the view to a scene I created? 1

Status
Not open for further replies.

Milie

Computer
Nov 27, 2013
12
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 :
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![smile]

Emilie
 
Replies continue below

Recommended for you

Thanks a lot for your help! I'm trying this :

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
 
Hi!

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
 
Hi,

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

 
One more question, I'm wondering : When I'm using CATIA without the macro, I just select the scene and I press 'Enter' on my keyboard nothing happen. It's only working when I double-click on the scene. Then, is it suppose to work if I ask a script to simulate the 'Enter' key ?

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).
 
GREAT!!!
You're the best!
[2thumbsup]

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
 
Hello,

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
 
I can answer myself regarding to the problem with the CATScript. My problem was the value "Sleep". I don't know why if I put the value 1000 the scene is activated. Maybe my system needs more time to do it?
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
 
I answer myself again about the VBA problem. I solved it with the code given in this post:

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")

"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor