Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro Catia drawing layout get dimensions and geometrical tolerance

Status
Not open for further replies.

ososynoido

Automotive
Oct 17, 2012
4
FR
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

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
 
Replies continue below

Recommended for you

Hi,

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

 
Hi firends

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

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
 
Hello Fredo,

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 ?
 
hello I think the value I try to get are maybe not in dimension but could be in annotation. Is there an easy way to switch from dimension to annotation or should I search in Catprod/Catpart ?
 
Lets clarify a little bit....in your initial posted code, as far as I can see, everything is done for the 2D drafting workbench.

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

 
Sorry, my post wasn't that clear, so I had a screenshot of the drawing to give you a better idea. When I run the macro, after "selection.Search "CATDrwSearch.DrwDimension,all" I selected all dimension of the drawing but still I can not read it, so I think those value come directly from 3D part as annotation. Regarding geometrical tolerance, I don't have any idea how to export it to excel.
 
 http://files.engineering.com/getfile.aspx?folder=9e2a9197-705c-4c56-94a0-6babdfc74b9b&file=SC_dimension.JPG
Again, my first code is working if you will select first a drawing view. If you want to do it for all drawing you have to do a loop thru all views (of course, again, you need to modify the code). I never tried to get geometrical tolerances and I don't have time to do it now.

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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top