Advertisement
Guest User

Excel VBA Catai point

a guest
Apr 23rd, 2014
1,345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Filename As String
  2. Private Sub Browse_Click()
  3.     'Open File
  4.        Mainform.Hide
  5.         Filename = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
  6.         If Filename <> "False" Then
  7.             Application.Visible = False
  8.             filenamebox.Value = Filename
  9.         Else
  10.             Application.Visible = False
  11.             Filename = filenamebox.Value
  12.         End If
  13.         Mainform.Show
  14.     End Sub
  15.  
  16.     Private Sub ClearButton_Click()
  17.         Mainform.Hide
  18.         ActiveWorkbook.Close (False)
  19.         Application.Visible = False
  20.     End Sub
  21.  
  22.     Private Sub OKButton_Click()
  23.     'Set Up Message Labels
  24.        Title = "Information Message"
  25.     'Check for Entered Values
  26.        If filenamebox.Value <> "" Then
  27.             Workbooks.Open Filename:=Filename
  28.             Application.Visible = False
  29.     'Start CATIA and add an Open body to the document
  30.            'Start_CATIA Not needed because you are in process with CATIA.
  31.         Dim MyPartDocument As PartDocument
  32.             Dim MyPart As Part
  33.             Dim PointGeoSet As HybridBody
  34.             Set MyPartDocument = CATIA.Documents.Add("Part")
  35.             Set MyPart = MyPartDocument.Part
  36.             Set PointGeoSet = MyPart.HybridBodies.Add()
  37.             PointGeoSet.Name = "MyPoints"
  38.             Mainform.Hide
  39.     'Read Point Data from file and create point in CATIA
  40.            i = 2
  41.             Do Until Worksheets("Sheet1").Range("a" & i).Value = ""
  42.                 x = Worksheets("Sheet1").Range("a" & i).Value
  43.                 y = Worksheets("Sheet1").Range("b" & i).Value
  44.                 z = Worksheets("Sheet1").Range("c" & i).Value
  45.                 'call point creation sub
  46.                CreateZYXPoint MyPart, PointGeoSet,x,y,z,cstr(i)
  47.                 i = i + 1
  48.             Loop
  49.             i = i - 2
  50.             MsgBox i & " Points Created in New Part", , Title
  51.         Else
  52.             MsgBox "Enter a Filename", , Title
  53.         End If
  54.         ActiveWorkbook.Close (False)
  55.         'update part in Catia
  56.     MyPart.Update
  57.         Mainform.Show
  58.     End Sub
  59.  
  60.     Private Sub UserForm_Initialize()
  61.         If Worksheets("Filepath_Location").Range("a1").Value <> "" Then
  62.             Filename = Worksheets("Filepath_Location").Range("a1").Value
  63.             filenamebox.Value = Filename
  64.         End If
  65.     End Sub
  66.  
  67. Sub CreateXYZPoint(TargetPart As Part, TargetGeometricalSet As HybridBody, _
  68.                 Xmm As Double, Ymm As Double, Zmm As Double, _
  69.                 PointCount As String)
  70. Dim HSFactory As HybridShapeFactory
  71. Dim NewPoint As Point
  72.  
  73. 'get the factory
  74. Set HSFactory = TargetPart.HybridShapeFactory
  75.  
  76. 'create the point with the factory
  77. Set NewPoint = HSFactory.AddNewPointCoord(Xmm, Ymm, Zmm)
  78.  
  79. 'Append the point to the geometrical set
  80. TargetGeometricalSet.AppendHybridShape NewPoint
  81.  
  82. 'rename the point
  83. NewPoint.Name = "Point." & PointCount
  84.  
  85. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement