I would like to mirror the part with a VBA or iLogic program. Otherwiese I have to rebuild each part manually from the beginning. The part should be equal to the origin - but not derived.
Hi,
I'm not sure how easy it would be to do it in a way that keeps the part in tact and all features where they should be.
E.g. if you move things around in a sketch the feautures based on the solid extruded from it might not find the edges they were originally on, etc.
I guess how easy it would be to achieve what you want depends on how complicated the part documents are.
Cheers,
Hi Georg,
You can use API(MirrorFeatures.Add) to mirror all the part features and work features in a part, but not sketches. I don't understand why you need to mirror the whole part, can you explain more about your requirement?
Hello Rocky,
its much easier to edit the part in the wright direction.
Georg
Hi Georg,
I want to know is not the current MirrorFeatures.Add sufficient for now? Can you explain in detail about why you want to mirror sketches also? It would be better you can provide an example.
Hello Rocky,
we have very complex components . It is much easier to edit them in the correct position and orientation. Therefor I need the function to mirror the sketch.
Georg
If you do like to mirror a sketch, maybe you can try a workaround as below:
1. Mirror a WorkPlane for a source sketch you want to mirror it. If the source sketch you want to mirror is based on a planar face then you can create a WorkPlane on the face first.
2. Create a sketch on the mirrored WorkPlane. You may need to change the sketch properties to make it looks like a mirrored sketch of the source sketch.
3. Use PlanarSketch.CopyContentsTo to copy the sketch entities from source sketch to the target sketch.
This will make the taget sketch looks like the mirrored sketch, but the problem is the target sketch could not automatically update when the source sketch has any change. Hope this helps.
Do you have an example for this? Thank you very much.
I could copy the sketch
Sub VBAMain()
Dim oPart1 As PartDocument
Set oPart1 = ThisApplication.Documents.Open("c:\part1.ipt", False)
Dim oSketch_inPart1 As Sketch
Set oSketch_inPart1 = oPart1.ComponentDefinition.Sketches(1)
Dim oPart2 As PartDocument
Set oPart2 = ThisApplication.Documents.Open("c:\part2.ipt", False)
Dim oSketch_inPart2 As Sketch
Set oSketch_inPart2 = oPart2.ComponentDefinition.Sketches(1)
Call oSketch_inPart1.CopyContentsTo(oSketch_inPart2)
Call oPart1.Close(True)
oPart2.Update
oPart2.Save
Call oPart2.Close(True)
End Sub
I think you want to mirror a sketch in the same part document, if the source planar sketch(say Sketch1) is based on a work plane(say WorkPlane1) then you can create a mirrored work plane(say WorkPlane2) and then create a planar sketch(say Sketch2) on the mirrored work plane(WorkPlane2), and then you may use the AddByProjectingEntity (I suggested to use CopyContentsTo, but use AddByProjectingEntity may be better) to project the sketch entities in the source sketch Sketch1 to the target sketch Sketch2. If the source planar sketch is based on a planar Face, then you can firstly create a work plane based on the Face then follow similar steps to create the target sketch and project sketch entities from the source sketch to target sketch.
It is better you can provide a data if you still not sure how to do with it.
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.
Can't find what you're looking for? Ask the community or share your knowledge.