Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Renaming and Line creation

Status
Not open for further replies.

Alan Lowbands

Aerospace
May 17, 2017
274
Hi Guys,
I'm trying to create a script to put a point in the centre of a hole then create a line from that relative to a planer face.
I have found some code that creates the first point and I've managed to alter it a little to send the point to a chosen geo set and also rename it.
I can't figure out how to get the rename to add a instance number like catia does when creating the points ie Point.1, Point.2 etc.
Does anyone know how to do this ?
After that I need to create a line.
I have found some commands from Automation V5 but how you put thim in to practice I don't know. I'm searching the web looking for a relative example.
Any help on either things would be really appreciated.

code below (whoever wrote that and shared, many thanks)

regards
Alan

---------------------------------------------------------------------------------------------------------------------------------------

Sub CATMain()

Set oDoc = CATIA.ActiveDocument
Set oPart = oDoc.Part

Dim reference1 'As Reference

Set oHSF = oPart.HybridShapeFactory

Dim InputObject(0)
InputObject(0) = "Edge"

Set oCentre = CATIA.ActiveDocument.Selection
Status = oCentre.SelectElement2(InputObject, "Select Circle", False)

Set oTemp = oCentre.Item(1)

Set oRef = oTemp.Reference

Set oPoint = oHSF.AddNewPointCenter(oRef)

'Set oHB = oPart.HybridBodies.Add() 'Will add a new Geometrical Set for each Point
Set oHB = oPart.HybridBodies.Item("Points") 'Sends to named Geo Set

oPoint.Name = "Hole Centre" &intIndex'+(oNo-1) ' Can't get this bit to rename in sequence :(

oPoint.Compute

oHB.AppendHybridShape oPoint

End Sub



' Found this in Automation V5

'Dim oSurface As Reference
'Set oSurface = LineNormal.Surface

'Dim oPoint As Reference
'Set oPoint = LineNormal.Point

'Dim oOrientation As long
'Set oOrientation = LineNormal.Orientation

'Dim oEnd As CATIALength
'Set oEnd = LineNormal.EndOffset

'Dim oStart As CATIALength
'Set oStart = LineNormal.BeginOffset
 
Replies continue below

Recommended for you

Thanks Tesak
Tried it but it still fails at the same line. :(
hole1.Sketch.GetAbsoluteAxisData myAxisCoordinate

I'm not after selecting all the holes, I just need to select them one at a time, first the edge then the face and create the line.
The original script I botched up is fine at part level but won't update at product level.
Is there anyway for me to isolate the first point or extract it's coordinates without executing the 'hybridBody1.AppendHybridShape oCentrePoint' line.
I could then use the coordinates to make the line.
I've tried using -

vHole.GetOrigin (origin)
Msgbox "Origin = " & origin(0) & ", " & origin(1) & ", " & origin(2)

that I found online but that doesn't work either lol

cheers anyway :)
Alan




 
LWolfs code works and creates the lines great but they are in each parts geo-set.
I need all the lines to be created in a selected 'collector' parts geo-set.
I think this is where i'm having the problem.
I can get the points and lines in the selected geo-set but they wont update once there in there.

or is it me being thick ?

thanks for the help
Alan
 
That makes sense :)
The code i'm playing about with is below.
My thinking was to create a point using the method that worked in my original code but not use line 'hybridBody1.AppendHybridShape oCentrePoint'.
I was then trying to create a new Line using the coordinates from "oCentrePoint" hoping it would create a link.

I'm probably going about this in totally the wrong way lol

cheers
Alan

-----------------------------------------------------------------------------------------------------------------------------------------------

Sub CATMain()

Dim InputObject1(0)
Dim oCentreSelection
Dim oCentreItem
Dim oCentreRef
Dim oCentrePoint
Dim InputObject2(0)
Dim oFaceSelection
Dim oFaceItem
Dim oFaceRef
Dim oVector


Do


