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!

Get Shape Name in textbox

Status
Not open for further replies.

NaWin55

Mechanical
Mar 21, 2020
97
IN
Hi
i am facing this issue where i need to get the name of the hybridshape or surface which is selected
but its not working properly here is the userform and macro
HoleUI_wr0ewr.png


when i select it shows "CATIASelection7"

but it should show Fill.1 or whatever the hybridshape that is selected
here is the VBScript
Option Explicit

Dim oDoc As Document
Dim oPartDoc As PartDocument
Dim oPart As Part
Dim oBodys As Bodies
Dim oBody As Body
Dim oSel As Selection
Dim oSel2 As Object
Dim hybBodys As HybridBodies
Dim hybBody As HybridBody
Dim hybShapefact As HybridShapeFactory
Dim hybshapes As HybridShapes
Dim hybshape As HybridShape

Private Sub CancelBtn_Click()
Unload Me
End Sub

Private Sub surfaceBtn_Click()
Set oDoc = CATIA.ActiveDocument
Set oPartDoc = CATIA.ActiveDocument
Set oPart = oPartDoc.Part

Set oSel = CATIA.ActiveDocument.Selection
Set oSel2 = oSel

oSel.Clear

Dim varFilter(1) As Variant
varFilter(0) = "Face"
varFilter(1) = "Face"

Dim status As String
status = oSel2.SelectElement3(varFilter, "Select Face", False, CATMultiSelTriggWhenUserValidatesSelection, False)

If (status = "Cancel") Then
MsgBox "User Cancelled"
Else
nameBox.Text = oSel.Name
End If
End Sub
 
Replies continue below

Recommended for you

oSel is the selection element, so it's name is something with Selection. oSel.Value is the selected item.

regards,
LWolf
 
it is giving error Object doesn't support this property or method
 
osel.item(1).value
Still not working

but i tried this it is getting only FILL shape name but other hybridshapes names
here is the image
fill_umu6z4.png


if i select flat surface which is fill it is showing correct name
if i select cylinder surface then also it shows Fill.1 name
but i want it to show the surface name whichever i select

here is the macro i wrote
i think you can do it from this macro help

Option Explicit

Dim oDoc As Document
Dim oPartDoc As PartDocument
Dim oPart As Part
Dim oBodys As Bodies
Dim oBody As Body
Dim oSel As Selection
Dim oSel2 As Object
Dim hybBodys As HybridBodies
Dim hybBody As HybridBody
Dim hybShapefact As HybridShapeFactory
Dim hybshapes As HybridShapes
Dim hybshape As HybridShape

Private Sub UserForm_Initialize()
DiaList.AddItem "3"
DiaList.AddItem "6"
DiaList.AddItem "12"
DiaList.AddItem "16"
End Sub
Private Sub CancelBtn_Click()
Unload Me
End Sub

Private Sub surfaceBtn_Click()
Set oDoc = CATIA.ActiveDocument
Set oPartDoc = CATIA.ActiveDocument
Set oPart = oPartDoc.Part

Set hybShapefact = oPart.HybridShapeFactory
Set hybBodys = oPart.HybridBodies

Set oSel = CATIA.ActiveDocument.Selection
Set oSel2 = oSel

oSel.Clear

Dim varFilter(1) As Variant
varFilter(0) = "Face"
varFilter(1) = "Face"

Dim status As String
status = oSel2.SelectElement3(varFilter, "Select Face", False, CATMultiSelTriggWhenUserValidatesSelection, False)

If (status = "Cancel") Then
MsgBox "User Cancelled"
Else
Dim i As Integer
For i = 1 To oSel.Count
Set hybBody = hybBodys.Item(i)
Set hybshapes = hybBody.HybridShapes
Set hybshape = hybshapes.Item(i)
nameBox.Text = hybshape.Name
Next
End If
End Sub
 
Sub CATMain()

Set oSel = CATIA.ActiveDocument.Selection
oSel.Clear

Dim varFilter(0) As Variant
varFilter(0) = "AnyObject"

Dim status As String
status = oSel.SelectElement3(varFilter, "Select Face", False, CATMultiSelTriggWhenUserValidatesSelection, False)

If (status = "Cancel") Then
MsgBox "User Cancelled"
Else
MsgBox oSel.item(1).Value.name
End If

End Sub​

regards,
LWolf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top