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!

Catia v5 VBA, StartCommand "Constraint" doesn't give the expected result

Status
Not open for further replies.

SirSkorpan

Mechanical
Oct 5, 2013
7
Hi,

I'm currently learning to program Catia v5 in VBA. I've done a bit of VBA programming before as well as some other languages (Java, C++ and PHP primarily).

At the moment I'm trying to create a toolbar that, among other things, has buttons, which mimic the command buttons in the default Catia toolbar. I've found the CATIA.StartCommand function to be very useful but when it comes to constraints it doesn't work as I expect.

In my script I want to start the Constraint command (the one used to dimension a sketch in the Sketcher workbench). I looked in the command list (view->commands list...) and found "Constraint" for the dimensioning tool and "Constraint..." for the "Constraint box" (the one where you can only put geometrical constraints). I tried with this:

Code:
Sub CATMain()
    CATIA.StartCommand ("Constraint")
End Sub

and I also tried writing "c:Constraint" in Catia's command box (not sure what it's called but the box at the bottom where you can write your commands instead of clicking the icons).

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

How to I start the "Constraint" command from VBA instead of the "Constraint Box"?

Regards,
Skorpan
 
Replies continue below

Recommended for you

Hi,

Thank you for your reply!

The problem is that I'm not actually trying to create dimensions (constraints) per se. What I want is to mimic the functionality of the button in the Constraint toolbar. So when someone pushes the button I create in VBA I want them to get the same result as if they pushed it in the original toolbar.

In itself it might seem like an unnecessary thing to create but it's part of a bigger project where the implementation makes sense :)

Unfortunately I don't have the v5automation help installed on this computer. I'll see what I can find out when I get back to work, until then I'd we very grateful of any and all information I could get on the subject.

Regards,
 
To add to my previouspost. Since every other command is possible to run through the power bar (I belive that's what the little text box at the bottom of the Catia window is called), why would the Constraint/Dimension command not be possible?

It is also possible to run the command through the "Commands List" although I susspect that Catia is not showing the correct ID for the command.

Regards,
 
That is basically what I want to happen. After the button has been pressed I want the user to pick the sketch element/-s he/she wants to dimension. I'm not trying to set the dimension/constraint in this way I'm only trying to start the command so the user can set them (by picking in the sketch).

I'm now trying to use SendKey like this:
Code:
Sub CATMain()
    ' CATIA.StartCommand ("Constraint")
    MsgBox "Attempting to start a Constraint"
    CATIA.RefreshDisplay = True
    SendKeys "%(i)coc"
End Sub

But this dosen't seem to work either.

Regards,
Skorpan
 
Do you really get that if you run that statement? I only get an error message saying "Unavailable Command" if I run that in a sketch. Or if I first select a sketch element and then run it, I get that box where you can choose constraints (but not make dimensions). :(

I'm running Catia v5R20 ServicePack 1, could it be that they have changed something between versions?

Regards,
Skorpan
 
That is so unfair :eek: I do exactly the same thing but I get the error explained before :(

Could it be a bug in the version of Catia I'm running?

I also notice you use a different editor commpared to me, do you also use an other type of script?

When I start a new script I go to (in Catia) Tools->Macro->Macros and click "Macro libraries..." choose "VBA projects" as Library type Click "Create new library...". After I decide a name and place I click ok->close->create. I then choose "MS VBA" as Macro Language and type a name and click "ok". When I click "Edit..." I come to the same Editor which office uses (Microsoft Visual Basic). Could this be a source for trouble maybe I get stuff in the file that I can't see but messes up something?

Thanks for taking the time!

Regards,
Skorpan
 
I should say that I tried to use CATScript and MS VBScript with the same result as I got in VBA. And when I start script in those other two variants I don't get the option to start my script directly from the editor like you did.
 
I'm using Scite Editor, with some modification done by me for properties file, just because I like how is looking (colors for different statements, variables, a.s.o.). I've added also the CATScript and catvbs among files which can run directly from the editor (I'm not using something else). You can do same thing with Notepad++ if you like it more.

I don't think is a bug in CATIA...

Regards
Fernando

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top