Dim part1
'Set partDocument1 = CATIA.ActiveDocument 'Part Level
Dim partDocument1
Set partDocument1 = CATIA.ActiveDocument.Product.Products.Item(1).ReferenceProduct.Parent 'Product Level


Set part1 = partDocument1.Part

Dim hybridShapeFactory1 'As Factory
Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim hybridBodies1 'As HybridBodies
Set hybridBodies1 = part1.HybridBodies

Dim hybridBody1 'As HybridBody
Set hybridBody1 = hybridBodies1.Item(1)

Dim hybridShapes1 'As HybridShapes
Set hybridShapes1 = hybridBody1.HybridShapes

Dim selection1 'As Selection
Set selection1 = partDocument1.Selection

'------------------------------Select Hole Centre & Create Point---------------------

InputObject1(0) = "Edge"

Set oCentreSelection = CATIA.ActiveDocument.Selection
Status = oCentreSelection.SelectElement2(InputObject1, "Select Circle", False)

Set oCentreItem = oCentreSelection.Item(1)

Set oCentreRef = oCentreItem.Reference

Set oCentrePoint = hybridShapeFactory1.AddNewPointCenter(oCentreRef)

'hybridBody1.AppendHybridShape oCentrePoint

'------------------------------------------------------------------------------------

Dim hole1 'As Object

Set hole1 = oCentrePoint
reDim myAxisCoordinate(8)
hole1.Sketch.GetAbsoluteAxisData myAxisCoordinate ' This is as far as it goes
OriginX = myAxisCoordinate(0)
OriginY = myAxisCoordinate(1)
OriginZ = myAxisCoordinate(2)
HorizontalX = myAxisCoordinate(3)
HorizontalY = myAxisCoordinate(4)
HorizontalZ = myAxisCoordinate(5)
VerticalX = myAxisCoordinate(6)
VerticalY = myAxisCoordinate(7)
VerticalZ = myAxisCoordinate(8)
reDim H(2) 'As Double
reDim V(2) 'As Double
H(0) = HorizontalX
H(1) = HorizontalY
H(2) = HorizontalZ
V(0) = VerticalX
V(1) = VerticalY
V(2) = VerticalZ
Dim zAxis
zAxis = CrossProd(H, V)

Set oPart = GetPartFromObject(hole1)
Set hybridShapeFactory1 = oPart.HybridShapeFactory
Dim hybridShapeDirection1 'As HybridShapeDirection
Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(zAxis(0), zAxis(1), zAxis(2))
Dim hybridShapeLinePtDir1 'As HybridShapeLinePtDir
Set hybridShapeLinePtDir1 = hybridShapeFactory1.AddNewLinePtDir(hole1.Sketch.AbsoluteAxis.Origin, hybridShapeDirection1, -0, 20, False)

Set hybridBodies1 = oPart.HybridBodies

Set hybridBody1 = hybridBodies1.item(1)

hybridBody1.AppendHybridShape hybridShapeLinePtDir1


'-----------------------------Select Face & Create Vector---------------------------- not using at the moment

'InputObject2(0)= "Face"

'Set oFaceSelection = CATIA.ActiveDocument.Selection
'Status=oFaceSelection.SelectElement2(InputObject2,"Select Face",false)

'Set oFaceItem = oFaceSelection.Item(1)

'Set oFaceRef = oFaceItem.Reference

'Set oVector = hybridShapeFactory1.AddNewLineNormal(oFaceRef, oCentrePoint, 0.000000, 50.000000, True)
'hybridBody1.AppendHybridShape oVector

'Set oPoint25 = hybridShapeFactory1.AddNewPointOnCurveFromDistance(oVector, 25.000000, False) 'Point at 25mm
'oPoint25.DistanceType = 1
'hybridBody1.AppendHybridShape oPoint25

'Set oPoint50 = hybridShapeFactory1.AddNewPointOnCurveFromDistance(oVector, 0.000000, False) 'Point at 50mm - end of Vector
'oPoint50.DistanceType = 1
'hybridBody1.AppendHybridShape oPoint50

