×
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 VB Programming, Get the name and place it as the text file name.

CATIA VB Programming, Get the name and place it as the text file name.

CATIA VB Programming, Get the name and place it as the text file name.

(OP)
I have learned how to get the name of the part file and place it as the name of the text file that I want to write to, but my problems are:

1. I can only get it to make the new text file write to drive C:
2. And I cannot internally populate the points at the same time using stream writer, because I have to make it get the file name from CATIA.

How do I accomplish this?

My Code:


Sub CATMain()


'==================Call Variables=====================================

Dim ObjFso
Dim SourceLocation
Dim DestinationLocation
Dim SourceFileName
Dim DestinationFileName
SourceLocation = "C:TestFolder1"
DestinationLocation = "C:TestFolder2"
SourceFileName = "Source File.txt"
DestinationFileName = "Destination File.txt"

Dim aToExport(5000, 3) As Variant
Dim iNumberOfPoint As Integer
Dim sTime As String
Dim sName As String
Dim FileObj


'=================CATIA Declarations===================================

On Error Resume Next

Set PartDocument1 = CATIA.ActiveDocument

Set part1 = PartDocument1.Part

Set hybridShapeFactory1 = part1.HybridShapeFactory

Set objNetwork = CreateObject("Wscript.Network")

Set hb1 = CATIA.ActiveDocument.Part.InWorkObject

Set hsf = CATIA.ActiveDocument.Part.HybridShapeFactory

Set prt = CATIA.ActiveDocument.Part

Set sel = CATIA.ActiveDocument.Selection

Set SPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")

Set PlaneZX = CATIA.ActiveDocument.Part.OriginElements.PlaneZX

' Reset the Selection

Set sSEL = CATIA.ActiveDocument.Selection

sSEL.Clear


'====================Create A Text File With CATIA Part Name===============


sTime = Replace(Time, ":", "-")

sName = "C:\" & Left(CATIA.ActiveDocument.Name, Len(CATIA.ActiveDocument.Name) - 8) & "-" & sTime & ".txt" '<----Creates A file with the Active Part Name in CATIA

Open sName For Output As #1 ' open file for writting


Set FileSys = CATIA.FileSystem


'=================Select The Objects In CATIA And Write To File============


'FileObj = FileSys.CreateFile("C:\pointsout.txt"=

Set TextsTr = FileObj.OpenAsTextStream("ForWriting")

Dim selection1

Set selection1 = PartDocument1.Selection

selection1.Add part1.FindObjectByName("RibPath")

selection1.Search "CATPrtSearch.Point,sel"



Dim Coord(2) '<-----Other Code

For I = 1 To selection1.Count '<-----Count Each Point Other Code

Dim CurrWorkbench '<----WorkBench Variable

Set CurrWorkbench = PartDocument1.GetWorkbench("SPAWorkbench") '<----Get Current WorkBench in CATIA

Dim Measure '<-----Measure Variable

Set Measure = CurrWorkbench.GetMeasurable(selection1.Item(I).Reference) '<----Get Current Measurement

Measure.GetPoint Coord '<------Getting the Points Using Measure Method

TextsTr.Write (Coord(0) / 25.4 & ", " & Coord(1) / 25.4 & ", " & Coord(2) / 25.4 & vbCrLf) '<-----Writes the Coordinates in inches

Set FileObj = FileSys.CreateFile("C:\pointsout.txt", True) '<----This does work in writing the points to a text file, but doesn't have the Part Name instead it makes the text file "pointsout.txt


Next



part1.Update


Close

MsgBox "Check the file : " & sName, vbInformation ' information about job done



'==============Create A Directory Folder If It Doesn't Exist==============


strFolderPath = FolderPath & "\" & FolderName
If Dir(strFolderPath, vbDirectory) = "" Then
Set FileObj = FileSys.CreateFolder("C:\Tube Production")

Else

Set FileObj = FileSys.CreateFolder("C:\Tube Production")

End If


'==============Copy A File To The File To Folder "Tube Production=========



Set FileSys = My.Computer.FileSystem
My.Computer.FileSystem.RenameFile "C:\Tube Production\pointsout.txt", "C:\Tube Production\" & Left(CATIA.ActiveDocument.Name, Len(CATIA.ActiveDocument.Name) - 8) & ".txt" <----Doesn't work, but I tried to make it change the name to CATIA Active Document Part Name



End Sub

