Wifirex
Mechanical
- Nov 12, 2018
- 9
Ref: thread560-349581
Here is the working version of what the previous thread managed to achieve. Still a long shot from what I am looking for but someone may find it useful.
I will clarify in my next post what exactly these guys were trying to do, and see if anyone can collaborate with me by picking up where these guys left off to get this macro working.
Schöne Grüße aus Berlin
Here is the working version of what the previous thread managed to achieve. Still a long shot from what I am looking for but someone may find it useful.
Code:
' ==============================================================
' Purpose: Code to create a text file in Folder (MUST BE SPECIFIED BELOW) and write CATDrawing points coordinates inside from the currently active view
' Usage: 1 - A CATDrawing document must be active and drawn points must be present (CATPart points don't work)
' 2 - Run macro
' Author: modifed by ferdo, originator unknown (Disclaimer: You use this code at your own risk)
' ===============================================================
Sub CATMain()
Dim Documents1 'As Documents
Dim DrawDocument1 'As DrawingDocument
Dim DrawSheets1 'As DrawingSheets
Dim DrawSheet1 'As DrawingSheet
Dim GeoEle 'As GeometricElements
Dim Pt2D 'As Point2D
On Error Resume Next
' Code to create and write in a file
' The resulting file its not so fine, I don't have time to make it look better....
Dim sPath 'As PathString
Dim sTime 'As TimeString
Dim sName 'As TimeString
Dim sFile 'As TimeString
documentname = CATIA.ActiveDocument.Name
position = InStr(documentname,".CATDrawing")
position = position -1
documentname = Left(documentname,position)
sPath = "C:\Users\XXXXXXXX" ' <<<<< SPECIFY PATH HERE
'~ sPath = CATIA.Application.SystemService.Environ("CATReport")
sName = "\XYDrawing_" & documentname & ".TXT"
sFile = sPath & sName
Set oFileOut = CATIA.FileSystem.CreateFile(sFile,TRUE)
Dim oStream 'As TextStream
Set oStream = oFileOut.OpenAsTextStream("ForWriting")
' Code for Points
Set documents1 = CATIA.Documents
Set drawDocument1 = CATIA.ActiveDocument
Set DrawSheets1 = drawDocument1.Sheets
Set DrawSheet1 = DrawSheets1.ActiveSheet
Set DrawViews = DrawSheet1.Views
Set DrawView1 = DrawViews.ActiveView
Set GeoEle = DrawView1.GeometricElements
For i = 1 To GeoEle.Count
Set Pt2d = GeoEle.Item(i)
Dim coord(1)
if Pt2d.GeometricType = 2 then ' GeometricElement 2 = CatGeotypePoint2D
Pt2d.GetCoordinates coord
' change value in inch if you want, just delete ' (the comment sign)
coord(0) = coord(0)'/25.4
coord(1)=coord(1)'/25.4
end if
Set Point(i) = GeoEle.Item(i).Value
oStream.Write (Pt2d.Name&" :"&coord(0)&" , "&coord(1))
Next
oStream.close
MsgBox "Check the file : " & sFile, vbInformation ' information about where the file is
End Sub
I will clarify in my next post what exactly these guys were trying to do, and see if anyone can collaborate with me by picking up where these guys left off to get this macro working.
Schöne Grüße aus Berlin