Position products - Macro

Luiz Henrique Silva

Position products - Macro

Hello Experts, 

I have been searching for how exactly work movable object inside a product

I know that is subdivided in a matriz of 3 positions each subject and the last 3 of them is xyz coords.

Example of code:

Sub CATMain()

Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Dim products1 As Products
Set products1 = product1.Products

Dim product2 As Product
Set product2 = products1.Item("Part2.1")

Dim move1 As Move
Set move1 = product2.Move

Set move1 = move1.MovableObject

Dim arrayOfVariantOfDouble1(11)
arrayOfVariantOfDouble1(0) = 0.998602
arrayOfVariantOfDouble1(1) = -0.024799
arrayOfVariantOfDouble1(2) = -0.046671
arrayOfVariantOfDouble1(3) = -0.024799
arrayOfVariantOfDouble1(4) = 0.559952
arrayOfVariantOfDouble1(5) = -0.828154
arrayOfVariantOfDouble1(6) = 0.046671
arrayOfVariantOfDouble1(7) = 0.828154
arrayOfVariantOfDouble1(8) = 0.558554
arrayOfVariantOfDouble1(9) = -227.149108
arrayOfVariantOfDouble1(10) = -0.299527
arrayOfVariantOfDouble1(11) = -0.202018
Set move1Variant = move1
move1Variant.Apply arrayOfVariantOfDouble1

End Sub

If someone can give me a direction I would aprecciate so much 

Thank you.

Colby Maust

RE: Position products - Macro
(in response to Luiz Henrique Silva)

I'm a little unclear exactly what it is you're looking to do, but I think this can help you. My use case for the following code is when I paste a part into an assembly, and it pastes it way out at the absolute axis, which may be outside my current view. Instead of zooming out and trying to find the part to put constraints on it, I use this macro to move it closer to where I want it. When you run it, it will ask you to select your component to move. I suggest you select it from the tree, not by clicking on the model, less chance for error that way. Then it asks you to click where you want to move it to. Whatever point, line, face etc. that you click on next is where your component will move to, with the absolute axis of your component being at that location. Give it a try and see if it does what you want.

Sub CATMain()

Dim Product
Dim InputObjectType(0), Status
Set Selection = CATIA.ActiveDocument.Selection
Selection.Clear
InputObjectType(0) = "Product"
Status = Selection.SelectElement2(InputObjectType, "Select a Component", False)
If Status = "Normal" Then
Set MainProd = CATIA.ActiveDocument.Product
Set Products = MainProd.Products
Set Prdct = Selection.Item(1)
cnt = Products.Count
For i = 1 To cnt
If Products.Item(i).Name = Prdct.Value.Name Then
Set Product = Products.Item(i)
Exit For
End If
If Products.Item(i).Name = Prdct.Value.Parent.Parent.Name Then
Set Product = Products.Item(i)
Exit For
End If
Next
Else: Exit Sub
End If
Dim pos(11)
Product.Position.GetComponents pos

Dim point
Dim WindowLocation3D(2)
Dim InputObjectType2(6)
InputObjectType2(0) = "Point"
InputObjectType2(1) = "BiDim"
InputObjectType2(2) = "MonoDim"
InputObjectType2(3) = "Vertex"
InputObjectType2(4) = "Line"
InputObjectType2(5) = "Edge"
InputObjectType2(6) = "Point"
Status = Selection.SelectElement2(InputObjectType2, "Select a location to move component to", False)
If Status = "Normal" Then

Set point = Selection.Item(1)
point.GetCoordinates WindowLocation3D
Else: Exit Sub
End If


pos(9) = WindowLocation3D(0)
pos(10) = WindowLocation3D(1)
pos(11) = WindowLocation3D(2)
Product.Position.SetComponents pos
Selection.Clear
End Sub

Edited By:
Colby Maust[Subscriber Members] @ Aug 31, 2022 - 12:36 PM (America/Eastern)
Colby Maust[Subscriber Members] @ Aug 31, 2022 - 12:37 PM (America/Eastern)

Iouri Apanovitch

RE: Position products - Macro
(in response to Luiz Henrique Silva)

Product.Move.Apply moves the component from its current position.

Product.Position.SetComponents sets the absolute coordinates of the component

Both require transformation matrix, e.g. T, pretty standard linear coordinate transformation, the key is to get this matrix right:

