BasicEngineer
New member
- Aug 30, 2024
- 1
Hello Everyone,
I am working on a project at work aimed at automating the CAD process for shaft design. We have already seen significant success with the 3D design aspect. However, we are encountering some challenges with the drafting portion. The drawings consist of four views:
[ul]
[li]Side view where you can see shaft lengthwise[/li]
[/ul]
[ul]
[li]Section view where you can see shaft lengthwise[/li]
[/ul]
[ul]
[li]Detailed view of the left side of the shaft[/li]
[/ul]
[ul]
[li]Detailed view of the right side of the shaft[/li]
[/ul]
The length of the shafts varies, and if the shaft is too long, a broken view is applied to the first two views. This makes positioning the detailed view window challenging. What I have been trying to do is select the side view and list all the generated items found in this view along with their corresponding locations. By using the points farthest to the left and right on the X-axis, I can position these detailed view windows. Unfortunately, my code is unable to access the locations of these generated items. By 'generated items,' I mean all the lines and points that make up the drawing view.
Can someone please take a look at my code and give me advice on how I could make this work?
Many thanks
I am working on a project at work aimed at automating the CAD process for shaft design. We have already seen significant success with the 3D design aspect. However, we are encountering some challenges with the drafting portion. The drawings consist of four views:
[ul]
[li]Side view where you can see shaft lengthwise[/li]
[/ul]
[ul]
[li]Section view where you can see shaft lengthwise[/li]
[/ul]
[ul]
[li]Detailed view of the left side of the shaft[/li]
[/ul]
[ul]
[li]Detailed view of the right side of the shaft[/li]
[/ul]
The length of the shafts varies, and if the shaft is too long, a broken view is applied to the first two views. This makes positioning the detailed view window challenging. What I have been trying to do is select the side view and list all the generated items found in this view along with their corresponding locations. By using the points farthest to the left and right on the X-axis, I can position these detailed view windows. Unfortunately, my code is unable to access the locations of these generated items. By 'generated items,' I mean all the lines and points that make up the drawing view.
Can someone please take a look at my code and give me advice on how I could make this work?
Code:
Sub CATMain()
Dim drawingDocument1 As drawingDocument
Set drawingDocument1 = CATIA.ActiveDocument
Dim selection1 As selection
Set selection1 = drawingDocument1.selection
Dim Sheet As DrawingSheet
Set Sheet = drawingDocument1.Sheets.ActiveSheet
Dim View As DrawingView
Set View = Sheet.Views.ActiveView
Dim Selec_2 As selection
Set Selec_2 = drawingDocument1.selection
Selec_2.Add View
' Perform the search for generated items
selection1.Search "CATDrwSearch.CATEarlyGenItem,sel"
' List all found items with their locations in the Immediate Window
Dim i As Integer
For i = 1 To selection1.Count
' Get the current element
Dim element As Object
Set element = selection1.Item(i).Value
' Print item type and index to Immediate Window
Debug.Print "Item " & i & ": " & TypeName(element)
' Try to get the element's location if available
On Error Resume Next
Select Case TypeName(element)
Case "Line2D"
Debug.Print "Start Point X: " & element.StartPoint.x & ", Start Point Y: " & element.StartPoint.Y
Debug.Print "End Point X: " & element.EndPoint.x & ", End Point Y: " & element.EndPoint.Y
Case "Circle2D"
Debug.Print "Center X: " & element.Center.x & ", Center Y: " & element.Center.Y
Debug.Print "Radius: " & element.Radius
Case "Text2D"
Debug.Print "Anchor Point X: " & element.AnchorPoint.x & ", Anchor Point Y: " & element.AnchorPoint.Y
Debug.Print "Text: " & element.Text
Case Else
' Attempt to access generic X, Y if available
If HasProperty(element, "X") And HasProperty(element, "Y") Then
Debug.Print "Location X: " & element.x & ", Location Y: " & element.Y
Else
Debug.Print "Location data not available for this type."
End If
End Select
On Error GoTo 0
Next i
End Sub
' Helper function to check if an element has a property
Function HasProperty(obj As Object, propName As String) As Boolean
On Error Resume Next
HasProperty = Not IsNull(CallByName(obj, propName, VbGet))
On Error GoTo 0
End Function
Many thanks