L3munoz
Industrial
- Aug 29, 2011
- 26
Hi everybody,
I'm still working on my CATIA script to create a body from some points coordinates I have in an Excel file. I found great information about scripts to perform this task, so it is going pretty well. However I still have a problem.
Here is the deal. I have curves which share some 'conection' points, as this vertices are belonging to 3 or 4 curves in some intersections. If I write the Excel file with all the points for each curve I guess it will result in some cases in to 3 or 4 'different' points at the same coordinates. How can I fix this problem?
My idea was to create a ConnectionPoints array where all this vertices are loaded. Then another matrix where each row is the curve I consider, and the columns are the beginning and ending conection point index. Something like this, considering I just have 4 vertices to build up a pyramid.
[1 2; 2 4; 2 3; 1 3; 3 4; 1 4]
Then, when I create the splines, first I add the start point, then I just read all the points but the extremes from the Excel file, and finally I add the end point. Please, find below the code. So, when I run it, it gives me an "Type Mismatch" error in the command
Spline(iSplineId).AddPoint ConnectionPoint(iStartPointId)
I was expectig it to add the connection point with index iStartPointId in the spline, but it doesnt. I think it is because of ConnectionPoint(...) type. But I don't have any other idea about how to fix this problem without creating this ConnectionPoint array...
Any help or advice is welcome. Thanks in advance...
L3munoz.
Sub BuildingModel()
Dim PtDoc As Object
Dim PtPart As Object
Dim PtHybridBody As Object
Dim myPtHybridBody As Object
Dim myPtSheet As Object
Set PtDoc = GetCATIAPartDocument
Set PtPart = PtDoc.Part
Set PtHybridBody = PtPart.HybridBodies
Set myPtHybridBody = PtHybridBody.Add
myPtHybridBody.Name = "Train Geometry"
Set myPtSheet = GetExcelFile
Dim iLinea As Integer
Dim iValide As Integer
Dim X As Double
Dim Y As Double
Dim Z As Double
Dim ExtremePoints() As Integer
Set ExtremePoints() = GeometryInfo
Dim ConnectionPoint() As Object
Dim Point As Object
Dim Spline() As Object
Dim iPointId As Integer
Dim iSplineId As Integer
Dim iStartPointId As Integer
Dim iEndPointId As Integer
iLinea = 1
iValide = 0
iPointId = 1
iSplineId = 1
While iValide<> ciEnd
AnalyzeCell myPtSheet, iLinea, X, Y, Z, iValide
iLinea = iLinea + 1
If (iValide = 1) Then
While iValide <> ciEndConnectionPoints
AnalyzeCell myPtSheet, iLinea, X, Y, Z, iValide
iLinea = iLinea + 1
ReDim ConnectionPoint(1 to iPointId) As Object
Set ConnectionPoint(iPointId) = PtPart.HybridShapeFactory.AddNewPointCoord(X, Y, Z)
myPtHybridBody.AppendHybridShape ConnectionPoint(iPointId)
iPointId = iPointId + 1
Wend
End If
If (iValide = 2) Then
ReDim Spline(1 to iSplineId) As Object
Set Spline(iSplineId) = PtPart.HybridShapeFactory.AddNewSpline
Spline(iSplineId).SetSplineType 0
Spline(iSplineId).SetClosing 0
iStartPointId = ExtremePoints(iSplineId,1)
iEndPointId = ExtremePoints(iSplineId,2)
Spline(iSplineId).AddPoint ConnectionPoint(iStartPointId)
While iValide <> ciEndCurve
AnalyzeCell myPtSheet, iLinea, X, Y, Z, iValide
iLinea = iLinea + 1
If (iValide = 0) Then
Set Point = PtPart.HybridShapeFactory.AddNewPointCoord(X, Y, Z)
myPtHybridBody.AppendHybridShape Point
Spline(iSplineId).AddPoint Point
End If
Wend
Spline(iSplineId).AddPoint ConnectionPoint(iEndPointId)
myPtHybridBody.AppendHybridShape Spline(iSplineId)
iSplineId = iSplineId + 1
End If
PtPart.Update
Wend
End Sub
I'm still working on my CATIA script to create a body from some points coordinates I have in an Excel file. I found great information about scripts to perform this task, so it is going pretty well. However I still have a problem.
Here is the deal. I have curves which share some 'conection' points, as this vertices are belonging to 3 or 4 curves in some intersections. If I write the Excel file with all the points for each curve I guess it will result in some cases in to 3 or 4 'different' points at the same coordinates. How can I fix this problem?
My idea was to create a ConnectionPoints array where all this vertices are loaded. Then another matrix where each row is the curve I consider, and the columns are the beginning and ending conection point index. Something like this, considering I just have 4 vertices to build up a pyramid.
[1 2; 2 4; 2 3; 1 3; 3 4; 1 4]
Then, when I create the splines, first I add the start point, then I just read all the points but the extremes from the Excel file, and finally I add the end point. Please, find below the code. So, when I run it, it gives me an "Type Mismatch" error in the command
Spline(iSplineId).AddPoint ConnectionPoint(iStartPointId)
I was expectig it to add the connection point with index iStartPointId in the spline, but it doesnt. I think it is because of ConnectionPoint(...) type. But I don't have any other idea about how to fix this problem without creating this ConnectionPoint array...
Any help or advice is welcome. Thanks in advance...
L3munoz.
Sub BuildingModel()
Dim PtDoc As Object
Dim PtPart As Object
Dim PtHybridBody As Object
Dim myPtHybridBody As Object
Dim myPtSheet As Object
Set PtDoc = GetCATIAPartDocument
Set PtPart = PtDoc.Part
Set PtHybridBody = PtPart.HybridBodies
Set myPtHybridBody = PtHybridBody.Add
myPtHybridBody.Name = "Train Geometry"
Set myPtSheet = GetExcelFile
Dim iLinea As Integer
Dim iValide As Integer
Dim X As Double
Dim Y As Double
Dim Z As Double
Dim ExtremePoints() As Integer
Set ExtremePoints() = GeometryInfo
Dim ConnectionPoint() As Object
Dim Point As Object
Dim Spline() As Object
Dim iPointId As Integer
Dim iSplineId As Integer
Dim iStartPointId As Integer
Dim iEndPointId As Integer
iLinea = 1
iValide = 0
iPointId = 1
iSplineId = 1
While iValide<> ciEnd
AnalyzeCell myPtSheet, iLinea, X, Y, Z, iValide
iLinea = iLinea + 1
If (iValide = 1) Then
While iValide <> ciEndConnectionPoints
AnalyzeCell myPtSheet, iLinea, X, Y, Z, iValide
iLinea = iLinea + 1
ReDim ConnectionPoint(1 to iPointId) As Object
Set ConnectionPoint(iPointId) = PtPart.HybridShapeFactory.AddNewPointCoord(X, Y, Z)
myPtHybridBody.AppendHybridShape ConnectionPoint(iPointId)
iPointId = iPointId + 1
Wend
End If
If (iValide = 2) Then
ReDim Spline(1 to iSplineId) As Object
Set Spline(iSplineId) = PtPart.HybridShapeFactory.AddNewSpline
Spline(iSplineId).SetSplineType 0
Spline(iSplineId).SetClosing 0
iStartPointId = ExtremePoints(iSplineId,1)
iEndPointId = ExtremePoints(iSplineId,2)
Spline(iSplineId).AddPoint ConnectionPoint(iStartPointId)
While iValide <> ciEndCurve
AnalyzeCell myPtSheet, iLinea, X, Y, Z, iValide
iLinea = iLinea + 1
If (iValide = 0) Then
Set Point = PtPart.HybridShapeFactory.AddNewPointCoord(X, Y, Z)
myPtHybridBody.AppendHybridShape Point
Spline(iSplineId).AddPoint Point
End If
Wend
Spline(iSplineId).AddPoint ConnectionPoint(iEndPointId)
myPtHybridBody.AppendHybridShape Spline(iSplineId)
iSplineId = iSplineId + 1
End If
PtPart.Update
Wend
End Sub