'----------------------------------------------------------------------------------------------------------



'----------------------------Rename-------------------------------------------------

'oPoint25.Name = "OTP"

'oPoint50.Name = "OTP"


selection1.Clear

part1.Update

Loop

End Sub
 
Hi Alan,
your code is a "real" mess :). I do not understand an infinite Do ... Loop around the whole procedure. As I see it, the reason why its is not working by you is the simple fact that you use it on holes which are not the "real" CATIA Hole features, but probably holes drilled with pockets. The code from LWolf is applicable only on "real" CATIA holes.

Tesak
- Play Tetris in CATIA V5 drawing
 
Hi tesak
Ye I know it’s a mess lol
It was done to save me a lot of mouse clicks on some work I’m doing, not really meant to be an example of how to program :)
The holes I’m working ( was working on, finished now ) are created using the hole function in Catia. There not pockets.
LWolfs code works perfectly but creates lines on every hole.
The fixture had hundreds of holes in it, I only need to select about 40 so I couldn’t use that.
I ended up making an allcatpart and used my original code then copied the points back to my product. It worked but broken links :(
I just don’t understand why catia isn’t creating the reference geometry when I create the points.
Usually you can’t stop catia doing that?
It would be nice to get it working for next t8me though.

Cheers for the help
Alan
 
Hi Alan,
in your code you are mixing pears and apples. In this part of the code you assign HybridShapePointCenter point into a oCentrePoint variable and then you assign this center point to a hole1 variable. The variable hole1 is meant to be a Hole object. In fact, you are calling Sketch.GetAbsoluteAxisData on a point (HybridShapePointCenter) object, not on the Hole object as expected, so no wonder that you get an error message. Do not expect that methods of the Hole object will be applicable to the Point object as these are completely different entities.

And then, without even posting your code, you want us to give you an explanation, why the hell it is not working. Really, you have to give us all the details, otherwise, do not expect answers.

Code:
Set oCentrePoint = hybridShapeFactory1.AddNewPointCenter(oCentreRef)

'hybridBody1.AppendHybridShape oCentrePoint

'------------------------------------------------------------------------------------

Dim hole1 'As Object

Set hole1 = oCentrePoint
reDim myAxisCoordinate(8)
hole1.Sketch.GetAbsoluteAxisData myAxisCoordinate ' This is as far as it goes

Tesak
- Play Tetris in CATIA V5 drawing
 
Hi tesak,

I don't do this for a living and have no formal training, I'm trying to learn how to do little snippets of code that will help me do the job I do.
If I don't ask I won't learn.
I had no idea that the hole1 variable was supposed to be a hole object so I've learned something that I didn't know, so for that thankyou.

I didn't post the last code as the question I asked was about the original code (already posted) that wasn't allowing me to update the part.
I really do appreciate any help that you and other members of this forum have given me, it has helped me to produce some bits of code that I use everyday and that save me a lot of time.

But.
There's no need to be nasty, the last line of your post is patronizing.
You also had to learn this at some point in your life so give people a chance to mess up without trying to knock them down.
We are all engineers here and most will have experience and expertise in one field or another.
I personally wouldn't be arrogant with someone who asked for my help with something they didn't know, because at one time, I didn't know either.


thanks for the help
Alan


 
Sorry, I really didn't want to sound arrogant, I just wanted to point out to the fact, that you have to always give us all details, otherwise you are just loosing your and our time. From your post, I have had an impression that the original code from LWolf is not working, because of the snippet you posted. But in fact, you were referring to an error in your version of the code, that nobody has ever seen before. This is then really just a source of confusion and time wasting. We could have saved at least 5 posts if you had published your version of the code right below your question.
But anyway, sorry, I didn't mean to be rude.

Tesak
- Play Tetris in CATIA V5 drawing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor