Welcome to 3DCADForums

Join our CAD community forums where over 25,000 users interact to solve day to day problems and share ideas. We encourage you to visit, invite you to participate and look forward to your input and opinions. Acrobat 3D, AutoCAD, Catia, Inventor, IronCAD, Creo, Pro/ENGINEER, Solid Edge, SolidWorks, and others.

Register Log in

Starting the "Constraint" Command from VBA, what is the right way?

Hi,

I'm trying to start the "Constraint" command (which should allow you to place a dimension to sketch elements in the Sketcher Workbench) from a VBA script.

I looked in the command list (view->commands list...) and found the names "Constraint" for the dimensioning tool and "Constraint..." for the "Constraint box" (which opens a box where you can set geometrical constraints, which is not what I want). I tried with this (the simplest case):

Code:
Sub CATMain()
CATIA.StartCommand ("Constraint")
End Sub
and I also tried writing "c:Constraint" in Catia's command field (or power bar?).

None of these attempts give me the Constraint command I'm looking for. Instead I get "Unavailable Command", but if I select the sketch element I want to constrain I get the "Constraint box".

How do I start the "Constraint" command (used for dimensions) from VBA instead of the "Constraint Box"?

Regards, Skorpan
 

MrCATIA

Super Moderator
To activate the Constraint command, you have to be in the Sketcher workbench (open/edit the sketch).
 
To activate the Constraint command, you have to be in the Sketcher workbench (open/edit the sketch).
Hi,

Thank you for your reply!

I realise that commands are sensitive to what workbench you are in. Even so the StartCommand("Constraint") gives the same error since it seems to call the "Costraints..." command which is a different one. The first i the one where you set dimensions and the other is the box which allows you to set geometrical constraints (but no dimensions). The problem, I've found, seem to be with the Catia version we are using I've tried this on Catia V5 R19 and R20 without sucess but when the same code runs on R21 it works as intended.

To me, it seems like Catia uses another command in the earlier versions and I wonder if there is a way to find out which one it is. My second attempt at a solution is to use SendKeys and go through the insert menu and start the Constraint command that way. However, I haven't gotten it to work. This is my code:

Code:
Sub CATMain()
    CATIA.RefreshDisplay = True
    SendKeys "%icoc"
End Sub
I've also tried with a WSShell (which I don't really understand what it does) but neither seem to have any effect, as nothing happens on the screen. I run it through the alt+F8 menu and choose start in catia (and I've tried using a quick button). If I run it in the editor it works (but only in the editor window ofcourse), so maybe I need to make sure I focus the Catia window somehow? How would I do that?

Thanks again for your reply!

Regards,
Skorpan
 

Sponsor

Top