T(0)...T(2) - the "new" X-axis vector, expressed in the "old" XYZ coordinates

T(3)...T(5) - the "new" Y-axis vector, expressed in the "old" XYZ coordinates

T(6)...T(8) - the "new" Z-axis vector, expressed in the "old" XYZ coordinates

T(9)...T(11) - the "new" origin, expressed in the "old" XYZ coordinates

There's a lot of info on linear coordinate transformation on the web, cause it's used a lot. It is what your graphics card is doing when smth moves on you computer screen.

Hope that helps

 

 

Matt Hanson

RE: Position products - Macro
(in response to Colby Maust)

It's hard to know what exactly you want to do without a full explanation.  But first, let's make sure that you understand the position matrix of occurrences.

 

Dim TransformationArray(11)

TransformationArray(0) = 1    |
TransformationArray(1) = 0    |<--- I vector
TransformationArray(2) = 0    |

TransformationArray(3) = 0    |
TransformationArray(4) = 1    |<--- J vector
TransformationArray(5) = 0    |

TransformationArray(6) = 0    |
TransformationArray(7) = 0    |<--- K vector
TransformationArray(8) = 1    |

TransformationArray(9) = 0.000 (x coord)
TransformationArray(10) = 0.000 (y coord)
TransformationArray(11) = 0.000 (z coord)

 

You can return the current values into this array, and from this point, either use them to perform mathematical operations to transform/translate, or you can just set arbitrary values.

Matt Hanson

RE: Position products - Macro
(in response to Matt Hanson)

The big question is, do you want to manipulate a position based on geometry, or do you want to do math?

Michael Laursen

RE: Position products - Macro
(in response to Luiz Henrique Silva)

What would be the purpose of moving a component in a product...? Do you create products/assemblies without constraints..?

I use constraint and for most constraints I use the AxisSystem to AxisSystem with a coincidence constraint and a macro to constrain them automatically. I did a presentation on this at COE Experience 2022.

Luiz Henrique Silva

RE: Position products - Macro
(in response to Michael Laursen)

Hello Michael, Some companies doesnt allow to use constraint in their Assemblies, as hard that it may sounds. =)

somehow I get used to it. (Only moving items with snap, it is their rule)

The company that I actually working for, they use a method that I particulary think is harder than usual. 

they create an axis on each session of aircraft instead of using the absolute, we need create the part in absolute axis, then move it to another position, then put this additional axis. 

Edited By:
Luiz Henrique Silva[Subscriber Members] @ Nov 17, 2022 - 02:14 PM (America/Sao_Paulo)
Luiz Henrique Silva[Subscriber Members] @ Nov 17, 2022 - 02:14 PM (America/Sao_Paulo)

Michael Laursen

RE: Position products - Macro
(in response to Luiz Henrique Silva)

Well... i don't know how rigid the organization are. and it can be difficult to make changes. But if the rule are not to have constraints... then why not just delete them when the product are fully constrained/positioned. The constraints can be deleted with a vb-script quite fast. Components can be constrained with an AxisSystem to AxisSystem. 

How do you control direction of the components if only using snap..? Will it always snap the same way no matter where it's positioned in the assembly.. ? 

How do you store the information of what to snap and to which component. ? Filebased..? are the complete assembly "Constrained" automatically based on snap or just a few local components when instantiating...? There are so many questions, and a simple task seems to be a lot more complex. 

Let me know if you want to share notes and discus the different methods 

Marc A Jeeves

RE: Position products - Macro
(in response to Michael Laursen)

Morning,

As with everything, not really understanding something leads to its removal within an environment.  This is a story I have heard many times and what i have learned over the years may help.

 

The root of the issue is the modelling kernel and its inability to cleanly reroute BRep, solid works tends to be better than CATIA at this.   CATIA has the ability to semi-automatically map the BRep based on distance between the old and new geometry's , but its not perfect.

 

Secondarily the users are not using the Replace function when editing geometry, this will remap the  BRep IDs and allow the changes to somewhat transparent.

 

Thirdly When Engineering Connections (Constraints) are created we must always create them to published wireframe geometry not the BRep of the model, because we cant guarantee that the Kernel or the Designer will reroute the BRep.

 

Ultimately the Engineering Connections fail due to the BRep ID's changing.

 

