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
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