Get solid body name from selected face in assembly or part document

Get solid body name from selected face in assembly or part document

william
Advocate Advocate
1,204 Views
2 Replies
Message 1 of 3

Get solid body name from selected face in assembly or part document

william
Advocate
Advocate

Hello All
I am looking to select a face in either an assembly or part environment, and extract the solid body name from the selected face. 

The difficulty I have run into is, in an assembly the selected face is a kFaceProxyObject and in a part it is a kFaceObject. 

Is there an easy way to access the solid/surface body it belongs to and report the name? 
Any tips? 

 

Links to related threads below

Inventor 2019 Help | Proxies | Autodesk

Solved: iLogic - obtain solid body name using selected feature - Autodesk Community - Inventor

 

Where I have got to so far with the code, 

ThisApplication.StatusBarText = "Select a Face"
Dim doc = ThisApplication.ActiveDocument
Dim entity = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a Face")

doc.SelectSet.Select(entity)


Dim oSelectSet As SelectSet = doc.SelectSet


Dim Types As ObjectTypeEnum() = [Enum].GetValues(GetType(ObjectTypeEnum))

For Each obj As Object In oSelectSet
    
    For Each Type As ObjectTypeEnum In Types
        If obj.Type = Type Then
            MsgBox(Type.ToString)
        End If 
    Next
    
Next

 

0 Likes
Accepted solutions (1)
1,205 Views
2 Replies
Replies (2)
Message 2 of 3

william
Advocate
Advocate
Accepted solution

ok never mind, it was easier than I thought. 

 

ThisApplication.StatusBarText = "Select a Face"
Dim doc = ThisApplication.ActiveDocument
Dim entity = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a Face")

doc.SelectSet.Select(entity)

Dim oFace As Face
oFace = doc.SelectSet(1)
	If Not oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
		MessageBox.Show("A planar face must be selected, the rule will exit", "Error Handling")
		Return
	End If

strTest = oFace.SurfaceBody.Name

MessageBox.Show("Name = " & strTest, "Title")

 

0 Likes
Message 3 of 3

william
Advocate
Advocate

Full code below. Export face as DXF

 

'CREDITS: 
'Code By @ClintBrown3D
'Originally posted at https://clintbrown.co.uk/dxf-export
'Mouse input code based on this forum post: https://forums.autodesk.com/t5/inventor-customization/ilogic-to-handle-mouse-event-for-part-selection/td-p/3902918
'Additonal DXF info via 'https://forums.autodesk.com/t5/inventor-customization/export-face-as-dxf-from-api/td-p/1965512

Start :

Error0 = 1
On Error GoTo error1
ThisApplication.StatusBarText = "Select a Face to Export as DXF"
Dim doc = ThisApplication.ActiveDocument
Dim entity = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a Face to Export as DXF")

doc.SelectSet.Select(entity)

Dim oFace As Face
oFace = doc.SelectSet(1)
	If Not oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
		MessageBox.Show("A planar face must be selected, the rule will exit", "Error Handling")
		Return
	End If

strSBName = oFace.SurfaceBody.Name
strSBNameArray = strSBName.Split("_")
strSBNameArrayCount = UBound(strSBNameArray)
strDefaultFileName = strSBNameArray(strSBNameArrayCount) 'gets the last element in the array 

SetTheFilePathHere = ThisDoc.Path
SetTheFilenameHere = InputBox("Enter the file name", "Face to DXF Export",strDefaultFileName)

ThisApplication.CommandManager.PostPrivateEvent(kFileNameEvent, SetTheFilePathHere &"\" & SetTheFilenameHere & ".dxf")

ThisApplication.StatusBarText = "Exporting your DXF, please hold"
Dim oCtrlDef As ButtonDefinition
oCtrlDef = 
ThisApplication.CommandManager.ControlDefinitions.Item("GeomToDXFCommand")
oCtrlDef.Execute
Error0 = 0
MessageBox.Show("Success! - DXF exported", "Face to DXF Export")
ThisApplication.StatusBarText = "Success! - DXF exported"
InventorVb.DocumentUpdate(False)

Q = MessageBox.Show("Select another face?", "Face to DXF Export",MessageBoxButtons.YesNo)
If Q = vbYes Then 
	GoTo Start
End If

error1 :
If Error0 = 1 Then
MessageBox.Show("iLogic Rule Cancelled", "Face to DXF Export")
End If
0 Likes