Code:
MACRO_NAME = "ToleranceDRW"
MACRO_VERS = "V1.0"'VER: 1.0
'DESC: CREATE ADDS TOLERANCE TO SELECTED DIMENSIONS DEPENDING ON VALUE.
'PREP: ACTIVE DOCUMENT MUST BE OF TYPE CATDRAWING
'LANG: CATSCRIPT
'DATE: 19/12/12
'CREA: DasDon
'-------------------------------------------
'----------------------------------------
'DECLARE VARIABLE
'--------------------
'CONSTANT VARIABLES
'--------------------
'GENERAL VARIABLES
DIM oSel As Selection
'--------------------
'ARRAYS
DIM InputObj(0)
InputObj(0) = "DrawingDimension"
'----------------------------------------
'----------------------------------------
SUB CATMain()
'--------------------
'CHECK IF DOCUMENT OPENED IS CORRECT FORMAT
IF CATIA.Documents.Count = 0 THEN
MSGBOX "no documents are opened in CATIA!" & CHR(10) & "please open a document",16,"DOCUMENT ERROR"
EXIT SUB
END IF
IF TYPENAME(CATIA.ActiveDocument) <> "DrawingDocument" THEN
MSGBOX "the active document must be of type Drawing Document!" & CHR(10) & "please open correct document type",16,"DOCUMENT ERROR"
EXIT SUB
END IF
'--------------------
'SET STANDARD VARIABLES
CATInit
'--------------------
'SELECTION OF DIMENSIONS AND CALL TOLERANCE SUB
STATUS = oSel.SelectElement3(InputObj,"select dimensions...",true,CATMultiSelTriggWhenUserValidatesSelection ,false)
IF oSel.Count <1 THEN Exit Sub
FOR n = 1 TO oSel.Count
TolaranceDimension oSel.Item(n).Value
NEXT
'--------------------
'--------------------
'macro finished
END_MESSAGE
END SUB
'----------------------------------------
'----------------------------------------
SUB CATInit()
SET oSel = CATIA.ActiveDocument.Selection
END SUB
'----------------------------------------
'----------------------------------------
SUB TolaranceDimension (byVal DimObj)
DIM dimValueObj As DrawingDimValue
DIM dimValue As Integer
DIM plusValue As Double
Dim minusValue As Double
SET dimValueobj = DimObj.GetValue
dimValue = dimValueobj.Value
IF dimValue > 0.0 AND dimValue < 10.0 THEN
plusValue = 0.2
minusValue = -0.2
ELSEIF dimValue > 10.0 AND dimValue < 20.0 THEN
plusValue = 0.3
minusValue = -0.3
ELSEIF dimValue > 20.0 AND dimValue < 30.0 THEN
plusValue = 0.4
minusValue = -0.4
END IF
DimObj.SetTolerances 1,"TOL_0.7", "" , "" , plusValue, minusValue, 0
End
'----------------------------------------
'----------------------------------------
SUB END_MESSAGE()
MSGBOX MACRO_NAME & " " & MACRO_VERS & " finished." _
& vbLF & "Please check results" & vbLF & _
"-----------------------------------" & vbLF & _
"-----------------------------------" & vbLF & _
"macro written by:" & vbLF & _
"DasDon" , vbyes, MACRO_NAME & " " & MACRO_VERS
END SUB
'----------------------------------------