Show sketch of body by picking

Show sketch of body by picking

tim11_manhhieu
Advocate Advocate
250 Views
2 Replies
Message 1 of 3

Show sketch of body by picking

tim11_manhhieu
Advocate
Advocate

Hi all,

I'm trying to write a macro to show sketch of a body using picking, but I'm stucking at getting sketch of oFeature.

I want to show Sketch 2 of Extrusion2 of body P37.
My code will probably be long, if you have shorter code please share.

Thanks in advance.

tim11_manhhieu_0-1735179990506.png

 

 

Option Explicit

Sub ShowSketchBody()

Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oObj As Object
Set oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Pick a body:")

Dim oBody1 As SurfaceBody
Set oBody1 = oObj

Dim oBodies As SurfaceBodies
Set oBodies = oDoc.ComponentDefinition.SurfaceBodies

Dim oBody2 As SurfaceBody
Dim oFeature As PartFeature

For Each oBody2 In oBodies

    If oBody2.name = oBody1.name Then
    
        For Each oFeature In oBody1.AffectedByFeatures
        
            If oFeature.HealthStatus = kUpToDateHealth Then
            
'                //I'm stucking here, dont know how to get sketch of oFeature//
            
            End If
                
        Next
    
    End If

Next

End Sub

 

 

 

 

 

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

Michael.Navara
Advisor
Advisor
Accepted solution

Hi @tim11_manhhieu 

This is iLogic code instead of VBA, because it can be shorter, but if you need VBA, it can be reworked.

This code make visible all extrude sketches. If you want, you can break the For-Each loop after first iteration.

 

 

Dim pick = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Pick body")
Dim body1 As SurfaceBody = pick

For Each extrudeFea As ExtrudeFeature In body1.AffectedByFeatures.OfType(Of ExtrudeFeature)
	Dim sk As PlanarSketch = extrudeFea.Profile.Parent
	sk.Visible = True
	'Exit For 'For the first sketch only
Next

 

 

0 Likes
Message 3 of 3

tim11_manhhieu
Advocate
Advocate

thanks for your respond, it is amazing. VBA code for Extrude Feature and Hole Feature below.

 

Option Explicit

Sub ShowSketchBody()

    Dim oDoc As PartDocument
    Dim oObj As Object
    Dim body As SurfaceBody
    Dim partFea As PartFeature
    Dim sk As PlanarSketch
    
    Set oDoc = ThisApplication.ActiveDocument
    Set oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Pick body: ")
    
    If TypeOf oObj Is SurfaceBody Then
    
        Set body = oObj
        
        For Each partFea In body.AffectedByFeatures
        
            If TypeOf partFea Is ExtrudeFeature Then
                Set sk = partFea.Profile.Parent
                sk.Visible = True
            End If
            
            If TypeOf partFea Is HoleFeature Then
                Set sk = partFea.sketch
                sk.Visible = True                
            End If
            
        Next partFea

    End If

End Sub

 

0 Likes