Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catia Macro Find Axis and Face Coordinates

Status
Not open for further replies.

blues1143

Computer
Nov 22, 2016
14
Hello,

I am looking for a macro to find 2 coordinates of a hole axis and 2 for a face.

I want it to work by running the macro, select axis, msgbox with 2 coordinates, select face, msgbox with 2 coordinates.

Any ideas

Thanks,
 
Replies continue below

Recommended for you

Hello,

Please be more specific (provide an example) about "coordinates of an axis" and "coordinates of a face". A picture would truly worth a thousand words :)

cilici
 
Okay forget the face for now.

Basically I want to have a button to position a cap screw head into the product by selecting a hole axis and a face.

So when assembling a screw as normal you would bring it into the assembly, then snap the central axis of the screw to the central axis of the hole. Then snap the bottom face of the screw to the face you want it to sit on.

Not sure how I could give a picture. Any ideas?
 
what is your code so far and where/what is the problem?

Eric N.
indocti discant et ament meminisse periti
 
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("FIXINGS")

Dim products2 As Products
Set products2 = product2.Products

Dim arrayOfVariantOfBSTR1(0)
arrayOfVariantOfBSTR1(0) = Part Location
Set products2Variant = products2
products2Variant.AddComponentsFromFiles arrayOfVariantOfBSTR1, "All"

Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim productDocument2 As ProductDocument
Set productDocument2 = documents1.Item(Product to Assemble Into)

Dim product3 As Product
Set product3 = productDocument2.Product

Dim products3 As Products
Set products3 = product3.Products

Dim product4 As Product
Set product4 = products3.Item("M8_SOCKET_CAP_HEAD.1")

Dim move1 As Move
Set move1 = product4.Move

Set move1 = move1.MovableObject

Dim arrayOfVariantOfDouble1(11)
arrayOfVariantOfDouble1(0) = 0#
arrayOfVariantOfDouble1(1) = 0#
arrayOfVariantOfDouble1(2) = 1#
arrayOfVariantOfDouble1(3) = -0#
arrayOfVariantOfDouble1(4) = 1#
arrayOfVariantOfDouble1(5) = -0#
arrayOfVariantOfDouble1(6) = -1#
arrayOfVariantOfDouble1(7) = -0#
arrayOfVariantOfDouble1(8) = 0#
arrayOfVariantOfDouble1(9) = 3262#
arrayOfVariantOfDouble1(10) = -390#
arrayOfVariantOfDouble1(11) = 1526.983066
Set move1Variant = move1
move1Variant.Apply arrayOfVariantOfDouble1

Set move1 = product4.Move

Set move1 = move1.MovableObject

Dim arrayOfVariantOfDouble2(11)
arrayOfVariantOfDouble2(0) = 1#
arrayOfVariantOfDouble2(1) = 0#
arrayOfVariantOfDouble2(2) = 0#
arrayOfVariantOfDouble2(3) = 0#
arrayOfVariantOfDouble2(4) = 1#
arrayOfVariantOfDouble2(5) = 0#
arrayOfVariantOfDouble2(6) = 0#
arrayOfVariantOfDouble2(7) = 0#
arrayOfVariantOfDouble2(8) = 1#
arrayOfVariantOfDouble2(9) = 0#
arrayOfVariantOfDouble2(10) = 0#
arrayOfVariantOfDouble2(11) = 0.616934
Set move1Variant = move1
move1Variant.Apply arrayOfVariantOfDouble2

End Sub

Thats my code so far. Its pretty much just a recorded macro. I had to take some of the titles out (product and file location) but they are fine in my version. How can I automate this so that I click a line and a feature of the screw goes to there... Really I just need a vector of the axis or 2 points on the axis to be able to get the movement numbers seen above.

How can I do this?
 
you can ask the user to select a cylindrical face, then define a reference out of it. then ask user to select a face and create another reference.

From those 2 ref, get the matrix position for the location of the screw.

in order to get the matrix position you could build and axis based on the intersection of the face and the cylindrical axis...

check this thread560-251808, you might learn from it (like asking user to select face and many other valuable stuff)...

Will come back to you soon

Eric N.
indocti discant et ament meminisse periti
 
Had a look through this. Looks very useful.

Unfortunately it does not tell me what I want. I think I am going along the right lines now though...

If I select the top circle and the bottom circle of the hole, create a point in the centre then get the coordinates of the points and do math to work out the direction.

Any better ideas?
 
or you can select the cylindrical face (1 click) and get its axis... which solution you think the user will prefer?

you might also check if something is already selected and if it is a cylindrical face in case the user made the selection first.

But you can go with the 2 circles... it's up to you (in fact 1 circle is enough as a circle is on a plane and the circle axis is normal to the plane...

so did you find in the CPSC how to ask user to select a circle?

Eric N.
indocti discant et ament meminisse periti
 
Got it to work with the circles!

2 clicks are needed for direction so circles seems the best way to do it.

Do you know how to get the diameter/radius of a circle from selectelement2?

I got creating a point in the circle then modified it so it doesn't append.
 
check measurable object

Eric N.
indocti discant et ament meminisse periti
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor