home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Corel Draw 6
/
corel-draw-6-cd1.iso
/
draw
/
select.csc
< prev
next >
Wrap
Text File
|
1995-08-18
|
6KB
|
195 lines
REM Selects all the Objects of a color. It then applies a fill
REM Select.csc July 20, 1995
REM This is set up for RGB color mode. All the objects must be drawn in RGB for this to work.
REM This script is very complicated. It can easily be changed by modifying the SearchAndReplace
REM Subroutine. By carefully editing it, you can change this script to search for objects with
REM certain properties, and alter the properties of these objects.
REM For advanced script programmers, the SearchAll subroutine uses recursion to cycle through
REM all the objects in the drawing. You have to use recursion in order to search inside of groups.
REM Without this the script will endless loop. Therefore, the SearchAll subroutine can be copied
REM into any script that you want to loop through all of the objects in a drawing.
DECLARE SUB SearchAll(ID&, StartID&)
DECLARE SUB SearchAndReplace()
GLOBAL CONST ColorType = 5 'RGB
GLOBAL RedVal% 'These all have to be global so that the SearchAndReplace function can access them
GLOBAL GreenVal% 'making them global is easier than passing all of them to the function
GLOBAL BlueVal% 'but can cause problems if the values are changed. In this case, they are not changed.
GLOBAL RedTol%
GLOBAL GreenTol%
GLOBAL BlueTol%
GLOBAL RedIgnore%
GLOBAL GreenIgnore%
GLOBAL BlueIgnore%
GLOBAL RedFill%
GLOBAL GreenFill%
GLOBAL BlueFill%
BEGIN DIALOG Dialog1 314, 150, "Select Objects of RGB Value:"
TEXT 10, 30, 50, 8, "Red Value"
SPINCONTROL 70, 30, 50, 12, RedVal%
TEXT 10, 52, 50, 8, "Green Value"
SPINCONTROL 70, 52, 50, 13, GreenVal%
TEXT 10, 76, 50, 8, "Blue Value"
SPINCONTROL 70, 76, 50, 13, BlueVal%
TEXT 126, 30, 50, 8, "Tolerance +/-"
SPINCONTROL 180, 30, 50, 13, RedTol%
TEXT 126, 53, 50, 8, "Tolerance +/-"
SPINCONTROL 180, 53, 50, 12, GreenTol%
TEXT 126, 76, 50, 8, "Tolerance +/-"
SPINCONTROL 180, 76, 50, 13, BlueTol%
CHECKBOX 240, 30, 36, 10, "Ignore", RedIgnore%
CHECKBOX 240, 52, 40, 10, "Ignore", GreenIgnore%
CHECKBOX 240, 76, 38, 10, "Ignore", BlueIgnore%
OKBUTTON 56, 107, 65, 17
CANCELBUTTON 186, 107, 70, 17
END DIALOG
REM Set Defaults
NumObjectsInDrawing = 20
RedVal = 255
GreenVal = 255
BlueVal = 255
RedTol = 10
BlueTol = 10
GreenTol = 10
RedIgnore = 0
GreenIgnore = 0
BlueIgnore = 0
RETRY:
ret = DIALOG(dialog1)
IF CANCEL THEN STOP
REM Check Values
IF RedVal > 255 OR RedVal < 0 THEN
BEEP
MESSAGE "RED VALUE IS INVALID"
RedVal = 255
GOTO RETRY
END IF
IF GreenVal > 255 OR GreenVal < 0 THEN
BEEP
MESSAGE "GREEN VALUE IS INVALID"
GreenVal = 255
GOTO RETRY
END IF
IF BlueVal > 255 OR BlueVal < 0 THEN
BEEP
MESSAGE "BLUE VALUE IS INVALID"
BlueVal = 255
GOTO RETRY
END IF
IF RedTol > 255 OR RedTol < 0 THEN
BEEP
MESSAGE "RED TOLERANCE IS INVALID"
RedTol = 255
GOTO RETRY
END IF
IF GreenTol > 255 OR GreenTol < 0 THEN
BEEP
MESSAGE "GREEN TOLERANCE IS INVALID"
GreenTol = 255
GOTO RETRY
END IF
IF BlueTol > 255 OR BlueTol < 0 THEN
BEEP
MESSAGE "BLUE TOLERANCE IS INVALID"
BlueTol = 255
GOTO RETRY
END IF
REM Get the fill color
BEGIN DIALOG FillColorDialog 140, 150, "RGB Fill color to replace with:"
TEXT 10, 30, 50, 8, "Red Value"
SPINCONTROL 70, 30, 50, 12, RedFill%
TEXT 10, 52, 50, 8, "Green Value"
SPINCONTROL 70, 52, 50, 13, GreenFill%
TEXT 10, 76, 50, 8, "Blue Value"
SPINCONTROL 70, 76, 50, 13, BlueFill%
OKBUTTON 13, 107, 51, 17
TEXT 6, 7, 121, 18, "Please select RGB values for the fill color"
PUSHBUTTON 72, 107, 51, 17, "&None"
END DIALOG
ret = DIALOG(FillColorDialog)
IF ret = 3 THEN STOP 'If None chosen
IF RedFill > 255 OR RedFill < 0 THEN
BEEP
MESSAGE "RED VALUE IS INVALID"
RedFill = 255
GOTO RETRY
END IF
IF GreenFill > 255 OR GreenFill < 0 THEN
BEEP
MESSAGE "GREEN VALUE IS INVALID"
GreenFill = 255
GOTO RETRY
END IF
IF BlueFill > 255 OR BlueFill < 0 THEN
BEEP
MESSAGE "BLUE VALUE IS INVALID"
BlueFill = 255
GOTO RETRY
END IF
WITHOBJECT DRAW
ret = true
.UnSelectAll
.SelectNextObject 0
ID1& = .GetObjectsCDRStaticID()
CALL SearchAll(ID1&, 0)
.UnSelectAll
END WITHOBJECT
SUB SearchAll(ID, StartID)
LocalID = ID
LocalStart = StartID
WITHOBJECT DRAW
DIM Booltest as boolean 'Boolean set to false when its back to the first object
Booltest = TRUE
REM For Each Object
DO WHILE Booltest
IF .GetObjectType() = 12 THEN 'Grouped objects cause problems.
GroupID& = .GetObjectsCDRStaticID()
.SelectNextObject -1
IDNext& = .GetObjectsCDRStaticID()
CALL SearchAll (IDNext, GroupID) 'must call function recursively if a group encountered
.SelectNextObject 0 'Select Next object in next group
END IF
CALL SearchAndReplace 'SearchAndReplace is called for each object.
'Edit it if you want to change the functionality of the script
.SelectNextObject 0
IF .GetObjectsCDRStaticID() = LocalID THEN Booltest = False
LOOP
.SelectObjectOfCDRStaticID LocalStart
END WITHOBJECT
END SUB
SUB SearchAndReplace
WITHOBJECT DRAW
.GetUniformFillColor t&, Color1&, Color2&, Color3&, Color4& 'returns the color and type of the object
REM Booleans FOR each color type
REM Within tolerance OR ignored.
IF t = ColorType THEN 'check color type
RedTest = (ABS(Color1 - RedVal) <= RedTol) OR (RedIgnore = 1)
GreenTest = (ABS(Color2 - GreenVal) <= GreenTol) OR (GreenIgnore = 1)
BlueTest = (ABS(Color3 - BlueVal) <= BlueTol) OR (BlueIgnore = 1)
IF RedTest AND GreenTest AND BlueTest THEN 'If object is the right color
.ApplyUniformFillColor 5, RedFill%, GreenFill%, BlueFill%, 0
END IF
ELSE 'If object is wrong type
Message "Non RGB Object found and Ignored"
END IF
END WITHOBJECT
END SUB