Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Symmetry command in macro for text 2

Status
Not open for further replies.

pKayy

Mechanical
Mar 28, 2016
44
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!
 
Replies continue below

Recommended for you

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,
 
Bump. Any help on this would be greatly appreciated.
 
Thanks Drew,

Seem to be getting an issue with sketches1.Item. Compiler says Object required: 'sketches1'. Maybe I need to declare something?
 
@peterkim89
Yes. It's probably a declaration issue. Here's my full code for you to reference.

Code:
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
 
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.
 
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".


 
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.


 
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?
 
Wow what a great feature. Thanks a lot Drew!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor