×
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

Symmetry command in macro for text
2

Symmetry command in macro for text

Symmetry command in macro for text

(OP)
Hi guys,

Can't seem to find a specific solution for this anywhere on the internet... Maybe you guys can help.

We use a macro here to create text and paste it onto an existing sketch in the part body. This macro works fine, but I want to tweak it a bit and flip the orientation of the text before pasting. This text is scribed into an ID plate which will leave an impression in the foam, therefore, the text must be reversed.

I've included the section of code that copies the text in a DXF file and pastes it onto the part sketch.

'Copy text---------------------------------------------------------------------------------------------------
'Set drawingDocument1 = CATIA.ActiveDocument
'Set selection1 = drawingDocument1.Selection
Set selection1 = drawingdocument2.Selection
selection1.Search "Name=Poly*,all"
selection1.copy

'Switch to Part again---------------------------------------------------------------------------------------
Original_part.activate

'msgbox "Now you can paste the text into a sketch"
'selection1.paste

selection2.Add sketch1
selection2.paste

set mypart=original_part.part

Thanks!

RE: Symmetry command in macro for text

you can use change sketch support for that.

RE: Symmetry command in macro for text

(OP)
Thanks Jenia!

Could you be a bit more specific? I understand what "change sketch support" is and can perform this manually, but I'm unsure of the coding side. I have a very basic knowledge of programming languages and am not familiar with the syntax VBA uses.

Cheers,

RE: Symmetry command in macro for text

(OP)
Bump. Any help on this would be greatly appreciated.

RE: Symmetry command in macro for text

@peterkim89
I don't think you can create a positioned sketch in VBA. You can try programming the inversion to achieve a similar result.

CODE --> catvba

Dim sketch1 As Sketch
Set sketch1 = sketches1.Item("Sketch.1")

sketch1.InverseOrientation 

Drew Mumaw
www.textsketcher.com
www.drewmumaw.com

RE: Symmetry command in macro for text

(OP)
Thanks Drew,

Seem to be getting an issue with sketches1.Item. Compiler says Object required: 'sketches1'. Maybe I need to declare something?

RE: Symmetry command in macro for text

@peterkim89
Yes. It's probably a declaration issue. Here's my full code for you to reference.

CODE --> catvba

Sub CATMain()

Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

part1.Update

Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Dim body1 As Body
Set body1 = bodies1.Item("PartBody")

Dim sketches1 As Sketches
Set sketches1 = body1.Sketches

Dim sketch1 As Sketch
Set sketch1 = sketches1.Item("Sketch.1")

sketch1.InverseOrientation

part1.UpdateObject sketch1

End Sub 

Drew Mumaw
www.textsketcher.com
www.drewmumaw.com

RE: Symmetry command in macro for text

(OP)
Almost there!

The declaration for "Sketches" is still causing an issue. Specifically line 21 (set sketch1 = sketches1.Item("Sketch.1").

Now, I don't have much experience with programming, but I try to dissect it. Could the issue be that I do not put ANY sketches or GSD components inside bodies? I keep them in a separate Geometric Set. Seems like the declaration of sketches only looks inside the bodies, not geo sets.

RE: Symmetry command in macro for text

Correct. The sketch would need to be located in the body named PartBody based on the code you have shared. You would need to use the Sketches collection of the HybridBody(Geometric Set) in order to find the Sketch named "Sketch.1".


RE: Symmetry command in macro for text

The problem is that my sketch was in a partbody and yours is in a geo set.

Use Insert > Object resolution... and then select the sketch in the tree to see it's path.

Drew Mumaw
www.textsketcher.com
www.drewmumaw.com

RE: Symmetry command in macro for text

(OP)
So, I need to keep all sketches inside separate geometrical sets (the way things are done around here). Drew, I'm trying your suggestion, but "Object" is grayed out.

I tried manipulating my code, but something is still not working...

Sub CATMain()

dim partDocument1 As PartDocument
set partDocument1 = CATIA.ActiveDocument

dim part1 As Part
set part1 = partDocument1.Part

part1.update

dim bodies1 As HybridBodies
set bodies1 = part1.HybridBodies

dim body1 As Body
set body1 = bodies1.Item("Construction: ID Plate")

MsgBox body1.Name

dim sketches1 As Sketches
set sketches1 = body1.Sketches This is where the compiler stops and gives me an error.

MsgBox sketches1.Name

dim sketch1 As Sketch
set sketch1 = sketches1.Item("ID")

sketch1.InverseOrientation

End Sub


Really appreciate the help guys.


RE: Symmetry command in macro for text

(OP)
Managed to figure it out and make it work! Here is the code..

Sub CATMain()

dim partDocument1 As PartDocument
set partDocument1 = CATIA.ActiveDocument

dim part1 As Part
set part1 = partDocument1.Part

'MsgBox part1.Name

dim hybridBodies1 As HybridBodies
set hybridBodies1 = part1.HybridBodies.Item(1)

'MsgBox hybridBodies1.Name

dim sketch1 As Sketch
set sketch1 = hybridBodies1.HybridSketches.Item("ID")

'MsgBox sketch1.Name

sketch1.InverseOrientation

part1.Update

End Sub


One question... This macro flips the orientation of the sketch along the X-axis. Is there a simple way to flip this sketch along the Y-axis?

RE: Symmetry command in macro for text

Insert > Object resolution... is found in the VBA editor not CATIA.

A helpful tip: put your cursor anywhere in your code and hit F1 to bring up the documentation for that code. This will come in handy when learning.

Drew Mumaw
www.textsketcher.com
www.drewmumaw.com

RE: Symmetry command in macro for text

(OP)
Wow what a great feature. Thanks a lot Drew!

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