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 :
Any idea ?
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
Maybe it will be good to get the CoG of the surface then get the coordinates. Finally, copy paste that CoG point as you wish. Is just an idea...
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: Use the function AddNewPointOnSurface
indocti discant et ament meminisse periti
RE: Use the function AddNewPointOnSurface
indocti discant et ament meminisse periti
RE: Use the function AddNewPointOnSurface
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.ClearRE: Use the function AddNewPointOnSurface
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
but if you create a direction by value (1,0,0) it works
please also look at how I pass the reference:
CODE --> VBA
indocti discant et ament meminisse periti
RE: Use the function AddNewPointOnSurface
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 Subthe 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.
indocti discant et ament meminisse periti
RE: Use the function AddNewPointOnSurface
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