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!

Adding a line normal 2 a surface in a loop

Status
Not open for further replies.

Aar0nr

New member
Aug 20, 2013
9
MX
i want to construct lines normal to a face using the centroid as a reference, but, some how one of the two references for addnewlinenormal is not working, it says it requires an object. what am i doing wrong?


For i = 1 To X
Set objsel = CATIA.ActiveDocument.Selection
objsel.Clear
objsel.Search "Type=Topology.Face,all"
X = objsel.Count2

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part

Set Selection = partDocument1.Selection

Set reference1 = Selection.Item(i).Reference

Set spabench = partDocument1.GetWorkbench("SPAWorkbench")
Set mymeas = spabench.GetMeasurable(reference1)
myans = mymeas.Area
data_file.WriteLine ("Cara #" & i)
data_file.WriteLine (myans)

'****************Centroides
Set centroide = spabench.GetMeasurable(reference1)
Dim mycoord(2)
centroide.GetCOG mycoord

xc = mycoord(0)
yc = mycoord(1)
zc = mycoord(2)

'***************Creacion de los puntos de centroides
Dim punto As HybridShapeFactory
Set punto = part1.HybridShapeFactory

Dim coord As HybridShapePointCoord
Set coord = punto.AddNewPointCoord(xc, yc, zc) 'Variables

Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies

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

hybridBody1.AppendHybridShape coord

Dim reference2 As Reference
Set reference2 = part1.CreateReferenceFromGeometry(coord)

data_file.WriteLine "Coordenadas del centroide"
data_file.WriteLine ("X: " & mycoord(0))
data_file.WriteLine ("Y: " & mycoord(1))
data_file.WriteLine ("Z: " & mycoord(2))

part1.Update

'*************************creacion de la linea normal
Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Dim body1 As Body
Set body1 = bodies1.Item("PartBody")

Dim shapes1 As Shapes
Set shapes1 = body1.Shapes

Dim solid1 As Solid
Set solid1 = shapes1.Item("PartBody")

Dim hybridShapeLineNormal1 As HybridShapeLineNormal
Set hybridShapeLineNormal1 = hybridShapeFactory1.AddNewLineNormal(reference1, reference2, 0#, 20#, False)

hybridBody1.AppendHybridShape hybridShapeLineNormal1

part1.InWorkObject = hybridShapeLineNormal1

part1.Update

thanks in advance
 
Replies continue below

Recommended for you

Hi,

I've done some small corrections to let the macro create the CoG for all faces first.

Code:
Sub CATMain()

Set objsel = CATIA.ActiveDocument.Selection
objsel.Clear
objsel.Search "Type=Topology.Face,all"
X = objsel.Count2

For i = 1 To X

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part

Set Selection = partDocument1.Selection
Set reference1 = Selection.Item(i).Reference

Set spabench = partDocument1.GetWorkbench("SPAWorkbench")
Set mymeas = spabench.GetMeasurable(reference1)
myans = mymeas.Area

'****************Centroides
Set centroide = spabench.GetMeasurable(reference1)
ReDim mycoord(2)
centroide.GetCOG mycoord

xc = mycoord(0)
yc = mycoord(1)
zc = mycoord(2)

'***************Creacion de los puntos de centroides
Dim punto As HybridShapeFactory
Set punto = part1.HybridShapeFactory

Dim coord As HybridShapePointCoord
Set coord = punto.AddNewPointCoord(xc, yc, zc) 'Variables

Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies

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

hybridBody1.AppendHybridShape coord

Dim reference2 As Reference
Set reference2 = part1.CreateReferenceFromGeometry(coord)

Next

'*************************creacion de la linea normal
''I didn't wrote your code here
End Sub

Up to here the modified macro is working good but after that where is Set reference1 in your macro ?

Regards
Fernando

 
hi ferdo, it works now, this is what i did:

Set objsel = CATIA.ActiveDocument.Selection
objsel.Clear
objsel.Search "Type=Topology.Face,all"
X = objsel.Count2

Dim varlinea As Integer
varlinea = objsel.Count2

'********************CICLO*************************
'****************Areas
For i = 1 To X
Set objsel = CATIA.ActiveDocument.Selection
objsel.Clear
objsel.Search "Type=Topology.Face,all"

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set Selection = partDocument1.Selection

Set ref1 = Selection.Item(i).Reference

'****************Centroides
Set centroide = spabench.GetMeasurable(ref1)
Dim mycoord(2)
centroide.GetCOG mycoord

xc = mycoord(0)
yc = mycoord(1)
zc = mycoord(2)

'***************Creacion de los puntos de centroides
Dim punto As HybridShapeFactory
Set punto = part1.HybridShapeFactory

Dim coord As HybridShapePointCoord
Set coord = punto.AddNewPointCoord(xc, yc, zc) 'This is where i create a point on the face centroid

Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies

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

hybridBody1.AppendHybridShape coord

data_file.WriteLine "Coordenadas del centroide"
data_file.WriteLine ("X: " & mycoord(0))
data_file.WriteLine ("Y: " & mycoord(1))
data_file.WriteLine ("Z: " & mycoord(2))

part1.Update

'***********************************************
Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Dim body1 As Body
Set body1 = bodies1.Item("PartBody")

Dim shapes1 As Shapes
Set shapes1 = body1.Shapes

Dim solid1 As Solid
Set solid1 = shapes1.Item("PartBody")

Dim reflinea2 As Reference
Set reflinea2 = part1.CreateReferenceFromObject(coord) 'reference for the point

Dim reflinea1 As Reference
Set reflinea1 = part1.CreateReferenceFromBRepName("RSur:(Face:(Brp:(PartBody;" + CStr(varlinea) + ");None:();Cf11:());WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", solid1)

'i had to create a reference from the BRepname of the face, it is the only way i found to make it work. using varlinea value to create a reference for every face of the part.
'****
Dim hybridShapes1 As HybridShapes
Set hybridShapes1 = hybridBody1.HybridShapes

Dim hybridShapePointCoord1 As HybridShapePointCoord
Set hybridShapePointCoord1 = hybridShapes1.Item("Point." & i)

Dim hybridShapeLineNormal1 As HybridShapeLineNormal
Set hybridShapeLineNormal1 = hybridShapeFactory1.AddNewLineNormal(reflinea1, reflinea2, 0#, 20#, False) '20 mm, it could be anything.

hybridBody1.AppendHybridShape hybridShapeLineNormal1

part1.InWorkObject = hybridShapeLineNormal1

part1.Update

'its only working for .IGS

thanks a lot for your time ferdo, i had to create the line normal inside the cicle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top