Академический Документы
Профессиональный Документы
Культура Документы
' ****************************************************************************
' Purpose: To draw a Frame and TitleBlock
'
' Assumptions: A Drafting document should be active
'
' Author: GDG\DU\PYW
' Languages: VBScript
' Version: V5R18
' Reg. Settings: English (United States)
' ****************************************************************************
Public ActiveDoc As Document
Public Sheets
Public Sheet
Public Views
Public View
Public Texts As DrawingTexts
Public Text As DrawingText
Public Fact As Factory2D
Public Selection As Selection
Function CreateLine( iX1 As Double, iY1 As Double, iX2 As Double, iY2 As Double,
iName As String) As Curve2D
'-------------------------------------------------------------------------------
' Creates a sketcher lines thanks to the current 2D factory set to the global
variable Fact
' The created line is reneamed to the given iName
' Start point and End point are created and renamed iName&"_start", iName&"_end"
'-------------------------------------------------------------------------------
Set CreateLine = Fact.CreateLine( iX1, iY1, iX2, iY2)
CreateLine.Name = iName
Set point=CreateLine.StartPoint 'Create the start point
point.Name = iName&"_start"
Set point=CreateLine.EndPoint 'Create the start point
point.Name = iName&"_end"
End Function
Sub CATMain()
If Not CATInit(targetSheet) Then Exit Sub
On Error Resume Next
name = Texts.GetItem("Reference_" + GetMacroID()).Name
If Err.Number <> 0 Then
Err.Clear
name = "none"
End If
On Error Goto 0
If (name = "none") Then
CATDrw_Creation
Else
CATDrw_Resizing
CATDrw_Update
End If
CATExit
End Sub
End If
CATExit targetSheet
End Sub
End Sub
Function GetContext()
' Find execution context
Select Case TypeName( Sheet )
Case "DrawingSheet"
Select Case TypeName( ActiveDoc )
Case "DrawingDocument": GetContext="DRW"
Case "ProductDocument": GetContext="SCH"
Case Else: GetContext="Unexpected"
End Select
CATColorGeometry
CATExit targetSheet
End Sub
If GetContext()="Unexpected" Then
Msg = "The macro runs in an inappropriate environment."&chr(13)&"The script
will terminate wihtout finishing the current action."
Title ="Unexpected environement error"
MsgBox Msg,16, Title
CATInit=FALSE 'Exit with error
Exit Function
End If
Selection.Clear
CATIA.HSOSynchronized=False
View.SaveEdition
End Sub
Sub CATCreateReference()
'-------------------------------------------------------------------------------
'How to create a reference text
'-------------------------------------------------------------------------------
Set Text = Texts.Add("", GetWidth() - GetOffset(), GetOffset())
Text.Name = "Reference_" + GetMacroID
End Sub
If Mode = 1 Then
CATCheckRef = 0
Else
MsgBox "No Frame and Titleblock!"
CATCheckRef = 1
End If
End Function
Sub CATFrame()
'-------------------------------------------------------------------------------
'How to create the Frame
'-------------------------------------------------------------------------------
Dim Cst_1 As Double 'Length (in cm) between 2 horinzontal marks
Dim Cst_2 As Double 'Length (in cm) between 2 vertical marks
Dim Nb_CM_H As Integer 'Number/2 of horizontal centring marks
Dim Nb_CM_V As Integer 'Number/2 of vertical centring marks
Dim Ruler As Integer 'Ruler length (in cm)
Sub CATFrameBorder()
'-------------------------------------------------------------------------------
'How to draw the frame border
'-------------------------------------------------------------------------------
On Error Resume Next
CreateLine GetOV(), GetOV() , GetOH(), GetOV() ,
"Frame_Border_Bottom"
CreateLine GetOH(), GetOV() , GetOH(), GetHeight() -
GetOffset(), "Frame_Border_Left"
CreateLine GetOH(), GetHeight() - GetOffset(), GetOV(), GetHeight() -
GetOffset(), "Frame_Border_Top"
CreateLine GetOV(), GetHeight() - GetOffset(), GetOV(),
GetOV() , "Frame_Border_Right"
If Err.Number <> 0 Then Err.Clear
On Error Goto 0
End Sub
For i = 1 To Nb_CM_V
If (i * Cst_2 < .5 * GetHeight() - 1.) Then
y= .5 * GetHeight() + i * Cst_2
CreateLine GetOV(), y, .25 * GetOffset(), y,
"Frame_CentringMark_Left_"&Int(y)
CreateLine GetOH(), y, GetWidth() - .25 * GetOffset(), y,
"Frame_CentringMark_Right_"&Int(y)
y= .5 * GetHeight() - i * Cst_2
CreateLine GetOV(), y, .25 * GetOffset(), y,
"Frame_CentringMark_Left_"&Int(y)
CreateLine GetOH(), y, GetWidth() - .25 * GetOffset(), y,
"Frame_CentringMark_Right_"&Int(y)
End If
Next
If Err.Number <> 0 Then Err.Clear
On Error Goto 0
End Sub
For i = 1 To Nb_CM_H
t=Chr(65 + Nb_CM_H - i)
CreateText(t,.5 * GetWidth() + (i - .5) * Cst_1,GetHeight() - .5 *
GetOffset(),"Frame_Text_Top_1_"&t).Angle=-90
t=Chr(64 + Nb_CM_H + i)
CreateText(t,.5 * GetWidth() - (i - .5) * Cst_1,GetHeight() - .5 *
GetOffset(),"Frame_Text_Top_2_"&t).Angle=-90
Next
For i = 1 To Nb_CM_V
t=CStr(Nb_CM_V + i)
CreateText t ,GetWidth() - .5 * GetOffset(),.5 * GetHeight() + (i - .5) *
Cst_2,"Frame_Text_Right_1_"&t
CreateText(t ,.5 * GetOffset() ,.5 * GetHeight() + (i - .5) *
Cst_2,"Frame_Text_Left_1_"&t).Angle=-90
t=CStr(Nb_CM_V - i + 1)
CreateText t ,GetWidth() - .5 * GetOffset(),.5 * GetHeight() - (i - .5) *
Cst_2,"Frame_Text_Right_1_"&t
CreateText(t ,.5 * GetOffset() ,.5 * GetHeight() - (i - .5) *
Cst_2,"Frame_Text_Left_2"&t).Angle=-90
Next
If Err.Number <> 0 Then Err.Clear
On Error Goto 0
End Sub
For i = 1 To Ruler/100
CreateLine .5 * GetWidth() - 50 * i, GetOV(), .5 * GetWidth() - 50 * i, .5
* GetOffset() , "Frame_Ruler_1_"&i
CreateLine .5 * GetWidth() + 50 * i, GetOV(), .5 * GetWidth() + 50 * i, .5
* GetOffset() , "Frame_Ruler_2_"&i
For j = 1 To 4
CreateLine .5 * GetWidth() - 50 * i + 10 * j, GetOV(), .5 * GetWidth() -
50 * i + 10 * j, .75 * GetOffset(), "Frame_Ruler_3"&i&"_"&j
CreateLine .5 * GetWidth() + 50 * i - 10 * j, GetOV(), .5 * GetWidth() +
50 * i - 10 * j, .75 * GetOffset(), "Frame_Ruler_4"&i&"_"&j
Next
Next
End Sub
Sub CATCreateTitleBlockStandard()
'-------------------------------------------------------------------------------
'How to create the standard representation
'-------------------------------------------------------------------------------
Dim R1 As Double
Dim R2 As Double
Dim X(5) As Double
Dim Y(7) As Double
R1 = 2.
R2 = 4.
X(1) = GetOH() + Col(2) + 2.
X(2) = X(1) + 1.5
X(3) = X(1) + 9.5
X(4) = X(1) + 15.5
X(5) = X(1) + 21.
Y(1) = GetOV() + (Row(2)+Row(3))/2.
Y(2) = Y(1) + R1
Y(3) = Y(1) + R2
Y(4) = Y(1) + 5.5
Y(5) = Y(1) - R1
Y(6) = Y(1) - R2
Y(7) = 2*Y(1) - Y(4)
Sub CATTitleBlockText()
'-------------------------------------------------------------------------------
'How to fill in the title block
'-------------------------------------------------------------------------------
CATLinks
End Sub
Sub CATDeleteRevisionBlockFrame
DeleteAll "CATDrwSearch.2DGeometry.Name=RevisionBlock_Line_*"
End Sub
Sub CATCreateRevisionBlockFrame
'-------------------------------------------------------------------------------
'How to draw the revision block geometry
'-------------------------------------------------------------------------------
revision = CATCheckRev()
If revision=0 Then Exit Sub
For ii=0 To revision
iX = GetOH()
iY1 = GetHeight() - GetOV() - GetRevRowHeight()*ii
iY2 = GetHeight() - GetOV() - GetRevRowHeight()*(ii+1)
CreateLine iX + GetColRev(1), iY1, iX + GetColRev(1), iY2,
"RevisionBlock_Line_Column_" + GetRevLetter(ii) + "_1"
CreateLine iX + GetColRev(2), iY1, iX + GetColRev(2), iY2,
"RevisionBlock_Line_Column_" + GetRevLetter(ii) + "_2"
CreateLine iX + GetColRev(3), iY1, iX + GetColRev(3), iY2,
"RevisionBlock_Line_Column_" + GetRevLetter(ii) + "_3"
CreateLine iX + GetColRev(4), iY1, iX + GetColRev(4), iY2,
"RevisionBlock_Line_Column_" + GetRevLetter(ii) + "_4"
CreateLine iX + GetColRev(1), iY2, iX , iY2,
"RevisionBlock_Line_Row_" + GetRevLetter(ii)
Next
End Sub
Sub CATAddRevisionBlockText
'-------------------------------------------------------------------------------
'How to fill in the revision block
'-------------------------------------------------------------------------------
revision = CATCheckRev()+1
X = GetOH()
Y = GetHeight() - GetOV() - GetRevRowHeight()*(revision-.5)
Init = InputBox("This review has been done by:", "Reviewer's name", "XXX")
Description = InputBox("Comment to be inserted:", "Description", "None")
If revision = 1 Then
CreateTextAF "REV" ,X + GetColRev(1) + 1.,Y ,"RevisionBlock_Text_Rev"
,catMiddleLeft,5
CreateTextAF "DATE" ,X + GetColRev(2) + 1.,Y ,"RevisionBlock_Text_Date"
,catMiddleLeft,5
CreateTextAF "DESCRIPTION",X + GetColRev(3) +
1.,Y ,"RevisionBlock_Text_Description" ,catMiddleLeft,5
CreateTextAF "INIT" ,X + GetColRev(4) + 1.,Y ,"RevisionBlock_Text_Init"
,catMiddleLeft,5
End If
Sub CATRemoveFrame()
'-------------------------------------------------------------------------------
'How to remove the whole frame
'-------------------------------------------------------------------------------
DeleteAll "CATDrwSearch.DrwText.Name=Frame_Text_*"
DeleteAll "CATDrwSearch.2DGeometry.Name=Frame_*"
DeleteAll "CATDrwSearch.2DPoint.Name=TitleBlock_Line_*"
End Sub
Sub CATDeleteTitleBlockStandard()
'-------------------------------------------------------------------------------
'How to remove the standard representation
'-------------------------------------------------------------------------------
DeleteAll "CATDrwSearch.2DGeometry.Name=TitleBlock_Standard*"
End Sub
Sub CATLinks()
'-------------------------------------------------------------------------------
'How to fill in texts with data of the part/product linked with current sheet
'-------------------------------------------------------------------------------
On Error Resume Next
Dim ViewDocument
'-------------------------------------------------------------------------------
'Display sheet format
'-------------------------------------------------------------------------------
Dim textFormat As DrawingText
Set textFormat = Texts.GetItem("TitleBlock_Text_Size_1")
textFormat.Text = GetDisplayFormat()
If Len(GetDisplayFormat()) > 4 Then
textFormat.SetFontSize 0, 0, 3.5
Else
textFormat.SetFontSize 0, 0, 5.
End If
'-------------------------------------------------------------------------------
'Display sheet numbering
'-------------------------------------------------------------------------------
Dim nbSheet As Integer
Dim curSheet As Integer
If Not DrwSheet.IsDetail Then
For Each itSheet In Sheets
If Not itSheet.IsDetail Then nbSheet = nbSheet + 1
Next
For Each itSheet In Sheets
If Not itSheet.IsDetail Then
curSheet = curSheet + 1
itSheet.Views.Item(2).Texts.GetItem("TitleBlock_Text_Sheet_1").Text =
CStr(curSheet) & "/" & CStr(nbSheet)
End If
Next
End If
On Error Goto 0
End Sub
Person = TextToFill_1.Text
If Person = "XXX" Then Person = "John Smith"
Person = InputBox("This Document has been " + string3 + " by:", "Controller's
name", Person)
If Person = "" Then Person = "XXX"
TextToFill_1.Text = Person
TextToFill_2.Text = ""&Date
End Sub
Sub CATColorGeometry()
'-------------------------------------------------------------------------------
'How to color all geometric elements of the active view
'-------------------------------------------------------------------------------
End Select
End Sub