RE: CATIA VB Programming, Get the name and place it as the text file name.

I used to do some thing similar to this out of KeyCreator. it came in quite handy for cnc bend chart data using excel.. reminiscing aside..

i believe the answer to your question is this.

CODE

Sub CATMain()


'==================Call Variables=====================================

Dim ObjFso
Dim SourceLocation
Dim DestinationLocation
Dim SourceFileName
Dim DestinationFileName
SourceLocation = "C:TestFolder1"
DestinationLocation = "C:TestFolder2"
SourceFileName = "Source File.txt"
DestinationFileName = "Destination File.txt"

Dim aToExport(5000, 3) As Variant
Dim iNumberOfPoint As Integer
Dim sTime As String
Dim sPath As String '<---------------------------------------------------------------------------------------------------added
Dim sName As String
Dim FileObj


'=================CATIA Declarations===================================

On Error Resume Next

Set PartDocument1 = CATIA.ActiveDocument

Set part1 = PartDocument1.Part

Set hybridShapeFactory1 = part1.HybridShapeFactory

Set objNetwork = CreateObject("Wscript.Network")

Set hb1 = CATIA.ActiveDocument.Part.InWorkObject

Set hsf = CATIA.ActiveDocument.Part.HybridShapeFactory

Set prt = CATIA.ActiveDocument.Part

Set sel = CATIA.ActiveDocument.Selection

Set SPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")

Set PlaneZX = CATIA.ActiveDocument.Part.OriginElements.PlaneZX

' Reset the Selection

Set sSEL = CATIA.ActiveDocument.Selection

sSEL.Clear


'====================Create A Text File With CATIA Part Name===============


sTime = Replace(Time, ":", "-")

sPath = Left(CATIA.ActiveDocument.Path, len(CATIA.ActiveDocument.Path))   '<------------------------------------------------------------------added

sName = sPath & Left(CATIA.ActiveDocument.Name, Len(CATIA.ActiveDocument.Name) - 8) & "-" & sTime & ".txt" '<----Creates A file with the Active Part Name in CATIA <-- modified

Open sName For Output As #1 ' open file for writting


Set FileSys = CATIA.FileSystem


'=================Select The Objects In CATIA And Write To File============


'FileObj = FileSys.CreateFile("C:\pointsout.txt"=

Set TextsTr = FileObj.OpenAsTextStream("ForWriting")

Dim selection1

Set selection1 = PartDocument1.Selection

selection1.Add part1.FindObjectByName("RibPath")

selection1.Search "CATPrtSearch.Point,sel"



Dim Coord(2) '<-----Other Code

For I = 1 To selection1.Count '<-----Count Each Point Other Code

Dim CurrWorkbench '<----WorkBench Variable

Set CurrWorkbench = PartDocument1.GetWorkbench("SPAWorkbench") '<----Get Current WorkBench in CATIA

Dim Measure '<-----Measure Variable

Set Measure = CurrWorkbench.GetMeasurable(selection1.Item(I).Reference) '<----Get Current Measurement

Measure.GetPoint Coord '<------Getting the Points Using Measure Method

TextsTr.Write (Coord(0) / 25.4 & ", " & Coord(1) / 25.4 & ", " & Coord(2) / 25.4 & vbCrLf) '<-----Writes the Coordinates in inches

Set FileObj = FileSys.CreateFile("C:\pointsout.txt", True) '<----This does work in writing the points to a text file, but doesn't have the Part Name instead it makes the text file "pointsout.txt 


Next



part1.Update


Close

MsgBox "Check the file : " & sName, vbInformation ' information about job done



'==============Create A Directory Folder If It Doesn't Exist==============


strFolderPath = FolderPath & "\" & FolderName
If Dir(strFolderPath, vbDirectory) = "" Then
Set FileObj = FileSys.CreateFolder("C:\Tube Production")

Else

Set FileObj = FileSys.CreateFolder("C:\Tube Production")

End If


'==============Copy A File To The File To Folder "Tube Production"=========



Set FileSys = My.Computer.FileSystem
My.Computer.FileSystem.RenameFile "C:\Tube Production\pointsout.txt", "C:\Tube Production\" & Left(CATIA.ActiveDocument.Name, Len(CATIA.ActiveDocument.Name) - 8) & ".txt" <----Doesn't work, but I tried to make it change the name to CATIA Active Document Part Name



End Sub 

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