×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

CATIA VBA Drafting Workbench

CATIA VBA Drafting Workbench

CATIA VBA Drafting Workbench

(OP)
Does anyone know the code to run the Symmetry command on all geometry in a DXF? I already have code to open the DXFs and to select all 2D lines with a search in the Drawing object but haven't quite figured out the Symmetry portion yet; the Automation help for CATIA (V5 R23) doesn't really seem to list it.

Thanks all!

RE: CATIA VBA Drafting Workbench

(OP)
That command appears to be running but the code doesn't wait after the command call, it just moves on. It may have to do with the fact that I'm running a

CODE --> VBA

selection.Search "CATDrwSearch.2DLine, all" 
right before the Symmetry command, since I think that search will also select the "VDirection/AbsoluteAxis/Main View" and "HDirection" lines; effectively, this would leave no geometry available to be symmetrical about.

Is there a declaration to only select simple 2D lines and not the axis lines?

RE: CATIA VBA Drafting Workbench

(OP)
I was able to step through the code and the problem seems to be that I can't select the Vertical or Horizontal axis. If I stop the code right there and just hand select the vertical axis, the symmetry command completes just fine.

Do you know what the search command is for the axis itself? I tried "2DAxis, VDirection" and "2DLine, VDirection" but no luck so far.

RE: CATIA VBA Drafting Workbench

The command is using a selection, which can be a line, a construction line or something else. Key word is selection, so you have to indicate that line.

If you create that line (symmetry) in your code then is much easier because you can change the name with a specific one (like mysymmline for example) and then you can use a search by name.

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: CATIA VBA Drafting Workbench

(OP)
Alright, I'm real close here. I was able to run the Symmetry command with no error before but without selecting the axis (so the code would move on without completing the Symmetry command because I close the file), and I was also able to create the line without running the Symmetry command. If I combine the code, however, I get the error Command unavailable: when I reach the "CATIA.StartCommand (Symmetry)" line. Here's what the code looks like:

CODE --> VBA

Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument

Dim DrwSht As DrawingSheet
Set DrwSht = drawingDocument1.Sheets.ActiveSheet

Dim DrwView As DrawingView
Set DrwView = DrwSht.Views.ActiveView

Dim fact As Factory2D
Set fact = DrwView.Factory2D

