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!

Catia Macro: SelectElement2 Return wrong Item Type

Status
Not open for further replies.

jagandeep

Automotive
May 27, 2013
82
IN
My Code is Below

Sub CATMain()

Dim MySelection 'As Selection
Dim MyDoc As Document
Dim MyPart As PartDocument
Dim MyDrawing As DrawingDocument
Dim MyProduct As ProductDocument

Set MyDrawing = CATIA.ActiveDocument
Set MySelection = MyDrawing.Selection

ReDim strArray(0)
strArray(0) = "DrawingView"
Dim Status As String

Status = MySelection.SelectElement2(strArray, "Select Drawing View", True)

If Status = "Cancel" Then
Exit Sub
End If

MsgBox MySelection.Item(1).Type

End Sub

I get Return Type as "DrawingView" even if i select Line2D object as shown in attached drawing sheet. But if I try this code without SelectElement2 (Selection Item Collection) I get return type as "Line2D"

Is it a Bug or a Feature ? Please suggest any workaround
 
Replies continue below

Recommended for you

@jagandeep
When I change the FilterType of the array to allow "Line2D" then it works on my end. See here.

Code:
Sub CATMain()

Dim MySelection 'As Selection
Dim MyDoc As Document
Dim MyPart As PartDocument
Dim MyDrawing As DrawingDocument
Dim MyProduct As ProductDocument

Set MyDrawing = CATIA.ActiveDocument
Set MySelection = MyDrawing.Selection

ReDim strArray(1)
strArray(0) = "Line2D"
strArray(1) = "DrawingView"
Dim Status As String

Status = MySelection.SelectElement2(strArray, "Select Drawing View", True)

If Status = "Cancel" Then
Exit Sub
End If

MsgBox MySelection.Item(1).Type

End Sub

Regards,
Drew Mumaw
 
Hi,
filter type is to filter the elements you want to select only.
If you are giving DrawingView as filtertype then you can select drawing view only from the selection.
Though you are selecting line2d, but it is giving back the view where this line resides because of filtertype.

Use filter type "AnyObject" to select any entity, you will get what you want.

Use TypeName(itemselected) for better handling of entities.


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
 
@drewmumaw for that I have to Include each and every possible type as filter. Thats a pain :d

@Maddy If I select "AnyObject" as filter type then I get Return Type as any object. May be UseTypeName(itemselected) will solve this problem. Care to explain it how ??
 
Actually I want to select element and get its parent 3D model. If user select wrong element, the macro returns error. Although I have done this through On Error statement but there might be some built in catia way to find wrong selection!
 
Use

MsgBox TypeName(oSelection.Item(1).Value)


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,

@jagandeep
When you are starting a thread do mention the purpose of what you are trying to do.
In your first post it doesn't mention anything about it.

And sorry for not having gone through with the post before my comment above
Actually I want to select element and get its parent 3D model.

Unfortunately the method to get 3D Model from the geometric elements of any kind which represents the 3D model on paper, doesn't exist as Dassault has not given any exposure of this kind (up to my knowledge)

To get a parent 3d model of a generated drawing view use
Set objLinked3DModel = MyView.GenerativeBehavior.Document
and objLinked3DModel.Parent if required to open the 3D model

If user select wrong element, the macro returns error
What do you mean by this? elaborate on this, if possible post a video of what you are doing.


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
 
Buddy I think you it wrong, my bad
All I want is user select a drawing view and to switch to its parent 3d model. But in case user select anything other than drawing view, he gets an error message.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top