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 to extract dimensions related to Instantiate 2D symbol in catia drawing & export them in e

Status
Not open for further replies.

friendlyamu

Mechanical
May 28, 2013
13
IN
Hi friends,

Am new to this forum...

i heard about this forum through my frnds.

happy to be part of this forum.

I need a macro very urgently to extract the dimensions near to the Instantiate 2D component symbols in CatiaV5 drawing and save/export those dimensions to an excell file.

am using Catia V5 R19....

Please do the needful...

 
Replies continue below

Recommended for you

Hi drewmumaw,understood from your reply that it is difficult to retrieve angle value in a Chamfer dimension. Please update once you get some success in this regard. But after running the code for a Chamfer dimension in the format Angle x Distance in a drawing,Code exports (only) the Angle value as Radian value to the .csv file. All other Angle values in the drawings are coming perfectly.Is it possible to fix this ?
With regards to DBalaji89's suggestion, it is definitely necessary to have some way to identify the dimension extracted in the .csv file. This way of giving balloon number & extracting it along with the corresponding dimension in the same line in the .csv is highly appreciated.Also it would be very helpful to accomplish my task if you can post the code that exports balloon numbers along with the dimension.
 
@DBalaji89
If you want the script to output the corresponding view that the dimension is located within use this:

Code:
Sub CATMain()
    
    Dim oDwgDoc1 As DrawingDocument
    
    On Error Resume Next
        Set oDwgDoc1 = CATIA.ActiveDocument
        If Err.Number <> 0 Then
            MsgBox ("The active document must be a drawing."), vbExclamation
            End
        End If
    On Error GoTo 0
    
    Dim oSel As Selection
    Set oSel = oDwgDoc1.Selection
    
    If oSel.Count < 1 Then
        MsgBox ("No dimensions selected."), vbExclamation
        End
    End If

    Dim oDwgDim As DrawingDimension
    Dim oInt As Integer
    Dim dblDims()
    
    Dim oTolType As Long
    Dim oTolName As String
    Dim oUpTol As String
    Dim oLowTol As String
    Dim odUpTol As Double
    Dim odLowTol As Double
    Dim oDisplayMode As Long
    
    For ctr = 1 To oSel.Count
        
        On Error Resume Next
            Set oDwgDim = oSel.Item(ctr).Value
            If Err.Number <> 0 Then
                MsgBox ("One of the selected elements is not a drawing dimension."), vbExclamation
                End
            End If
        On Error GoTo 0
        
        ReDim Preserve dblDims(3, ctr - 1)
        If oDwgDim.DimType = catDimAngle Then
            dblDims(0, ctr - 1) = oDwgDim.GetValue.Value * 57.2957795
        Else
            dblDims(0, ctr - 1) = oDwgDim.GetValue.Value
        End If
        oDwgDim.GetTolerances oTolType, oTolName, oUpTol, oLowTol, odUpTol, odLowTol, oDisplayMode
        dblDims(1, ctr - 1) = odUpTol
        dblDims(2, ctr - 1) = odLowTol
        dblDims(3, ctr - 1) = oDwgDim.Parent.Parent.Name
        odUpTol = 0
        odLowTol = 0
        
    Next
    
    Dim strFilePath As String
    Dim objFSO As Object
    Dim objStream As Object
    
    strFilePath = "C:\Users\Drew\Desktop\dimensions.csv"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objStream = objFSO.OpenTextFile(strFilePath, 8, True, 0)
    
    For i = 1 To oSel.Count
        objStream.WriteLine (dblDims(0, i - 1) & "," & dblDims(1, i - 1) & "," & dblDims(2, i - 1) & "," & dblDims(3, i - 1))
    Next

    objStream.Close

End Sub

Regards,
Drew Mumaw
 
@friendlyamu
I just saw your response after my browser refreshed. Hopefully the code I just posted for exporting the view name will suffice for locating the dimension.

Also, with regards to this:

friendlyamu said:
after running the code for a Chamfer dimension in the format Angle x Distance in a drawing,Code exports (only) the Angle value as Radian value to the .csv file. All other Angle values in the drawings are coming perfectly.Is it possible to fix this ?

