Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

How to get the Balloon Position from CATIA V5 Drawings using VBA

Status
Not open for further replies.

Sidtha

Aerospace
Nov 25, 2012
30
Hello All,

I am getting the Balloon number from the catia V5 drawings but not able to get the postion of the balloon from the draing view.
Below is my code to get the balloon number, Please help me to get the balloon positon from the drawing view.

Dim wb As Workbook, ws As Worksheet

Sub BOMExtract()

Dim CATIA As Object
Dim myselection As Selection
Dim textlist() As String
Dim showstate As CatVisPropertyShow
Dim dblViewScale As Double
Set wb = ThisWorkbook
Set ws = wb.Sheets("BOM")
LR = ws.Cells(Rows.Count, 1).End(xlUp).Row
ws.Range("A6:H1000").ClearContents
Set CATIA = GetObject(, "CATIA.Application")

Dim DrawingDocument1 As Document
Set DrawingDocument1 = CATIA.ActiveDocument
Set oDrwView = DrawingDocument1.Sheets.ActiveSheet.Views

Dim pattern As String
pattern = "\b(?:\d{1,3}-\d{1,2}|((?<!-)1\d{3}))\b"

j = 6

For i = 1 To oDrwView.Count
For numtxt = 1 To oDrwView.Item(i).Texts.Count
Set CurrentText = oDrwView.Item(i).Texts.Item(numtxt)
If CurrentText.Name Like "*Balloon*" Then
ws.Cells(j, 1).Value = CurrentText.text
j = j + 1
End If
Next numtxt
Next i

On Error GoTo 0
End Sub
BalloonPoition_xkgdby.png
 
Replies continue below

Recommended for you

There is the .x and .y property of a text (It is expressed with respect to the current view coordinate system.)
And you can obtain the x and y position of the view.

regards,
LWolf
 
Hi LWolf,

Yes i tried as you suggested but i am getting only the co ordinates.
Not geeting as i mentined in my question. below is the code updated one.

Need to export the Balloon position like D2 refering with frame values.
For i = 1 To oDrwView.Count

For numtxt = 1 To oDrwView.Item(i).Texts.Count
Set CurrentText = oDrwView.Item(i).Texts.Item(numtxt)
If CurrentText.Name Like "*Balloon*" Then
'ws.Cells(j, 1).Value = CurrentText.text
xpos = oDrwView.Item(i).x
ypos = oDrwView.Item(i).y
Debug.Print xpos
Debug.Print ypos
j = j + 1
End If
Next numtxt
Next i
 
the D2 coordinates is something added to the drawing frame (probably generated by a script) - and also probably connected to the drawing dimension as well. So all one needs to do is connect that logic to the x,y values obtained for the balloon.

regards,
LWolf
 
Yes for drawing sheet we have grid or zone values like horizontal numbers and vertical Leterrs like shown below.
Its STD template so wanted to check if the text or balloon belongs to which Zone like "A1,B2,,," like that.

Picture7_d8flqt.png
 
The size of the zones is typically governed by the sheet size; create a look-up table for converting coordinates to zone count and then from zone count to zone ID.

Making things more fun is that some drawing standards have variable sizes for drawings and therefore a variable number of zones. Even so, the number of possible formats is finite and not very large.
 
Thank you 3DDave will try your suggestion.
can you help me if you have some sample code to extract the same like you said.

Thank you
 
Can some help me to get the position of a balloon in catia v5 drawing like H7 as shown in picture.
 
you will have to get the position of the balloon in the DrawingView, then compute the global sheet position with regards to the position of the view in the sheet.

Then check this balloon global Sheet position with divisions.

if you know the division textname, you can work with position and distances.
Other solution is to work with the sheet layout / format and work from predefined position values.

Go step by step and show your progress, we will help...


step 1 position of balloon in view
does your code above works?​
step 2 position of balloon in sheet
get position of working view in sheet and do the math to get balloon sheet position​
step 3 division position of balloon
options here... you pick one...​


Eric N.
indocti discant et ament meminisse periti
 
Hi,

Thank you for reply.
step 1 position of balloon in view
Yes below is my code i am getting postion of balloon based on view postion
Sub BOMExtract()

Dim CATIA As Object
Dim myselection As Selection
Dim textlist() As String
Dim showstate As CatVisPropertyShow
Dim dblViewScale As Double
Dim MyDimension As DrawingDimension

Set wb = ThisWorkbook
Set ws = wb.Sheets("BOM")
LR = ws.Cells(Rows.Count, 1).End(xlUp).Row
ws.Range("A6:H1000").ClearContents
Set CATIA = GetObject(, "CATIA.Application")

