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

@friendlyamu
Are you referring to the dimensions that can be found by right-clicking the component instance in the tree and clicking on Properties and looking under the 2D Component Instance tab? See attached image for clarification.

If yes, then you can use the following code. I will need you to respond and clarify what sheet and view the instance is located on. Also, where and under what name do you want the excel file to be saved? Right now, this code simply outputs it via a message box.

Code:
Sub CATMain()

Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument

Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets

Dim drawingSheet1 As DrawingSheet
Set drawingSheet1 = drawingSheets1.Item("Sheet.1")

Dim drawingViews1 As DrawingViews
Set drawingViews1 = drawingSheet1.Views

Dim drawingView1 As DrawingView
Set drawingView1 = drawingViews1.Item("Front view")

Dim drawingComponents1 As DrawingComponents
Set drawingComponents1 = drawingView1.Components

Dim drawingComponent1 As DrawingComponent
Set drawingComponent1 = drawingComponents1.Item("Detail.1.1")

MsgBox "X: " & Round(drawingComponent1.X / 25.4, 2) & vbCr & "Y: " & Round(drawingComponent1.Y / 25.4, 2)

End Sub

Regards,
Drew Mumaw
 
Hi drewmumaw,

Thank you so much for your reply.

Sorry for not mentioned my requirements clearly in my previous thread.

My requirements are,I need a Macro which can export the list of dimensions containing the symbol adjacent to that & save as an excel (or) csv file.

The excel (or) csv file has to be saved in Drawing name and in the folder which contains the respective Catia V5 drawing.

Please see the attached image for clarification...








 
 http://files.engineering.com/getfile.aspx?folder=77460516-8d88-4881-9fb7-4d200b2a9663&file=Query.ppt
@friendlyamu
I understand. So you want to export to a .csv file with all of the dimensions that have a specific symbol next to them, correct? If yes, then my answer is, this cannot be done as you would like unless there's something else (possibly the naming of the dimensions?) that differentiates the dimensions with the symbols from the dimensions without the symbols. It's possible to export all of the dimensions on Sheet.1, but from your screen grab, I don't see how the macro would be able to tell which dims have a symbol associated and which ones don't. There would have to be some manual work after the fact. Or, like I mentioned, if the dimensions with the symbols have something special in their name such as "dimwithsymbol" then the macro could just export those. For example, a dimension with a symbol could be named "Dimension.4.dimwithsymbol" and the script would sort through all of the dims and include this one for export since it had the "dimwithsymbol" string in the name.

I put this macro together quickly to show you how to loop through all of the dims in each of the views on "Sheet.1". It just shows them in a message box pop up one at a time. It doesn't process angles correctly and doesn't have a way of telling dims with symbols apart from the dims without symbols:

Code:
Sub CATMain()

Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument

Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets

Dim drawingSheet1 As DrawingSheet
Set drawingSheet1 = drawingSheets1.Item("Sheet.1")

Dim drawingViews1 As DrawingViews
Set drawingViews1 = drawingSheet1.Views

For ctrViews = 1 To drawingViews1.Count

    Dim drawingDimensions1 As DrawingDimensions
    Set drawingDimensions1 = drawingViews1.Item(ctrViews)
    
    For ctrDims = 1 To drawingDimensions1.Count
    
        MsgBox drawingDimensions1.Item(ctrDims).GetValue.Value
    
    Next ctrDims

Next ctrViews

End Sub

Regards,
Drew Mumaw
 
Hi drewmumaw

The screen grab which I have attached in my previous thread was just an example. My Drawing may contain ‘N’ number of views (see the ‘Specification Tree’ for the drawing - REV003 in the image attached in my previous thread) and ‘N’ number of dimensions with the symbols and without the symbols in the views.

I dont understand what do you mean by dimension with a symbol could be named "Dimension.4.dimwithsymbol".Did you mean that each dimension with symbol should have an unique TEXT before?

Is it possible to sort and export the dimensions based on the Name given for the ‘Instantiate 2D component” symbol in the Drawing sheet? (For example TRIANGLE_3 (or) DIAMOND) ( Refer attached image)

And I don't want any message box pop up to show the dimensions in the views, thats not my requirement.
 
 http://files.engineering.com/getfile.aspx?folder=77e0e6dc-16a7-442a-b3a2-26156be51d34&file=3Que.ppt
