Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Use the function AddNewPointOnSurface

Status
Not open for further replies.

Pharys

Aerospace
Jul 29, 2015
15
0
0
GB
Hi everyone,

I'm trying to create a point in the center of a surface with the use of the AddNewPointOnSurface function. For the moment it doesn't work and I can't find why..
My surface is selected with the SelectElement2 function and this work great (I tried to change its color with VisProperties.SetRealColor).

Here is a piece of my code :

Code:
oSelection.Clear
SelectionStatus = oSelection.SelectElement2(InputObjectType, "Select a face", False)
Set oSelectedFace = oSelection.Item(1).Value
oSelection.Clear

Set FaceReferencePlaneForObject = oPart.CreateReferenceFromObject(oSelectedFace)
Set oDir = oHybridShapeFactory.AddNewDirection(oSelectedFace)

Set oFaceCenterPt = oHybridShapeFactory.AddNewPointOnSurface(FaceReferencePlaneForObject, oDir, 0)
oMyHybridBody.AppendHybridShape oFaceCenterPt

Any idea ?
 
Replies continue below

Recommended for you

i have the feeling that normal to surface direction might not be possible in this case, try any other direction.


Eric N.
indocti discant et ament meminisse periti
 
- InputObjectType(0)="PlanarFace"

What I tried :

I created new directions using AddNewDirectionByCoord; I put random values but it didn't worked.

I retrieved the CofG coordinates with the Inertia object but unfortunately it creates a point at (0,0,0).

Code:
                '---------------------------------------------
                'Create the center point
                '---------------------------------------------
                                
                Dim Coordinates(2)
                oSelectedFace.Inertia.GetCOGPosition Coordinates
                oPart.Update
                
                Set oFaceCenterPt = oHybridShapeFactory.AddNewPointCoord(Coordinates(0), Coordinates(1), Coordinates(2))
                oMyHybridBody.AppendHybridShape oFaceCenterPt
    
                oFaceCenterPt.Name = strICDName
    
                oPart.Update
                oSelection.Clear
 
In order to use GetCOGPosition, you need the SPAWorkbench...looks like you only gave a portion of your code, so I can't tell.

One way to do it is at this link, look at "Measuring the inertia of a specific surface"...

I have a code that makes a reference from a selection, but if a BREP (face, edge, etc) is picked, it fails...can you make a reference from a BREP? Maybe you need to extract the face first, and use the extract to get the COG from.

Dim oExtract as HybridShapeExtract
Set oExtract = ohybridShapeFactory.AddNewExtract oSelectedFace
oMyHybridBody.Append oExtract
 
I have the feeling AddNewDirection will not accept a referenced face. it works when i select a plane (I changed InputObjectType().

but if you create a direction by value (1,0,0) it works

please also look at how I pass the reference:

Code:
Sub CATMain()

Dim oSelection 'As Selection
Set oSelection = CATIA.ActiveDocument.Selection

Dim oPart As Part
Set oPart = CATIA.ActiveDocument.Part

Dim oHybridShapeFactory As HybridShapeFactory
Set oHybridShapeFactory = oPart.HybridShapeFactory

Dim oMyHybridBody As HybridBody
Set oMyHybridBody = oPart.HybridBodies.Add

Dim InputObjectType()
ReDim InputObjectType(0)
InputObjectType(0) = "PlanarFace"

oSelection.Clear
SelectionStatus = oSelection.SelectElement2(InputObjectType, "Select a face", False)
Set oSelectedFace = oSelection.Item(1)
oSelection.Clear

Dim FaceReferencePlaneForObject As Reference
Set FaceReferencePlaneForObject = oSelectedFace.Reference

Dim oDir As HybridShapeDirection
Set oDir = oHybridShapeFactory.AddNewDirectionByCoord(1, 0, 0)

Set oFaceCenterPt = oHybridShapeFactory.AddNewPointOnSurface(FaceReferencePlaneForObject, oDir, 0)

oMyHybridBody.AppendHybridShape oFaceCenterPt

oPart.Update

End Sub






Eric N.
indocti discant et ament meminisse periti
 
just to be clear, the direction does not really matters as the value for the point distance = 0.

I also found that if the face does have a hole (let say near where the point should be) then the point will be created on the selected surface closest to the point created if there was no Hole)

the green point is the point created when the solid is defined only by the Pad, the pink point is created after the Hole (I had to isolate the green point)

2015-09-12_12-42-04_kyzbei.png


I also create a point with formula centerofgravity (extarcted face of the solid). The point created by the script is off the CoG.

So if you want the point at the CoG of the solid's face, you have to use the SPAWorkbench and get the COG coordinate of the face:

Code:
Sub CATMain()

Dim oSelection 'As Selection
Set oSelection = CATIA.ActiveDocument.Selection

Dim oPart As Part
Set oPart = CATIA.ActiveDocument.Part

Dim TheSPAWorkbench  As SPAWorkbench
Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")

Dim oHybridShapeFactory As HybridShapeFactory
Set oHybridShapeFactory = oPart.HybridShapeFactory

Dim oMyHybridBody As HybridBody
Set oMyHybridBody = oPart.HybridBodies.Add

Dim InputObjectType()
ReDim InputObjectType(0)
InputObjectType(0) = "PlanarFace"

oSelection.Clear
SelectionStatus = oSelection.SelectElement2(InputObjectType, "Select a face", False)
Set oSelectedFace = oSelection.Item(1)
oSelection.Clear

Dim faceCoG(2)

Dim TM 'As Measurable
Set TM = TheSPAWorkbench.GetMeasurable(oSelectedFace.Reference)

TM.GetCOG faceCoG

Dim FaceReferencePlaneForObject As Reference
Set FaceReferencePlaneForObject = oSelectedFace.Reference

Dim oDir As HybridShapeDirection
Set oDir = oHybridShapeFactory.AddNewDirectionByCoord(1, 0, 0)

Set oFaceCenterPt = oHybridShapeFactory.AddNewPointOnSurface(FaceReferencePlaneForObject, oDir, 0)

Set oFaceCoGPt = oHybridShapeFactory.AddNewPointCoord(faceCoG(0), faceCoG(1), faceCoG(2))

oMyHybridBody.AppendHybridShape oFaceCenterPt

oMyHybridBody.AppendHybridShape oFaceCoGPt

oFaceCoGPt.Name = "CoG of Face"

oFaceCenterPt.Name = "(not the)Center of Face"

oPart.Update

End Sub

2015-09-12_13-12-20_dgzjf7.png


the FaceCenter point will move if the face change, the CoG is a point by coord, it will not change if the face change. if you want it to follow the geometry you have to create a surface extract, then the CoG point by formula of that extract.

Eric N.
indocti discant et ament meminisse periti
 
Sorry guys, I was off until today.

Yes lardman363, I only gave you a piece of code because I am not allowed to show the rest of it...
In any case, I checked my code and for the CofG, I have been wrong on two things :
- I didn't use the SPAWorkbench.
- And even if I've done it so, the Inertia object was inapropriate.

itsmyjob, I reviewed what I've done concerning the AddNewPointOnSurface and I have the same code as you, nevertheless it doesn't work. Here is why :
- The task I want to achieve is part of a bigger project and I tried to implement the solution directly in it.
It might be better to isolate the writing of the task solution in a module before integrated it to the rest. It will help me to avoid errors.

I'm going to use your piece of code to get the CofG of my solid's face.

Thank you for your help guys.
Pharys
 
Status
Not open for further replies.
Back
Top