Yes. It is possible to fix this, but all of your chamfer dimensions must be in the same format - either angle x distance or distance x angle. They can't be a mix of the two because there's no way that I've found in the API to grab the second dimension. So either it will export the angle (in degrees) if it's in the format angle x distance or the distance if it's in the format distance x angle.

Regards,
Drew Mumaw
 
Hi Drewmumaw,code works excellent. Code exports the selected Dimensions with Tolerances(if available)along with the VIEW name. Further I need your support on the following 2 points, 1)How about the earlier case that we discussed for extracting the balloon numbers (having positional link) along with the corresponding dimensions & put them in the same line. Can you provide the code for this ? 2) Also as per your suggestion, we will follow a consistency in providing the Chamfer dimension format as "angle x distance". So please help us in extracting the angle value for the Chamfer dimension in degrees (which is getting extracted as Radians as of now). Thanks for your constant support in this regard.
 
@friendlyamu
1. It's possible to extract the associated balloons, but it would require a loop to get all of the balloon's associated elements and then check to see if the associated element's dimension is getting exported. If it is, then it would also export that balloon's value. Long story short, it requires a lot more code, but would include the AssociateElement property:

Code:
Dim oBalloon As DrawingText
Set oBalloon = drawingTexts1.GetItem("Balloon.1")

oBalloon.AssociativeElement

2. If you have all chamfers in the format angle x distance then give this code a try. It should export the angle in degrees instead of radians.

Code:
Sub CATMain()
    
    Dim oDwgDoc1 As DrawingDocument
    
    On Error Resume Next
        Set oDwgDoc1 = CATIA.ActiveDocument
        If Err.Number <> 0 Then
            MsgBox ("The active document must be a drawing."), vbExclamation
            End
        End If
    On Error GoTo 0
    
    Dim oSel As Selection
    Set oSel = oDwgDoc1.Selection
    
    If oSel.Count < 1 Then
        MsgBox ("No dimensions selected."), vbExclamation
        End
    End If
    
    Dim oDwgDim As DrawingDimension
    Dim oInt As Integer
    Dim dblDims()
    
    Dim oTolType As Long
    Dim oTolName As String
    Dim oUpTol As String
    Dim oLowTol As String
    Dim odUpTol As Double
    Dim odLowTol As Double
    Dim oDisplayMode As Long
    
    For ctr = 1 To oSel.Count
        
        On Error Resume Next
            Set oDwgDim = oSel.Item(ctr).Value
            If Err.Number <> 0 Then
                MsgBox ("One of the selected elements is not a drawing dimension."), vbExclamation
                End
            End If
        On Error GoTo 0
        
        ReDim Preserve dblDims(3, ctr - 1)
        If oDwgDim.DimType = catDimAngle Or oDwgDim.DimType = catDimChamfer Then
            dblDims(0, ctr - 1) = oDwgDim.GetValue.Value * 57.2957795
        Else
            dblDims(0, ctr - 1) = oDwgDim.GetValue.Value
        End If
        oDwgDim.GetTolerances oTolType, oTolName, oUpTol, oLowTol, odUpTol, odLowTol, oDisplayMode
        dblDims(1, ctr - 1) = odUpTol
        dblDims(2, ctr - 1) = odLowTol
        dblDims(3, ctr - 1) = oDwgDim.Parent.Parent.Name
        odUpTol = 0
        odLowTol = 0
        
    Next
    
    Dim strFilePath As String
    Dim objFSO As Object
    Dim objStream As Object
    
    strFilePath = "C:\Users\Drew\Desktop\dimensions.csv"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objStream = objFSO.OpenTextFile(strFilePath, 8, True, 0)
    
    For i = 1 To oSel.Count
        objStream.WriteLine (dblDims(0, i - 1) & "," & dblDims(1, i - 1) & "," & dblDims(2, i - 1) & "," & dblDims(3, i - 1))
    Next

    objStream.Close

End Sub

Regards,
Drew Mumaw
 
Hi drewmumaw, code works great. Thanks a lot for your help and support.
 
Dear all,

Great work, I found this macro. But we have lot of problems with VBA, if possible could you translate it to catscript or catvbs format with balloon function?

regards,
Catia user/looser :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top