Component Mirror behaves differently from the UI

Programming and macros
User avatar
mp3-250
Posts: 630
Joined: Tue Sep 28, 2021 4:09 am
Answers: 20
Location: Japan
x 702
x 347

Component Mirror behaves differently from the UI

Unread post by mp3-250 »

From the UI if I select some components and make a position mirror of them, SW seems smart enough to automatically
switch each component alignment to get what I want.
1.jpg
Each component is aligned in this way automatically by SW like this without user interaction.
2.jpg
2.jpg (6.86 KiB) Viewed 1206 times
According to:
https://help.solidworks.com/2024/Englis ... eData.html
To create a basic Mirror Component feature, use at a minimum:

・IMirrorComponentFeatureData::MirrorPlane
・IMirrorComponentFeatureData::ComponentsToInstanceAlignToComponentOrigin

・(Optional) IMirrorComponentFeatureData::MirrorType (if not explicitly set, defaults to swMirrorComponentMirrorType_e.swMirrorType_CenterOfBoundingBox)
・(Optional) IMirrorComponentFeatureData::ComponentOrientationsAlignToComponentOrigin (if not explicitly set, defaults to swMirrorComponentOrientation2_e.swOrientation_MirroredX_MirroredY)

To create a mirror instance as a copy of the component, positioned symmetrically about a plane in one of four orientations (for fully symmetric components, all four orientations are true mirrors), use:

・MirrorPlane
・MirrorType
・ComponentOrientationsAlignToComponentOrigin
・ComponentOrientationsAlignToSelection
・ComponentsToInstanceAlignToComponentOrigin
・ComponentsToInstanceAlignToSelection
・AlignmentReferences
・FlipDirections
・SyncFlexibleSubAssemblies
I tried to use the minimum conditions and the alignment of every component defaults to the same value, as per documentation. So the mirror came out in a different way.

Code: Select all

   
    swMirroCompFeatData.mirrorPlane = mirrorPlane  
    swMirroCompFeatData.ComponentsToInstanceAlignToComponentOrigin = compsToInstance
    swMirroCompFeatData.MirrorType = swMirrorType_CenterOfBoundingBox
   
    ' Specify align to origins component orientations (I tried to skip this)
    'swMirroCompFeatData.ComponentOrientationsAlignToComponentOrigin = swOrientation_MirroredX_MirroredAndFlippedY
    
        ' Create MirrorComponent
    Set swFeat = swFeatMgr.CreateFeature(swMirroCompFeatData)
    
3.jpg
4.jpg
4.jpg (7 KiB) Viewed 1206 times
How can I make the macro give the same result of the UI?
by mp3-250 » Mon Sep 25, 2023 3:38 am
My components share the same assy CSYS, no right or left hand components only positional mirror of component that are symmetric.

I decided to build a loop to switch orientation for each component inside the mirror based on its x, y, z bounding box dimensions comparison. X>Y, Z>Y and X>Z comparison drive the component orientation and this gives me the same results as the UI mirror, at least as close as possible to my user intent.
Go to full post
User avatar
mp3-250
Posts: 630
Joined: Tue Sep 28, 2021 4:09 am
Answers: 20
Location: Japan
x 702
x 347

Re: Component Mirror behaves differently from the UI

Unread post by mp3-250 »

my educated guess is that the UI command calculate the bounding box of every component selected for mirror and comparing their length along x,y,z is able to figure out the approximate orientation and suggest it to the user accordingly.
User avatar
AlexLachance
Posts: 2184
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2364
x 2013

Re: Component Mirror behaves differently from the UI

Unread post by AlexLachance »

It has to do with the mirror feature settings but I can't really help you in terms of programming.
User avatar
josh
Posts: 295
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 16
x 22
x 508

Re: Component Mirror behaves differently from the UI

Unread post by josh »

Yes, there’s a bunch of commands where the UI takes a look at your model and tries to guess what options you’re going to want to use, but there’s nothing in the API to invoke those calculations. One other example is the Mate command, where it analyzes your selections and tells you which mates are appropriate/allowed for those selections. When adding mates via API, you have to already know what type of mate you want and add it specifically.
mario malic
Posts: 9
Joined: Thu Apr 13, 2023 4:19 am
Answers: 1
Location: Croatia
x 8
x 2

Re: Component Mirror behaves differently from the UI

Unread post by mario malic »

I think it should be something related to this member ComponentOrientationsAlignToComponentOrigin.
If you mirror every single component in the same way with the default option swOrientation_MirroredX_MirroredY. Components have their own coordinate systems and I believe this is the issue when you are having the default option. I think you should get a CS of one component and compare every other component with it to determine the proper option for ComponentOrientationsAlignToComponentOrigin.

In the mirror components menu if you press arrow 'Next' to go to the second step, you can see options for orientation of each component.
Looking for opportunities related to SolidWorks API usage.
User avatar
mp3-250
Posts: 630
Joined: Tue Sep 28, 2021 4:09 am
Answers: 20
Location: Japan
x 702
x 347

Re: Component Mirror behaves differently from the UI

Unread post by mp3-250 »

My components share the same assy CSYS, no right or left hand components only positional mirror of component that are symmetric.

I decided to build a loop to switch orientation for each component inside the mirror based on its x, y, z bounding box dimensions comparison. X>Y, Z>Y and X>Z comparison drive the component orientation and this gives me the same results as the UI mirror, at least as close as possible to my user intent.
Post Reply