Continue to Site

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!

Macro to select node in tree then Activate for editing

Status
Not open for further replies.

MellowJ

Automotive
Apr 25, 2013
8
US
We have a fairly consistent tree that is generated by another process. What I would like to do is create a macro that will select a node that is two levels down, expand it, then activate it for editing.

I've tried a few things, but nothing seems to activate the node (like a double-click would). I do have most of it working in catvba. Anybody have some catvba that would help activate the node?
 
Replies continue below

Recommended for you

then activate it for editing

Is it supposed to be the final result of Your macro OR activation is necessary to start another procedure (e.g constraining child of active component? ?

Solutions:
If case
1. - There is no need to activate object by double-click on it (as node on tree)
2. - You can select desired object (through macro) and start appropriate workbench by CATIA.StartWorkbench("Part Design") command

LukaszSz. Poland, Warsaw University of Technology, Faculty of Power and Aeronautical Engineering : MEchanical Engineering. BsC - 2013
 
alternative solution for scenario 2

You have to create external Shell script that activate node (object to activate must be selected) and save it as vbs file

in this case filename is: "D:\ActivateNode.vbs"
Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.sleep 200
WshShell.SendKeys "c:FrmActivate" + "{ENTER}", True



In Yours Catia macro:
Code:
'...
AppActivate "CATIA V5"
StartCMD = "wscript D:\ActivateNode.vbs "
Call Shell(StartCMD)
'...

LukaszSz. Poland, Warsaw University of Technology, Faculty of Power and Aeronautical Engineering : MEchanical Engineering. BsC - 2013
 
Thank you again Lukaszsz. I will give it a try.

We have some users that want to skip the double-click because each node under the VSYS_CHASSIS node represents a bill of material that needs to be positioned along a chassis frame rail. Expanding and activating the node allows them to save wear-and-tear on their fingers.
 
Solution one in lukaszsz' post does not solve the problem and thus is not even a solution.

Why do you say Sendkeys is tricky?
 
Hi,

When I said first solution was thinking of something like this (lukaszsz gives you just some guides, no one has time enough to give a complete solution):

Code:
Language="VBSCRIPT"

Sub CATMain()

        Dim documents1 As Documents
        Set documents1 = CATIA.Documents

        Dim partDocument1 As Document
        Set partDocument1 = documents1.Item("VSYS_CHASSIS.CATPart")

        Dim part1 As Part
        Set part1 = partDocument1.Part

        Dim selectPart
        Set selectPart = CATIA.ActiveDocument.Selection
        Dim editPart
        Set editPart = partDocument1

        selectPart.Add(partDocument1.Part)
        CATIA.StartWorkbench("PrtCfg")
        selectPart.Clear()

        editPart.Activate()
        
End Sub

SendKeys is tricky because you need to find how many seconds you should delay the execution (or maybe is not necessary), maybe you have another process on your computer which can interfere with SendKeys command, a.s.o.

Regards
Fernando

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top