Dim symLine As Line2D
Set symLine = fact.CreateLine(0#, 0#, 0#, 5#)

CATIA.StartCommand (Symmetry)

Dim selection3 As Selection
Set selection3 = drawingDocument1.Selection

selection3.Search "CATDrwSearch.2DLine,all"

Dim selection4 As Selection
Set selection4 = drawingDocument1.Selection

selection4.Search "CATDrwSearch.2DLine,symLine"

CATIA.ActiveDocument.Selection.Clear 

Just can't quite figure out the last bit here. I tried moving the Symmetry command up and down in the code but to no avail. Do I need to reactivate the sheet or something, like in Excel?

RE: CATIA VBA Drafting Workbench

Is CATIA.StartCommand "Symmetry" . But still, I would try to use something like bellow (Application. Wait or Sleep). In vba you can also sendkeys to the input line . You need the wait time to pick the symmetry line - here you can find in this forum or on Google different techniques.

CATIA.RefreshDisplay = True
AppActivate "CATIA V5"
SendKeys "c:Symmetry" + Chr(13), True
Application.Wait Now + TimeValue("00:00:10")

By the way, if you want to change the name of the line you have to
symLine.Name = "my_symLine"

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: CATIA VBA Drafting Workbench

(OP)
Sorry, was out traveling for a week.

Both

CODE --> VBA

Application.Wait 
and

CODE --> VBA

CATIA.Application.Wait 
throw up Object Required errors. Trying to figure this out now.

RE: CATIA VBA Drafting Workbench

(OP)
I've added as many libraries as I can but the "Wait" method is just not available to the "Application" object. Kind of scratching my head on this, since I see this particular line of code all over the place.

RE: CATIA VBA Drafting Workbench

(OP)
That's not really helpful, least of which because I already know how to use Google. All I've found on all these different forums is the same line of code repeated over and over, and a MS article that states that the Application object is part of the generic VBA library reference which I've already selected.

Either way, I made a loop delay Sub instead, and the 10 second pause doesn't help. The command still isn't completing.

When I figure out what's going on, I'll post the code back here.

RE: CATIA VBA Drafting Workbench

CODE --> vba

Sub CATMain()

MsgBox "You have 10 seconds to pick elements to create their symmetry and the symmetry line. Look in lower left corner of CATIA window for instructions"

On Error Resume Next
Set objCATIA = GetObject(, "CATIA.Application")

Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument

Dim DrwSht As DrawingSheet
Set DrwSht = drawingDocument1.Sheets.ActiveSheet

Dim DrwView As DrawingView
Set DrwView = DrwSht.Views.ActiveView

Dim fact As Factory2D
Set fact = DrwView.Factory2D

Dim symLine As Line2D
Set symLine = fact.CreateLine(0, 0, 0, 5)

CATIA.StartCommand (Symmetry)

Dim selection3 As Selection
Set selection3 = drawingDocument1.Selection

selection3.Search "CATDrwSearch.2DLine,all"

Dim selection4 As Selection
Set selection4 = drawingDocument1.Selection

selection4.Search "CATDrwSearch.2DLine,symLine"

CATIA.ActiveDocument.Selection.Clear

CATIA.RefreshDisplay = True

CATIA.StartCommand "Symmetry"

Dim time1, time2

time1 = Now
time2 = Now + TimeValue("0:00:10")
    Do Until time1 >= time2
        DoEvents
        time1 = Now()
    Loop

MsgBox "Time passed 10 sec"

End Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: CATIA VBA Drafting Workbench

(OP)
Sorry, I understand the confusion now.

I'm trying make this automatic, no user input. I have 1000's of DXFs to mirror and can't have someone sitting there clicking. Thus the attempt at selecting the "symLine" after selecting all the other 2D geometry.

I'll keep working on forcing this selection.

RE: CATIA VBA Drafting Workbench

(OP)
Alright, I made it work. Here's the code:

CODE --> VBA

Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument

Dim DrwSht As DrawingSheet
Set DrwSht = drawingDocument1.Sheets.ActiveSheet

Dim DrwView As DrawingView
Set DrwView = DrwSht.Views.ActiveView

Dim fact As Factory2D
Set fact = DrwView.Factory2D

SendKeys "c:Symmetry" + Chr(13), True

Dim selection3 As Selection
Set selection3 = drawingDocument1.Selection

selection3.Search "Drafting.Polyline,all"
Pause (1)

Dim symLine As Line2D
Set symLine = fact.CreateLine(0#, 0#, 0#, 5#)

Dim selection4 As Selection
Set selection4 = drawingDocument1.Selection

selection4.Search "CATDrwSearch.2DLine,symLine"
Pause (1)

CATIA.ActiveDocument.Selection.Clear
Pause (1)

SendKeys "c:Symmetry" + Chr(13), True

Dim selection5 As Selection
Set selection5 = drawingDocument1.Selection

selection5.Search "CATDrwSearch.DrwText,all"
Pause (1)

Set selection4 = drawingDocument1.Selection

selection4.Search "CATDrwSearch.2DLine,symLine"
Pause (1)

selection4.Delete

CATIA.ActiveDocument.Selection.Clear 

The text doesn't seem to mirror properly (the mirrored text is shifted slightly from its original position), indicating that there is some sort of offset applied to the text. That's the last bit I'll need to figure out.

RE: CATIA VBA Drafting Workbench

(OP)
The anchor position was getting reset, so I just added this:

CODE --> VBA

For i = 1 To DrwView.Texts.Count
    DrwView.Texts.Item(i).AnchorPosition = catMiddleRight
Next 

And everything works now. Thanks for the help!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources