Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Making copy of mirror feature instance

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
667 Views, 9 Replies

Making copy of mirror feature instance

I have a mirror feature which mirrors FACE2 feature (as seen in picture).

 

MirrorDissociate.png

Instead of Mirror, I wish to just make a copy of FACE2, give appropriate mirror transofrm and then suppress the Mirror feature.

 

Question: when I query FeaturePatternElements I get 2. How to identify the master (FACE2) and the slave (the one created by Mirror feature).

I tried to get CreatedByFeature from faces, but does not work.

 

Below is the trial code (not fully writtent as of now):

 

            Dim patternElements As FeaturePatternElements = mirrfeat.PatternElements
            For i As Integer = 1 To patternElements.Count
                Dim pattelem As FeaturePatternElement = patternElements.Item(i)
                Dim faces As Faces = pattelem.Faces
                Dim partFeat As PartFeature = faces.Item(1).CreatedByFeature
                Dim trans As Matrix = pattelem.Transform
                Dim tmpToMove As ObjectCollection = _invApp.TransientObjects.CreateObjectCollection
                tmpToMove.Add(partFeat)

                Dim moveDef As MoveDefinition = m_compDef.Features.MoveFeatures.CreateMoveDefinition(tmpToMove)
                moveDef.Copy()
                moveDef.AddFreeDrag(trans.Translation.X, trans.Translation.Y, trans.Translation.Z)
                m_compDef.Features.MoveFeatures.Add(moveDef)
            Next

I need Copy Feature functionality. If I get it without creating MoveFeature, that would be better.

 

Can you suggest correct way to get this done?

9 REPLIES 9
Message 2 of 10
xiaodong_liang
in reply to: Anonymous

Hi,

I think it would be safe to identify by FeaturePatternElement.Transform. This is a transform that describes this occurrences relative position to the parent feature(s). In the case of Mirror, if it is an identity matrix, that should be the the element of the root feature.
Message 3 of 10
Anonymous
in reply to: xiaodong_liang

How to extract/cast PartFeature from FeaturePatternElement?

Message 4 of 10
xiaodong_liang
in reply to: Anonymous

Hi,

 

it looks you want to get the corresponding feature of a face?  Of course Face.CreateByFeatures is the right one.  In theory, I think FeaturePatternElement.Faces should represent the faces collection of an instance, no matter root features or mirroed instances, however it is strange in Mirror instances, the Faces of first instance is empty, the Faces of the second instance is 1. 

 

I will need to dig into further. I will get back to you once getting progress. at this moment, if you want to know the root features, I think you can simply use MirrorFeature.ParentFeatures.

Message 5 of 10
Anonymous
in reply to: xiaodong_liang

The suggestion of using ParentFeatures is sufficient at the moment. Thanks a lot.

Message 6 of 10
Anonymous
in reply to: Anonymous

Coming back to the original issue... I wish to instantiate mirror features.

Here is the situation. FACE2 feature has been mirrored. So mirrorfeature->ParentFeatures->Item(1) gives FACE2.

 

In my program, I have built a new feature EXTRUDE2 which is similar to FACE2 and kept it in a dictionary map. Now while looking at (Mirror of FACE2) situation, I wish to make a copy EXTRUDE2, instead of mirroring it, at the same location as that of instance of FACE2.

 

Here is the code I am trying and it is failing at MoveFeature.

 

            Dim masterFeature As PartFeature = Nothing
            Dim masterABELFeature As PartFeature = Nothing
            Dim iMatrix As Matrix = _invApp.TransientGeometry.CreateMatrix()
            iMatrix.SetToIdentity()

            Dim parentfeatures As ObjectCollection = mirrfeat.ParentFeatures()
            masterFeature = parentfeatures.Item(1) ' will extend the logic for others later, TBD
            masterABELFeature = getCorrespondingABELFeature(masterFeature) 'Gets Extrusion2
Dim tmpToMove As ObjectCollection = _invApp.TransientObjects.CreateObjectCollection() tmpToMove.Add(masterABELFeature) Dim patternElements As FeaturePatternElements = mirrfeat.PatternElements For i As Integer = 1 To patternElements.Count Dim pattelem As FeaturePatternElement = patternElements.Item(i) Dim trans As Matrix = pattelem.Transform If Not trans.IsEqualTo(iMatrix) Then ' NON MASTERS Dim moveDef As MoveDefinition = m_compDef.Features.MoveFeatures.CreateMoveDefinition(tmpToMove) ' FAILS HERE, why?? moveDef.Copy() moveDef.AddFreeDrag(trans.Translation.X, trans.Translation.Y, trans.Translation.Z) newFeature = m_compDef.Features.MoveFeatures.Add(moveDef) newFeatures.Add(newFeature) End If Next

 

Any clue? Any other way of copying feature?

Message 7 of 10
adam.nagy
in reply to: Anonymous

MoveFeature is not for moving features - it's a Feature for Moving Bodies:

 

MoveFeature.png

 

Best thing is always to test things in the UI first. There the only way seemed to be copying the the sketch and creating a face from that.

 

Why don't you want to use Copy Feature? - that would at least be associative in case anything changes. 

 

Also why are you creating an Extrude instead of using a Face Feature?

Could I ask what you are trying to achieve by copying features around? What is the benefit? 



Adam Nagy
Autodesk Platform Services
Message 8 of 10
Anonymous
in reply to: adam.nagy

As part of my research, I am creating an equivalent EXTRUDE feature for FACE feature. Also, creating an equivalent SWEEP feature for FLANGE feature.

 

When I see MIRROR of FACE in the given tree, I am supposed to make a mirror copy of the EXTRUDE I had created for the FACE feature.

 

Copy-Features should work for me, if I can transform the copy by supplying mirror instance transform. This will mimic the mirror.

 

Can you point to some sample/link to see the code snippet for copy-features?

 

Message 9 of 10
adam.nagy
in reply to: Anonymous

Sorry, I meant MirrorFeature, not copy feature.

 

So you just want to turn each face into an extrude. Why is that good?

Once you turned them into an extrude, could you still use the MirrorFeature or you want to replace that as well with something else, and if so, why?

 

If you don't want to use mirror feature, then I think you could either:

- just make a new sketch with the copy of the other sketch entities which is at the right position for the extrude.. or...

- extrude the same sketch but in the opposite direction (so that it will be flipped like as part of a mirror feature) and in a way that it will create a new body, then use MoveFeature to move that body where you want it.  



Adam Nagy
Autodesk Platform Services
Message 10 of 10
Anonymous
in reply to: adam.nagy

Thanks. I will work on your suggestions of sketch copy etc

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report