Advertisement
HaFroProductions

3DText for CATIA (0.0.1.0) - M_Functions

Sep 23rd, 2011
1,462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.50 KB | None | 0 0
  1. Public Module M_Functions
  2.     Public ActiveDocument1 As Document
  3.     Public Selection1 As Object
  4.     Public reference1 As Reference
  5.  
  6.     '------------------------------------------------------
  7.     ' ConnectCATIA
  8.     '------------------------------------------------------
  9.     Public Sub ConnectCATIA()
  10.         ' call CATIA
  11.         On Error Resume Next
  12.         If F_Main.CATIA Is Nothing Then
  13.             F_Main.CATIA = GetObject(vbNullString, "CATIA.Application")
  14.             ' CATIA response
  15.             If F_Main.CATIA Is Nothing Then
  16.                 Call MsgBox("Could not connect to CATIA", vbCritical + vbOKOnly, "Error")
  17.                 End
  18.             End If
  19.         End If
  20.     End Sub
  21.  
  22.  
  23.     '------------------------------------------------------
  24.     ' SelectFace
  25.     '------------------------------------------------------
  26.     Sub SelectFace()
  27.         'Dim ActiveDocument1 As Document
  28.         ActiveDocument1 = F_Main.CATIA.ActiveDocument
  29.  
  30.         'Dim Selection1 As Object
  31.         Selection1 = ActiveDocument1.Selection
  32.         Selection1.Clear()
  33.  
  34.         Dim IOT(0)
  35.         IOT(0) = "PlanarFace"
  36.         Dim strreturn As String
  37.         strreturn = Selection1.SelectElement2(IOT, "Select a planar face", False)
  38.  
  39.         If strreturn <> "Normal" Then
  40.             Exit Sub
  41.         End If
  42.  
  43.         'Dim reference1 As Reference
  44.         reference1 = Selection1.Item(1).Reference
  45.  
  46.  
  47.         If TypeName(ActiveDocument1) = "ProductDocument" Then
  48.             F_Main.Part1 = Selection1.Item(1).LeafProduct.ReferenceProduct.Parent.Part
  49.         ElseIf TypeName(ActiveDocument1) = "PartDocument" Then
  50.             F_Main.Part1 = ActiveDocument1.Part
  51.         End If
  52.  
  53.     End Sub
  54.  
  55.     '------------------------------------------------------
  56.     ' Create3DText
  57.     '------------------------------------------------------
  58.     Sub Create3DText()
  59.  
  60.         Dim InWorkObject1 As Object
  61.         InWorkObject1 = F_Main.Part1.InWorkObject
  62.  
  63.         Dim documents1 As Documents
  64.         documents1 = F_Main.CATIA.Documents
  65.         Dim drawingDocument1 As DrawingDocument
  66.         drawingDocument1 = documents1.Add("Drawing")
  67.         'drawingDocument1.Standard = catISO
  68.  
  69.         Dim drawingSheets1 As DrawingSheets
  70.         drawingSheets1 = drawingDocument1.Sheets
  71.         Dim drawingSheet1 As DrawingSheet
  72.         drawingSheet1 = drawingSheets1.Item(1)
  73.         'drawingSheet1.PaperSize = catPaperA0
  74.         drawingSheet1.[Scale] = 1.0#
  75.         'drawingSheet1.Orientation = catPaperLandscape
  76.  
  77.  
  78.         Dim drawingViews1 As DrawingViews
  79.         drawingViews1 = drawingSheet1.Views
  80.  
  81.         Dim drawingView1 As DrawingView
  82.         drawingView1 = drawingViews1.Item("Main View")
  83.  
  84.         Dim drawingTexts1 As DrawingTexts
  85.         drawingTexts1 = drawingView1.Texts
  86.  
  87.         Dim drawingText1 As DrawingText
  88.         drawingText1 = drawingTexts1.Add(F_Main.TB_Text.Text, 0, 0) '.Item("Text.1")
  89.  
  90.  
  91.  
  92.         If Not F_Main.Font1 Is Nothing Then
  93.             Dim iFontSize As Double
  94.             iFontSize = 100.5
  95.             drawingText1.SetFontSize(0, 0, iFontSize)
  96.             Try
  97.                 drawingText1.SetFontName(0, 0, F_Main.Font1.Name & " (TrueType)")
  98.             Catch ex As Exception
  99.  
  100.             End Try
  101.         End If
  102.  
  103.         ' TEMP DXF
  104.         Dim TempDXF_Path As String = F_Main.TempDir & "\TEMP.dxf"
  105.  
  106.         drawingDocument1.ExportData(TempDXF_Path, "dxf")
  107.         drawingDocument1.Close()
  108.  
  109.  
  110.         Dim document2 As Document
  111.         document2 = documents1.Open(TempDXF_Path)
  112.  
  113.         Dim drawingDocument2 As DrawingDocument
  114.         drawingDocument2 = F_Main.CATIA.ActiveDocument
  115.  
  116.         Dim selection2 As Selection
  117.         selection2 = drawingDocument2.Selection
  118.  
  119.         selection2.Clear()
  120.  
  121.  
  122.  
  123.         Dim drawingSheets2 As DrawingSheets
  124.         drawingSheets2 = drawingDocument2.Sheets
  125.  
  126.         Dim drawingSheet2 As DrawingSheet
  127.         'drawingSheet2 = drawingSheets2.Item("Model")
  128.         drawingSheet2 = drawingSheets2.Item(1)
  129.  
  130.         Dim drawingViews2 As DrawingViews
  131.         drawingViews2 = drawingSheet2.Views
  132.  
  133.         Dim drawingView2 As DrawingView
  134.         drawingView2 = drawingViews2.Item("Hauptansicht")
  135.         'drawingView2 = drawingViews2.Item(1)
  136.  
  137.         selection2.Add(drawingView2)
  138.         selection2.Copy()
  139.  
  140.  
  141.         Selection1.clear()
  142.         Selection1.Add(reference1)
  143.         Selection1.Paste()
  144.  
  145.         F_Main.Sketch1 = Selection1.item(1).value
  146.  
  147.         drawingDocument2.Close()
  148.         System.IO.File.Delete(TempDXF_Path)
  149.  
  150.     End Sub
  151.  
  152. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement