×
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 Looping through PartBody and Pasting to New Part

Catia VBA Looping through PartBody and Pasting to New Part

Catia VBA Looping through PartBody and Pasting to New Part

(OP)
Hello,

Apologies if this has been posted before, I have searched and have not found a solution. I am new to Catia VBA, but have used Excel VBA before.

What do I want to do? I have created a Part with a number of Surfaces. I need to create an IGES files containing a single Surface for all the Surfaces with the Part.

How I have approached the problem, I have a Part that contains 10+ surfaces, using 'SelectElement3' I can select the the surfaces I want to export and I have created a loop that loops through the number of Surfaces I have selected. I then create a new part and copy & paste the Surface and then create the IGES file.

What is going wrong, Instead of pasting a single surface into the New Part the code pastes all the selected surfaces and then creates the IGES files! I feel I am struggling to understand the differences between Objects, Selection, PartDocument and Part. I also do not understand how to loop through the selected PartBody and then pass this to the object that pastes the Surface into the New Part.

Here is my Code,
Option Explicit

Private Sub subCreateIGES()

' Objects
Dim objSel As Selection
Dim objSelLB As Object
Dim objTgtDoc As PartDocument
Dim objTgt As Part
Dim objTgtSel As Selection

' Array
Dim InputObjectType(0)

' String
Dim Status As String
Dim strPartName As String

' Integer
Dim intCounter As Integer

Set objSel = CATIA.ActiveDocument.Selection
Set objSelLB = objSel

InputObjectType(0) = "Face"

Status = objSelLB.SelectElement3(InputObjectType, "Select points", True, CATMultiSelTriggWhenUserValidatesSelection, False)

If Status = "Cancel" Then Exit Sub

For intCounter = 1 To objSelLB.Count2

Set objTgtDoc = CATIA.Documents.Add("Part")
Set objTgt = objTgtDoc.Part
Set objTgtSel = objTgtDoc.Selection
Set objTgtDoc = CATIA.ActiveDocument

' Sets and Pastes in Target file as result
objTgtSel.Clear
objTgtSel.Add objTgt.Bodies.Item("PartBody")
objTgtSel.PasteSpecial ("CATPrtResult")

' Creates IGES file
CATIA.DisplayFileAlerts = False
objTgtDoc.ExportData "P:\Temp\IGES_" & intCounter & ".igs", "igs"
CATIA.DisplayFileAlerts = True

objTgtDoc.Close

Next intCounter

End Sub

Thanks in advance any help you may be able to provide.

Thanks James

RE: Catia VBA Looping through PartBody and Pasting to New Part

Hello,

Those surfaces are joined surfaces, or single surfaces in your file?
You need to see, what's happening after the objTgtSel.PasteSpecial ("CATPrtResult"). Probably when you make the paste, every surface is already there, and then all surfaces are converted.

Tiago Figueiredo
Tooling Engineer

Youtube channel:
https://www.youtube.com/channel/UC1qdlBeJJEgMgpPLV...

RE: Catia VBA Looping through PartBody and Pasting to New Part

(OP)
Hello Tiago,

Thank you for your response.

They are single surfaces.

Correct, after the code 'objTgtSel.PasteSpecial ("CATPrtResult")' all of the selected surfaces have been pasted into the new Part, which are then converted into the IGES file. I want to loop through the selected surfaces and only single surfaces to be pasted and converted to IGES with each loop.

Thanks James

RE: Catia VBA Looping through PartBody and Pasting to New Part

Try this:

CODE -->

Private Sub subCreateIGES()

' Objects
Dim objSel As Selection
Dim objSelLB As Object
Dim objTgtDoc As PartDocument
Dim objTgt As Part
Dim objTgtSel As Selection

' Array
Dim InputObjectType(0)

' String
Dim Status As String
Dim strPartName As String

' Integer
Dim intCounter As Integer
Dim Num_Surfaces As Integer

Dim Surface()

Set objSel = CATIA.ActiveDocument.Selection
Set objSelLB = objSel

InputObjectType(0) = "Face"

Status = objSelLB.SelectElement3(InputObjectType, "Select points", True, CATMultiSelTriggWhenUserValidatesSelection, False)

If Status = "Cancel" Then Exit Sub
Num_Surfaces = objSelLB.Count2
ReDim Preserve Surface(Num_Surfaces)

For intCounter = 1 To Num_Surfaces
Surface(intCounter) = objSelLB.Item(intCounter).Value
Next


For intCounter = 1 To objSelLB.Count2
objSelLB.Clear
objSelLB.Add (Surface(intCounter))
objSelLB.Copy
Set objTgtDoc = CATIA.Documents.Add("Part")
Set objTgt = objTgtDoc.Part
Set objTgtSel = objTgtDoc.Selection
Set objTgtDoc = CATIA.ActiveDocument

' Sets and Pastes in Target file as result
objTgtSel.Clear
objTgtSel.Add objTgt.Bodies.Item("PartBody")
objTgtSel.PasteSpecial ("CATPrtResult")

' Creates IGES file
CATIA.DisplayFileAlerts = False
objTgtDoc.ExportData "P:\Temp\IGES_" & intCounter & ".igs", "igs"
CATIA.DisplayFileAlerts = True

objTgtDoc.Close

Next intCounter

End Sub 

Tiago Figueiredo
Tooling Engineer

Youtube channel:
https://www.youtube.com/channel/UC1qdlBeJJEgMgpPLV...

RE: Catia VBA Looping through PartBody and Pasting to New Part

(OP)
Hello Tiago,

You are a star, thank you so much.

Cheers James

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