ososynoido
Automotive
Hi everybody,
I'm new in programming macro with catia and I'm trying to get in an excel file some text, dimension and geometrical tolerance automatically.
I wrote a part of the code and I can get Text without problem but I face 2 problems : I don't have any idea how to get geometrical tolerances and when I try to get dimensions, I get an runtime error (method 'NbExtLine' of object 'DrawingDimension' failed although I call the method GetValue)
Any advice would be really helpful
I'm new in programming macro with catia and I'm trying to get in an excel file some text, dimension and geometrical tolerance automatically.
I wrote a part of the code and I can get Text without problem but I face 2 problems : I don't have any idea how to get geometrical tolerances and when I try to get dimensions, I get an runtime error (method 'NbExtLine' of object 'DrawingDimension' failed although I call the method GetValue)
Any advice would be really helpful
Code:
Sub CATMain()
On Error Resume Next
Set oSysService = CATIA.SystemService
osds = oSysService.Environ("OSDS")
Set settingControllers1 = CATIA.SettingControllers
Dim Rtnm, name, datum, searchstr As String
Dim flname As String
Dim i, j, n, k, ps1, ps2, cntrl, psit As Integer
Dim Docs As Documents
Set Docs = CATIA.Documents
Dim SheetCollection As DrawingSheets
Dim Sheet As DrawingSheet
Dim PrdDOC, RtDOC As Document
Dim product2 As Product
Set RtDOC = CATIA.ActiveDocument
Rtnm = RtDOC.name
'MsgBox Rtnm
Set Docs = CATIA.Documents
Set SheetCollection = CATIA.ActiveDocument.Sheets
Dim sDocType, dtyp, docname As String
For i = 1 To Docs.Count
Set PrdDOC = Docs.Item(i)
name = Docs.Item(i).name
' MsgBox name
Next
Dim Viewcollection As DrawingView
Dim compo As DrawingComponent
Dim drwdim As DrawingDimension
Dim text As DrawingTexts
Dim typ, display As Long
Dim val
Dim tolname, uptol, lowtol As String
Dim uptolval, lowtolval As Double
Dim catdim As CatDimType
Dim dimdimvalue As DrawingDimValue
Dim geo As GeometricElement
Dim yesno As Boolean
For i = 1 To SheetCollection.Count
Set Sheet = SheetCollection.Item(i)
name = Sheet.name
' MsgBox "worksheet name : " & name
For j = 1 To Sheet.Views.Count
Set Viewcollection = Sheet.Views.Item(j)
'If Viewcollection.Texts.Count > 0 Then
' For k = 1 To Viewcollection.Texts.Count
' If MsgBox(Viewcollection.Texts.Item(1).text, vbQuestion + vbOKCancel) <> vbOK Then
' Exit Sub
' End If
'Next
'End If
'For l = 1 To Viewcollection.Components.Count
' Set compo = Viewcollection.Components.Item(l)
' If MsgBox("worksheet name : " & name & "composant name : " & compo.name & "x : " & compo.X & "y : " & compo.Y, vbQuestion + vbOKCancel) <> vbOK Then
' Exit Sub
' End If
'Next
For m = 1 To Viewcollection.Dimensions.Count
Set drwdim = Viewcollection.Dimensions.Item(m)
'drwdim.GetTolerances typ, tolname, uptol, lowtol, uptolval, lowtolval, display
' catdim = drwdim.DimType
name = drwdim.name
Set dimdimvalue = drwdim.GetValue
MsgBox Err.Description
'drwdim.GetTolerances(
If MsgBox("worksheet name : " & "drwdim : " & name & " drwdim name : " & drwdim.name & " value : " & val, vbQuestion + vbOKCancel) <> vbOK Then
Exit Sub
End If
Next
'For m = 1 To Viewcollection.GeometricElements.Count
' Set geo = Viewcollection.GeometricElements.Item(m)
' If MsgBox("geo name :" & geo.name & " type : " & geo.GeometricType, vbQuestion + vbOKCancel) <> vbOK Then
' Exit Sub
' End If
'Next
'For m = 1 To Viewcollection.re
' Set tabl = Viewcollection.Tables.Item(m)
'
' If MsgBox("tabl name :" & tabl.name, vbQuestion + vbOKCancel) <> vbOK Then
' Exit Sub
' End If
'Next
'Viewcollection.ReferenceView.name
Next
Next
'Dim foundobject As AnyObject
'CATIA.ActiveDocument.Selection.Search "Name='SEC.REG',all"
'For i = 1 To CATIA.ActiveDocument.Selection.Count
' Set Selection = CATIA.ActiveDocument.Selection
' Set Element = Selection.Item(i)
' Set Point = Element.Value
' MsgBox foundobject.name
' MsgBox "x : " & foundobject.X
' CATIA.ActiveDocument.Sheets
' Point.Getcoorinates (coords)
' MsgBox Point.name
'Catia.ActiveDocument.Selection.FindObject(
'Next
End Sub