Hi,

@ friendlyamu - be so kind and post what you tried to code to solve your requirements, it will be much easier for others to help you. If you want to learn more about programming first you should try something, don't expect for others to solve your problems completely, what you want is not so easy to be done (and by the way, it can be achieved only if your drawing was done in a specific way, meaning dimension has a link with the ditto, otherwise is to complicated and is wasting developer's time).

Generally speaking, when someone develop a macro for his company (or for himself), is taking in account how often it will be used and how big it will be the benefits using the macro comparing with time to develop that macro.

Regards
Fernando

 
@friendlyamu
The code I uploaded was labeled "vba". According to your screen grab 2Que, it looks like you were trying to test it in a vbscript editor with different syntax. That could possibly be causing the error you mentioned. To test it in CATIA's built in vba editor hit Alt+F11 or simply go to Tools > Macros > Visual Basic Editor. Create a new catvba file if one doesn't already exist. In the left hand side, right-click on the catvba file and insert a new module. See this image. You can put your code in here and run it by clicking the rightward facing arrow that looks like a play button.

Also, I'm aware that the code I uploaded did not solve your requirements, it was simply a starting off point for getting the logic structure together for your eventual solution - as I mentioned in my first post:
drewmumaw said:
I put this macro together quickly to show you how to loop through all of the dims in each of the views on "Sheet.1". It just shows them in a message box pop up one at a time. It doesn't process angles correctly and doesn't have a way of telling dims with symbols apart from the dims without symbols
Right now I simply use message boxes to view what could be output to a .csv - since I'm 100% sure that exporting to a .csv is possible I didn't waste any time including it in the logic. In other words, we can add that requirement last.

Thanks for the screen grabs. They are very helpful.

friendlyamu said:
Is it possible to sort and export the dimensions based on the Name given for the ‘Instantiate 2D component” symbol in the Drawing sheet? (For example TRIANGLE_3 (or) DIAMOND) ( Refer attached image)
No. The name of the "Instantiate 2Dcomponent" is not relevant from an automation standpoint. We need a way to determine which dimensions have a symbol next to them and which ones don't.

friendlyamu said:
I dont understand what do you mean by dimension with a symbol could be named "Dimension.4.dimwithsymbol".Did you mean that each dimension with symbol should have an unique TEXT before?
Yes. If it's feasible from your side of things - something along those lines would work. See this image as just an example of how the dimensions with the symbol could be named. If they all had some string of text in their name, such as "dimwithsymbol" or whatever else, then the macro would be able to know which dimensions need to be exported and which ones don't.

Regards,
Drew Mumaw
 
Hi drewmumaw, as I was away from work I couldn't reply immediately. I need your help in knowing the coding for exporting a selected set of dimensions from Catia V5 drawing to Excel. I'm not a programmer. So only with your support, I can accomplish this task.

 
@friendlyamu
This code will write your selected dimension values to a .csv file on the desktop (you need to change the file path in the code to reference your desktop location - not mine). See here for an example of the output.

Code:
Sub CATMain()

    Dim oDwgDoc1 As DrawingDocument
    Set oDwgDoc1 = CATIA.ActiveDocument
    
    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() As Double
    
    For ctr = 1 To oSel.Count
        Set oDwgDim = oSel.Item(ctr).Value
        ReDim Preserve dblDims(ctr - 1)
        dblDims(ctr - 1) = oDwgDim.GetValue.Value
    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(i - 1))
    Next

End Sub

Regards,
Drew Mumaw
 
Hi drewmumaw,

The code works great. Thanks a lot for your help.

This code exports the selected dimension to the Excel file superbly.

 
Hi drewmumaw, The code exports the nominal value of selected dimensions as .csv but ignores to take it's tolerance value. What should be done for accomplishing this ? Also I would like to know is it possible to export some selected Geometrical Tolerances (Say Flatness, Position etc.,) along with value in the feature control frame to .csv ?
 
@friendlyamu
The code below will also export the tolerance values. I'm not sure about the geometrical tolerances.

