×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Use the function AddNewPointOnSurface

Use the function AddNewPointOnSurface

Use the function AddNewPointOnSurface

(OP)
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 ?

RE: Use the function AddNewPointOnSurface

values of InputObjectType() ?

Eric N.
indocti discant et ament meminisse periti

RE: Use the function AddNewPointOnSurface

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

RE: Use the function AddNewPointOnSurface

(OP)
- 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 

RE: Use the function AddNewPointOnSurface

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

RE: Use the function AddNewPointOnSurface

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 --> VBA

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

RE: Use the function AddNewPointOnSurface

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)



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 --> vba

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 



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

RE: Use the function AddNewPointOnSurface

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources