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 VBA Drafting Workbench

Status
Not open for further replies.

pgm575

Aerospace
Mar 12, 2015
10
US
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!
 
Replies continue below

Recommended for you

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:
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?
 
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.
 
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

- Romania
- EU
 
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:
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?
 
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

- Romania
- EU
 
Sorry, was out traveling for a week.

Both
Code:
Application.Wait
and
Code:
CATIA.Application.Wait
throw up Object Required errors. Trying to figure this out now.
 
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.
 
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.
 
Code:
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

- Romania
- EU
 
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.
 
Alright, I made it work. Here's the code:

Code:
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.
 
The anchor position was getting reset, so I just added this:
Code:
For i = 1 To DrwView.Texts.Count
    DrwView.Texts.Item(i).AnchorPosition = catMiddleRight
Next

And everything works now. Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top