Code:
Sub CATMain()

    Dim oDwgDoc1 As DrawingDocument
    Set oDwgDoc1 = CATIA.ActiveDocument
    
    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() As Double
    
    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
        Set oDwgDim = oSel.Item(ctr).Value
        ReDim Preserve dblDims(2, ctr - 1)
        dblDims(0, ctr - 1) = oDwgDim.GetValue.Value
        oDwgDim.GetTolerances oTolType, oTolName, oUpTol, oLowTol, odUpTol, odLowTol, oDisplayMode
        dblDims(1, ctr - 1) = odUpTol
        dblDims(2, ctr - 1) = odLowTol
    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))
    Next
    
End Sub

Regards,
Drew Mumaw
 
Hi,

Geometrical tolerances were not exposed to automation.
There is no API of any kind to access, using object browser also wont yield any results.
Tried some times back with no success



Regards,
Maddy

The willingness to share knowledge does not make one charitable; it makes one self-reliant to know more.
Modified - Courtesy of Robert Brault
 
Hi drewmumaw, code works fine. After running the code I observed the following things,.. 1) Code extract and transfer the Angle value in the drawing as Radian value in the Excel(csv) sheet, 2) For Chamfer dimensions (say, 5*45 deg) code extracts only the 'length' 5 to the excel sheet, 3) Also the tolerance value of the previous listed nominal dimension is taken for the following Angle/Chamfer dimension even though no tolerance is assigned to them. (Refer attached image).

@Maddy02 : Thank a lot for your valuable information.
 
 http://files.engineering.com/getfile.aspx?folder=4da71db1-b42e-4368-8388-44e9550812b3&file=Dim_Tol.ppt
@friendlyamu
This should take care of the tolerance values and radians:

Code:
Sub CATMain()

    Dim oDwgDoc1 As DrawingDocument
    Set oDwgDoc1 = CATIA.ActiveDocument
    
    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() As Double
    
    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
        Set oDwgDim = oSel.Item(ctr).Value
        ReDim Preserve dblDims(2, 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
        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))
    Next

    objStream.Close

End Sub

Regards,
Drew Mumaw
 
Hi,

My requirement is also same that of what friendlyamu posted.But i want to extract some more details to the csv file.

Is it possible to extract the Balloon numbers along with the corresponding dimensions in the extracted csv file?

Please find the image for better understanding.

Thanks in advance.

Regards,

D.Balaji


 
 http://files.engineering.com/getfile.aspx?folder=21855455-7fdf-4e82-a0be-987ed7e65138&file=Reference.png
Hi drewmumaw, Code works great except that it doesn't transfer the Angle value in the Chamfer dimension. Is it possible to fix this ? Thanks for your help.
 
@friendlyamu
I looked, but couldn't find anything in the API for being able to do this. If you put the chamfer dimension in the format angle x distance then it will export the angle, but not the distance. Apparently, you can only access the first value in a chamfer dimension. This seems odd, so I'll keep looking through the API, but I tried several things already and couldn't find a way to access it. Maybe someone else will post a way that this can be done? But from my initial web searches and other threads it seems like automation in the drafting workbench is very restrictive.

@DBalaji89
Yes. It is possible to extract the balloon numbers. However, there must be something for the script to be able to know that the balloon is related to the dimension. Either the balloon should have a positional link (see this) with it's corresponding dimension, or the name of the dimension and the balloon should have a string in both that relates the two. For example, the name of the dimension could be DimensionWithBalloon.5 and the name of the name of the balloon could be Balloon.5. That way the script would know to look for a dimension and a balloon with the name Balloon.5 in them so that it could export them on the same line in the .csv file. I would recommend doing it with the positional link.

Regards,
Drew Mumaw
 
@drewmumaw
First of all i would like to say thanks for your reply.

To be frank, am not a programmer and I don't have any knowledge in writing code in VB.I just suggested to enhance Friendlyamu's requirement.

As per your last code it exports only selected set of dimensions to csv file.In case if the selected set of dimensions(selected from different VIEWS in the drawing) contain a similar dimensions it would be difficult to identify in the csv file that which dimension from which VIEW (or) ZONE in the drawing is exported.

So I requested, Is it possible to extract the Balloon numbers along with the corresponding dimensions in the extracted csv file?

It will be great if you can post the code that can extract Balloon numbers(having positional link with the dimension) along with the dimensions.

Thanks in advance.

Regards,

D.Balaji


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top