Dim drawingDocument1 As Document
Set drawingDocument1 = CATIA.ActiveDocument
Set oDrwView = drawingDocument1.Sheets.ActiveSheet.Views

Dim pattern As String
pattern = "\b(?:\d{1,3}-\d{1,2}|((?<!-)1\d{3}))\b"

j = 6
Dim selection1 As Selection
Set selection1 = drawingDocument1.Selection
'Selection1.Search "CATDrwSearch.DrwBalloon,all"
For i = 1 To oDrwView.Count

For numtxt = 1 To oDrwView.Item(i).Texts.Count
Set CurrentText = oDrwView.Item(i).Texts.Item(numtxt)
If CurrentText.Name Like "*Balloon*" Then
'ws.Cells(j, 1).Value = CurrentText.text
xpos = oDrwView.Item(i).x
ypos = oDrwView.Item(i).y
H = CurrentText.x
V = CurrentText.y
Debug.Print CurrentText.text & "-" & "HORIZONTAL: " & xpos
Debug.Print CurrentText.text & "-" & "VIRTICAL: " & ypos
Debug.Print CurrentText.text & "-" & "HORIZONTAL: " & H
Debug.Print CurrentText.text & "-" & "VIRTICAL: " & V

j = j + 1
End If
Next numtxt
Next i

'Call GetotherData
On Error GoTo 0
End Sub

Result is here

8914-HORIZONTAL: 935.219970703125
8914-VIRTICAL: 350.777282714844
8914-HORIZONTAL: -90.6343994140625
8914-VIRTICAL: 69.5528259277344


step 2 position of balloon in sheet
I am getting the postion bu i am not sure weather it is giving correct result its there in above code
 
so it seems
xpos = oDrwView.Item(i).x
ypos = oDrwView.Item(i).y

gives you the position of the view in the sheet
(I first got confused with oDrwView : this is the collection I would call it oDrwViews )

H = CurrentText.x
V = CurrentText.y

gives you balloon position in view coordinates.

now you do the math to get balloon position in sheet (it is easier if the view is not rotated, plz do not forget about this, also not sure about view scale impact... plz check this also)

Eric N.
indocti discant et ament meminisse periti
 

xpos = oDrwView.Item(i).x
ypos = oDrwView.Item(i).y

this will give the postion of X Y co ordinates of balloons based on view.

H = CurrentText.x
V = CurrentText.y

this i thought this will give postion of Balloon based on sheet but its not happening.

Can you help me to get the postion from the sheet
 
Set oDrwView = drawingDocument1.Sheets.ActiveSheet.Views

so oDrwView is the collection of Views in the active sheet

and oDrwView.Item(i) is the i[sup]th[/sup] view in the collection

and oDrwView.Item(i).X is the X value of the position of the i[sup]th[/sup] view in the active sheet

Eric N.
indocti discant et ament meminisse periti
 
xpos = oDrwView.Item(i).x----Position based on view
ypos = oDrwView.Item(i).y----Position based on view
H = CurrentText.x---Position based on sheet
V = CurrentText.y---Position based on sheet

VIEW A6-6BEFORE/AFTER MODIFICATION
935.219970703125
350.777282714844
8914-HORIZONTAL: 935.219970703125----Position based on view
8914-VIRTICAL: 350.777282714844----Position based on view
8914-HORIZONTAL: -90.6343994140625---Position based on sheet
8914-VIRTICAL: 69.5528259277344---Position based on sheet
8958-HORIZONTAL: 935.219970703125----Position based on view
8958-VIRTICAL: 350.777282714844----Position based on view
8958-HORIZONTAL: -106.647277832031---Position based on sheet
8958-VIRTICAL: 69.2395629882813---Position based on sheet

with i was not able to get the exact grid postion of balloon

Result should be for balloon 8914--H7
Result should be for balloon 8958--H78

for reference i have attached picture
Grid_Position_emslmn.png
 
viewposition_kimixu.png


the position is the same : it is the view position in the sheet. nothing to do with the balloon.

I might be wrong but i need some real convincing...

Eric N.
indocti discant et ament meminisse periti
 
the position you get from .X or .Y will not come back with H7 or H8. NEVER
it will come as a value in mm from the origin / reference element

you will have to compare the position (mm) of the balloon with the position (mm) of the H text and 7 text also in mm or compare with the position of the balloon in the sheet and the number of division based on the size of the sheet...

Eric N.
indocti discant et ament meminisse periti
 
Hi,

Sorry i was not able to get the same.
 
sorry

Eric N.
indocti discant et ament meminisse periti
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor