How to use MirrorFeatures.add to create Multi-body

How to use MirrorFeatures.add to create Multi-body

Anonymous
Not applicable
565 Views
2 Replies
Message 1 of 3

How to use MirrorFeatures.add to create Multi-body

Anonymous
Not applicable

Hi ,all

I need help,thanks

I have the following code,but it creates feature ,not multi-body

<code>

 

Public Sub Mirror()
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))

' Set a reference to the component definition.
Dim oCompDef As PartComponentDefinition
Set oCompDef = oPartDoc.ComponentDefinition

' Create a new sketch on the X-Y work plane.
Dim oSketch As PlanarSketch
Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(3))

' Set a reference to the transient geometry object.
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry

' Draw a rectangle
Dim oRectangleLines As SketchEntitiesEnumerator
Set oRectangleLines = oSketch.SketchLines.AddAsTwoPointRectangle( _
oTransGeom.CreatePoint2d(-1, 0), _
oTransGeom.CreatePoint2d(-4, -3))

' Create a profile.
Dim oProfile As Profile
Set oProfile = oSketch.Profiles.AddForSolid

' Create a base extrusion 1cm thick.
Dim oExtrude As ExtrudeFeature
Set oExtrude = oCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, 1, kNegativeExtentDirection, kJoinOperation)

Dim oParentFeatures As ObjectCollection
Set oParentFeatures = ThisApplication.TransientObjects.CreateObjectCollection

oParentFeatures.Add oExtrude

Dim oYZPlane As WorkPlane
Set oYZPlane = oCompDef.WorkPlanes.Item(1)

Dim oMirror As MirrorFeature
Set oMirror = oCompDef.Features.MirrorFeatures.Add(oParentFeatures, oYZPlane)
End Sub

 

<code end>

 

0 Likes
566 Views
2 Replies
Replies (2)
Message 2 of 3

YuhanZhang
Autodesk
Autodesk

Modified the code as below:

 

Public Sub Mirror()
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))

' Set a reference to the component definition.
Dim oCompDef As PartComponentDefinition
Set oCompDef = oPartDoc.ComponentDefinition

' Create a new sketch on the X-Y work plane.
Dim oSketch As PlanarSketch
Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(3))

' Set a reference to the transient geometry object.
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry

' Draw a rectangle
Dim oRectangleLines As SketchEntitiesEnumerator
Set oRectangleLines = oSketch.SketchLines.AddAsTwoPointRectangle( _
oTransGeom.CreatePoint2d(-1, 0), _
oTransGeom.CreatePoint2d(-4, -3))

' Create a profile.
Dim oProfile As Profile
Set oProfile = oSketch.Profiles.AddForSolid

' Create a base extrusion 1cm thick.
Dim oExtrude As ExtrudeFeature
Set oExtrude = oCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, 1, kNegativeExtentDirection, kJoinOperation)

Dim oParentFeatures As ObjectCollection
Set oParentFeatures = ThisApplication.TransientObjects.CreateObjectCollection

' Add the surface body as the mirror component
oParentFeatures.Add oPartDoc.ComponentDefinition.SurfaceBodies(1)

Dim oYZPlane As WorkPlane
Set oYZPlane = oCompDef.WorkPlanes.Item(1)

Dim oMirror As MirrorFeature
Set oMirror = oCompDef.Features.MirrorFeatures.Add(oParentFeatures, oYZPlane)

oMirror.NewBodyOperation = True

End Sub

 

Note: You should be able to mirror a surface body as a new body only, mirror a part feature does not support 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.

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thanks a lot . It works well.

 

0 Likes