Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
YuhanZhang
in reply to: GeorgK

I created a simple VBA sample to "mirror" 2D sketch, it can work for simple 2D sketch, you can start with it to add more code to make it work better, to run it you should first open a part document and select a planar object which can be used as the mirror tool:

 

Sub MirroSketchInPartSimpleSample()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oMirrorPlaneEntity As Object
    Set oMirrorPlaneEntity = oDoc.SelectSet(1)
    
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oDoc.ComponentDefinition
    
    Dim oSk As PlanarSketch, oMirrorSk As PlanarSketch
    Dim oCol As ObjectCollection
    Set oCol = ThisApplication.TransientObjects.CreateObjectCollection
    
    For Each oSk In oCompDef.Sketches
        If oSk.PlanarEntity.Type = kWorkPlaneObject Then
            Dim oMirrorFeature As MirrorFeature, oMirrorWP As WorkPlane
            oCol.Clear
            oCol.Add oSk.PlanarEntity
            Set oMirrorFeature = oCompDef.Features.MirrorFeatures.Add(oCol, oMirrorPlaneEntity)
            Set oMirrorWP = oCompDef.WorkPlanes(oCompDef.WorkPlanes.Count)
            
            Set oMirrorSk = oCompDef.Sketches.Add(oMirrorWP)
            
            oSk.CopyContentsTo oMirrorSk
        ElseIf oSk.PlanarEntity.Type = kFaceObject Then
            Dim oWPForSourceSk As WorkPlane
            Set oWPForSourceSk = oCompDef.WorkPlanes.AddByPlaneAndOffset(oSk.PlanarEntity, 0, True)
            
            oCol.Clear
            oCol.Add oWPForSourceSk
            Set oMirrorFeature = oCompDef.Features.MirrorFeatures.Add(oCol, oMirrorPlaneEntity)
            Set oMirrorWP = oCompDef.WorkPlanes(oCompDef.WorkPlanes.Count)
            
            Set oMirrorSk = oCompDef.Sketches.Add(oMirrorWP)
            oSk.CopyContentsTo oMirrorSk
        End If
    Next
End Sub

 

 

Please let me if you have more questions on this. 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.