The best solution is to not use any geometry from the models' themselves, but to construct a Skelton that defines the motion and link this geometry to each of the designed parts and republish it.  We can then use this geometry to create the engineering connections and kinematics if required.  Further more if i change the skeleton then the parts will update, the engineering connections will resolve and the if there is kinematic motion this will also update.

This structure provides support for motion, in this model the MSTR Skeleton lays out the motion wireframe / interfaces.  We then publish these and link them down to each sub assembly's Slave skeleton  where they are need and republished.  The engineering connections are then created between the publications of the slave skeletons.  Finally the motion created.

 

Note we have not yet created any designed parts, so we have two choices we can insert into the sub assemblies STD Components, or FST's.  When the motion is run these will now move because were moving the assembly that they are within.  Or we can use design in context, by inserting a new part below one of the sub assemblies and linking the wireframe geometry from the slave skeleton to the newly inserted part and then design based on these external references.

You could flatten the structure if you don't have motion.

 

Hope this makes sense, if you have any questions let me know.

 

See attached Video

 

Thanks Madaxe

 

Product

    Mstr Skeleton

        Publications

    Static Components Product

        Slave Skeleton 1

            Publications

        Part1

        Part2

        ....

    Moving Components Group 1 Product

        Slave Skeleton 2

            Publications

        Part3

        Part4

        ....

    Moving Components Group 2 Product

        Slave Skeleton 3

            Publications

        Part5

        Part6

        ....

 

 

 

 

 

 

Attachments

  • Engineering Connection For Motion.zip (46110.4k)
Edited By:
Marc A Jeeves[Gulfstream Aerospace Corporation] @ Nov 18, 2022 - 08:22 AM (America/Central)
Marc A Jeeves[Gulfstream Aerospace Corporation] @ Nov 18, 2022 - 09:51 AM (America/Central)

Michael Laursen

RE: Position products - Macro
(in response to Marc A Jeeves)

Hi Marc, 

But not having the components independent makes it a lot more complex. Especially when reusing components across products. 

Second.. how do you manage gaps/overlap where components interface/connects to each other.. ? 

Right now we are working on publishing an axisSystem for all connections/interfaces between two components and through the publication, we get the actual object and by that the BRep og all the axis's, plane's and the origin of the AxisSystem that the Publication points to. This means we can do any constraint we want. By this we also have a visual check of our tolerances.

The constraints are defined in a designtable for each Architectual variant. Then we simply automatically constrain the product based on this information.
All the product variants are defined in a second designtable. With this we are able to configure 1000+ product variants :-) 

Marc A Jeeves

RE: Position products - Macro
(in response to Michael Laursen)

Morning, Standard Components, fst, or carry over, there are two ways;

1. Ensure that every standard component has published wireframe interfaces where the publication names are identical across component family's allowing replacement. For Fasteners we normally have a single axis system that has a standard name, so i can replace a nut for a washer or a bolt for a nut etc..  For Standard Components we create wireframe geometry for the interfaces and across family's i.e. p-clamps, pumps, or battery's.  The publication names are kept generic and identical, again allowing one to be replaced for another.

2. Carry over components fall into this category or parts that don't have published interfaces.  We put these into a product in the correct location along with a skeleton part that defines the interface geometry.

 

The rlm should always define the common interfaces and link down tot he mulitple parts.

 

hope that helps

 

madaxe

Michael Laursen

RE: Position products - Macro
(in response to Marc A Jeeves)

Hi madaxe :-) 

Have you made a presentation of this topic at some point here on COE..? 

/Michael

Marc A Jeeves

RE: Position products - Macro
(in response to Michael Laursen)

Morning,

No we have been working on the process recently, ready for the next program, we have sprinkled it into the existing programs and its working well.  If your going to COE in April we can sit down and go through it if you want, if not we can setup a virtual meeting.  What industry are you in?

 

thanks

Marc Jeeves

Edited By:
Marc A Jeeves[Gulfstream Aerospace Corporation] @ Nov 22, 2022 - 08:30 AM (America/Central)

Michael Laursen

RE: Position products - Macro
(in response to Marc A Jeeves)

Hi Marc, 

Sorry, but i'm not lucky enough to go every year. It cost me like $7-8000 to visit COE.. :-( So... it would be nice to have a virtual meeting. Currently i'm working in the Pump Industri. We have met a few times before at COE.. :-) 

/Michael