Sub CATMain()
Const PATH_TO_POINTS_FILE = "C:\Temp\Points.txt"
' read points to be used for geometry generation from a file
Dim aPoint(2) ' as Double
Dim aPoints() ' As Double
Dim iNbPoints ' as Integer
iNbPoints = 0
Dim fsoFileSystem ' As FileSystemObject
Set fsoFileSystem = CreateObject("Scripting.FileSystemObject")
Dim tsSourceStream ' as TextStream
On Error Resume Next
Set tsSourceStream = fsoFileSystem.OpenTextFile(PATH_TO_POINTS_FILE)
If (Err.Number <> 0) Then
MsgBox "Can't open source file for reading (" & PATH_TO_POINTS_FILE & ")"
Exit Sub
End If
Dim sLine As String
Dim aLineSplit ' as Variant
Do While (tsSourceStream.AtEndOfStream = False)
' read next line
sLine = tsSourceStream.ReadLine()
' trying to split contents
Err.Clear
On Error Resume Next
aLineSplit = Split(sLine, " ")
If (Err.Number = 0) Then
' saving contents in array
ReDim Preserve aPoints(iNbPoints)
On Error Resume Next
aPoint(0) = Round(Val(aLineSplit(0)), 3)
On Error Resume Next
aPoint(1) = Round(Val(aLineSplit(1)), 3)
On Error Resume Next
aPoint(2) = Round(Val(aLineSplit(2)), 3)
If (Err.Number = 0) Then
aPoints(iNbPoints) = aPoint
iNbPoints = iNbPoints + 1
End If
End If
Loop
' close stream
tsSourceStream.Close
' get selection object
Dim oSelection As Selection
Set oSelection = CATIA.ActiveDocument.Selection
'------------------------------------------------
' FIND ALL GENERATED GEOMETRY IN SELECTED FEATURE
'------------------------------------------------
' start selection procedure
Dim oSelectedSolid As Body
Dim vSelection ' as Variant
Set vSelection = oSelection
Dim aSelTypeFilter(0) ' as Variant
aSelTypeFilter(0) = "Body"
Dim sSelResult ' as String
sSelResult = vSelection.SelectElement2(aSelTypeFilter, "Select body in which you want to find points", False)
If (sSelResult <> "Normal") Or (vSelection.Count <> 1) Then
' nothing has been selected
Exit Sub
Else
Set bdSelectedBody = oSelection.Item(1).Value
End If
Dim iGeometry ' As Long
' find all vertices
oSelection.Clear
oSelection.Add bdSelectedBody
oSelection.Search "Topology.Vertex;sel"
Dim aVertices() As Vertex
Dim vtVertex As Vertex
Dim iNbVertices ' as Integer
iNbVertices = 0
For iGeometry = 1 To oSelection.Count
Set vtVertex = oSelection.Item(iGeometry).Value
' save to array
ReDim Preserve aVertices(iNbVertices) As Vertex
Set aVertices(iNbVertices) = vtVertex
iNbVertices = iNbVertices + 1
Next
' find all edges
oSelection.Clear
oSelection.Add bdSelectedBody
oSelection.Search "Topology.Edge;sel"
Dim aEdges() As Edge
Dim edEdge As Edge
Dim iNbEdges ' as Integer
iNbEdges = 0
For iGeometry = 1 To oSelection.Count
Set edEdge = oSelection.Item(iGeometry).Value
' save to array
ReDim Preserve aEdges(iNbEdges) As Edge
Set aEdges(iNbEdges) = edEdge
iNbEdges = iNbEdges + 1
Next
' find all faces
oSelection.Clear
oSelection.Add bdSelectedBody
oSelection.Search "Topology.Face;sel"
Dim aFaces() As Face
Dim fcFace As Face
Dim iNbFaces ' as Integer
iNbFaces = 0
For iGeometry = 1 To oSelection.Count
Set fcFace = oSelection.Item(iGeometry).Value
' save to array
ReDim Preserve aFaces(iNbFaces) As Face
Set aFaces(iNbFaces) = fcFace
iNbFaces = iNbFaces + 1
Next
'---------------------------------------------
' MEASURE DISTANCE BETWEEN POINTS AND GEOMETRY
'---------------------------------------------
' get Part container of active document
Dim prtPart As Part
Set prtPart = CATIA.ActiveDocument.Part
' get SPA workbench
Dim wbSPA As SPAWorkbench
Set wbSPA = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
' access point on Measurable interface
Dim refPoint As Reference
Dim mesPoint As Measurable
Dim pntPoint As Point
Dim refGeometry As Reference
Dim dDistance ' as Double
Dim bGeometryFound ' as Boolean
' clear selection
oSelection.Clear
' loop through all points
Dim iPoint ' as Integer
For iPoint = 0 To iNbPoints - 1
' create "point-by-coordinates" feature
Set pntPoint = prtPart.HybridShapeFactory.AddNewPointCoord(aPoints(iPoint)(0), aPoints(iPoint)(1), aPoints(iPoint)(2))
pntPoint.Compute
' access it on Measurable interface
Set refPoint = prtPart.CreateReferenceFromObject(pntPoint)
Set mesPoint = wbSPA.GetMeasurable(refPoint)
bGeometryFound = False
' measure distance to VERTICES
If (bGeometryFound = False) Then
For iGeometry = 0 To iNbVertices - 1
Set vtVertex = aVertices(iGeometry)
Set refGeometry = vtVertex
dDistance = mesPoint.GetMinimumDistance(refGeometry)
dDistance = Round(dDistance, 3)
' if distance equals to zero then we've found desired geometry
If (dDistance = 0) Then
' add geometry to selection
oSelection.Add vtVertex
' exit loop
bGeometryFound = True
Exit For
End If
Next
End If
' measure distance to EDGES
If (bGeometryFound = False) Then
For iGeometry = 0 To iNbEdgees - 1
Set edEdge = aEdges(iGeometry)
Set refGeometry = edEdge
dDistance = mesPoint.GetMinimumDistance(refGeometry)
dDistance = Round(dDistance, 3)
' if distance equals to zero then we've found desired geometry
If (dDistance = 0) Then
' add geometry to selection
oSelection.Add edEdge
' exit loop
bGeometryFound = True
Exit For
End If
Next
End If
' measure distance to FACES
If (bGeometryFound = False) Then
For iGeometry = 0 To iNbFaces - 1
Set fcFace = aFaces(iGeometry)
Set refGeometry = fcFace
dDistance = mesPoint.GetMinimumDistance(refGeometry)
dDistance = Round(dDistance, 3)
' if distance equals to zero then we've found desired geometry
If (dDistance = 0) Then
' add geometry to selection
oSelection.Add fcFace
' exit loop
bGeometryFound = True
Exit For
End If
Next
End If
' delete created feature
prtPart.HybridShapeFactory.DeleteObjectForDatum pntPoint
Next ' iPoint
End Sub
Dim prtPart as Part
Dim bdCurrentSolid as Body
' получение "рабочего объекта"
Dim oInWorkObject as Object
Set oInWorkObject = prtPart.InWorkObject
' если рабочий объект не является телом, в качестве "текущего твердотельного" выбирается PartBody
If (TypeName(prtPart.InWorkObject) <> "Body") Then
Set bdCurrentSolid = prtPart.MainBody
Else
' рабочий объект является телом, оно выбирается в качестве "текущего твердотельного элемента"
Set bdCurrentSolid = oInWorkObject
End If
Values:
ZeroDim
Topological 0-D entity (such as a Point2D )
MonoDim
Topological 1-D entity which cannot be infinite (such as a HybridShapeSpline )
MonoDimInfinite
Topological 1-D entity which may be infinite, such as a HybridShapeSpline (not infinite) or a HybridShapeLinePtDir for which a call to HybridShapeLinePtDir.GetLengthType would give 1, 2 or 3 (infinite)
RectilinearMonoDim
1-D entity which cannot be infinite, the entity having a rectilinear geometry
RectilinearMonoDimInfinite
1-D entity which may be infinite, the entity having a rectilinear geometry
BiDim
Topological 2-D entity which cannot be infinite (such as a HybridShapeCylinder )
BiDimInfinite
Topological 2-D entity which may be infinite, such as a HybridShapeCylinder (non infinite) or a HybridShapePlaneOffsetPt (infinite)
PlanarBiDim
2-D entity which cannot be infinite, the entity having a planar geometry
PlanarBiDimInfinite
2-D entity having a planar geometry
CylindricalBiDim
2-D entity which cannot be infinite, the entity having a cylindrical geometry
TriDim
Topological 3-D entity (such as a Pad )
Wireless_Fidelity писал(а):И снова здравствуйте.
3. Disassemble'а в Automation нету....
если не секрет, это из третьей платформы бизнес объекты, или примитивы через RADE реализованные?создал несколько классов особых объектов..
Artem писал(а):кстати доступ к ребрам, если без селекшна обходится, хорошо реализуется через экспертное правило -можно вывести имена любой топологии в лист, а а с них получить фичеры которым они принадлежат
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 1