Macro Catia drawing layout get dimensions and geometrical tolerance
Macro Catia drawing layout get dimensions and geometrical tolerance
(OP)
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 --> VBA
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 




RE: Macro Catia drawing layout get dimensions and geometrical tolerance
Bellow an example how you can get dimensions value in a SELECTED VIEW (you have to adapt the code to your needs)
Sub CATMain()
Dim MyDocument As DrawingDocument
Set MyDocument = Catia.ActiveDocument
Dim MyDimension As DrawingDimension
Dim I As Long
Dim selection1 As Object '
Set selection1 = MyDocument.Selection
selection1.Search "CATDrwSearch.DrwDimension,sel"
For I = 1 To selection1.Count
Set MyDimension = selection1.Item(I).Value
MsgBox MyDimension.GetValue.Value 'Display the result for dimesion number i
Next
End Sub
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: Macro Catia drawing layout get dimensions and geometrical tolerance
I have a question.
How apply this macro to view in 3d, in a part view?
For found the value of a line for example
Because i try to run this macro but doesn´t work
I work with V5R20, but i don´t think that this are the problem
Thank you very much
RE: Macro Catia drawing layout get dimensions and geometrical tolerance
The macro posted above is working only in 2D (Drafting Workbench), in CATScript.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: Macro Catia drawing layout get dimensions and geometrical tolerance
How can i modify/get drawingdimension text height using macro. I tried with GetBoundaryBox method which returns an error "Function or Interface marked as restricted, or function uses an Automation type not supported in Visual Basic". Please Help
Regards
RE: Macro Catia drawing layout get dimensions and geometrical tolerance
thanks a lot for your question, I had to change some part of your code :"CATDrwSearch.DrwDimension,sel" returned 0 selection, so I had to change "sel" into "all". So I selected 160 dimensions but I have still a problem, when I call the method "getValue.Value" I got a run-time error "-2147023898(800703e6)": Method 'NbExtLine' of object 'DrawingDimension' failed. So I googled 2147023898 and it seems like I don't have memory acces to the value.
Do you have any idea how I can solve this issue ?
RE: Macro Catia drawing layout get dimensions and geometrical tolerance
So, select first a view and then run the CATScript. Read the code also, I believe you can understand more about what is doing.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: Macro Catia drawing layout get dimensions and geometrical tolerance
RE: Macro Catia drawing layout get dimensions and geometrical tolerance
In fact, in which workbench you want to run the macro and what you want to do exactly? Even better, maybe an example CATIA file it will be also good to understand what you want to do, maybe someone here give you more advices.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: Macro Catia drawing layout get dimensions and geometrical tolerance
RE: Macro Catia drawing layout get dimensions and geometrical tolerance
If your part (3D) is done in FTA workbench, this is another story. I don't have access to that workbench so you can search the forum how to get Annotations Sets in Excel from 3D.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208