home *** CD-ROM | disk | FTP | other *** search
/ Corel Draw 6 / corel-draw-6-cd1.iso / draw / select.csc < prev    next >
Text File  |  1995-08-18  |  6KB  |  195 lines

  1. REM Selects all the Objects of a color. It then applies a fill
  2. REM Select.csc July 20, 1995
  3.  
  4. REM This is set up for RGB color mode. All the objects must be drawn in RGB for this to work.
  5.  
  6. REM This script is very complicated. It can easily be changed by modifying the SearchAndReplace
  7. REM Subroutine. By carefully editing it, you can change this script to search for objects with
  8. REM certain properties, and alter the properties of these objects.
  9.  
  10. REM For advanced script programmers, the SearchAll subroutine uses recursion to cycle through 
  11. REM all the objects in the drawing. You have to use recursion in order to search inside of groups.
  12. REM Without this the script will endless loop. Therefore, the SearchAll subroutine can be copied
  13. REM into any script that you want to loop through all of the objects in a drawing.
  14.  
  15. DECLARE SUB SearchAll(ID&, StartID&)
  16. DECLARE SUB SearchAndReplace()
  17.  
  18. GLOBAL CONST ColorType = 5        'RGB
  19. GLOBAL RedVal%        'These all have to be global so that the SearchAndReplace function can access them
  20. GLOBAL GreenVal%    'making them global is easier than passing all of them to the function
  21. GLOBAL BlueVal%    'but can cause problems if the values are changed. In this case, they are not changed.
  22. GLOBAL RedTol%
  23. GLOBAL GreenTol%
  24. GLOBAL BlueTol%
  25. GLOBAL RedIgnore%
  26. GLOBAL GreenIgnore%
  27. GLOBAL BlueIgnore%
  28. GLOBAL RedFill%
  29. GLOBAL GreenFill%
  30. GLOBAL BlueFill%
  31.  
  32. BEGIN DIALOG Dialog1 314, 150, "Select Objects of RGB Value:"
  33.     TEXT  10, 30, 50, 8, "Red Value"
  34.         SPINCONTROL  70, 30, 50, 12, RedVal%
  35.     TEXT  10, 52, 50, 8, "Green Value"
  36.         SPINCONTROL  70, 52, 50, 13, GreenVal%
  37.     TEXT  10, 76, 50, 8, "Blue Value"
  38.         SPINCONTROL  70, 76, 50, 13, BlueVal%
  39.     TEXT  126, 30, 50, 8, "Tolerance +/-"
  40.         SPINCONTROL  180, 30, 50, 13, RedTol%
  41.     TEXT  126, 53, 50, 8, "Tolerance +/-"
  42.         SPINCONTROL  180, 53, 50, 12, GreenTol%
  43.     TEXT  126, 76, 50, 8, "Tolerance +/-"
  44.         SPINCONTROL  180, 76, 50, 13, BlueTol%
  45.     CHECKBOX  240, 30, 36, 10, "Ignore", RedIgnore%
  46.     CHECKBOX  240, 52, 40, 10, "Ignore", GreenIgnore%
  47.     CHECKBOX  240, 76, 38, 10, "Ignore", BlueIgnore%
  48.     OKBUTTON  56, 107, 65, 17
  49.     CANCELBUTTON  186, 107, 70, 17
  50. END DIALOG
  51.  
  52. REM Set Defaults
  53. NumObjectsInDrawing = 20
  54. RedVal = 255
  55. GreenVal = 255
  56. BlueVal = 255
  57. RedTol = 10
  58. BlueTol = 10
  59. GreenTol = 10
  60. RedIgnore = 0
  61. GreenIgnore = 0
  62. BlueIgnore = 0
  63.  
  64. RETRY:
  65. ret = DIALOG(dialog1)
  66. IF CANCEL THEN STOP
  67.  
  68. REM Check Values
  69.  
  70.     IF RedVal > 255 OR RedVal < 0 THEN
  71.         BEEP
  72.         MESSAGE "RED VALUE IS INVALID"
  73.         RedVal = 255
  74.         GOTO RETRY
  75.     END IF
  76.     IF GreenVal > 255 OR GreenVal < 0 THEN
  77.         BEEP
  78.         MESSAGE "GREEN VALUE IS INVALID"
  79.         GreenVal = 255
  80.         GOTO RETRY
  81.     END IF
  82.     IF BlueVal > 255 OR BlueVal < 0 THEN
  83.         BEEP
  84.         MESSAGE "BLUE VALUE IS INVALID"
  85.         BlueVal = 255
  86.         GOTO RETRY
  87.     END IF
  88.     IF RedTol > 255 OR RedTol < 0 THEN
  89.         BEEP
  90.         MESSAGE "RED TOLERANCE IS INVALID"
  91.         RedTol = 255
  92.         GOTO RETRY
  93.     END IF
  94.     IF GreenTol > 255 OR GreenTol < 0 THEN
  95.         BEEP
  96.         MESSAGE "GREEN TOLERANCE IS INVALID"
  97.         GreenTol = 255
  98.         GOTO RETRY
  99.     END IF
  100.     IF BlueTol > 255 OR BlueTol < 0 THEN
  101.         BEEP
  102.         MESSAGE "BLUE TOLERANCE IS INVALID"
  103.         BlueTol = 255
  104.         GOTO RETRY
  105.     END IF
  106.  
  107. REM Get the fill color
  108. BEGIN DIALOG FillColorDialog 140, 150, "RGB Fill color to replace with:"
  109.     TEXT  10, 30, 50, 8, "Red Value"
  110.     SPINCONTROL  70, 30, 50, 12, RedFill%
  111.     TEXT  10, 52, 50, 8, "Green Value"
  112.     SPINCONTROL  70, 52, 50, 13, GreenFill%
  113.     TEXT  10, 76, 50, 8, "Blue Value"
  114.     SPINCONTROL  70, 76, 50, 13, BlueFill%
  115.     OKBUTTON  13, 107, 51, 17
  116.     TEXT  6, 7, 121, 18, "Please select RGB values for the fill color"
  117.     PUSHBUTTON  72, 107, 51, 17, "&None"
  118. END DIALOG
  119. ret = DIALOG(FillColorDialog)
  120. IF ret = 3 THEN STOP            'If None chosen
  121.     IF RedFill > 255 OR RedFill < 0 THEN
  122.         BEEP
  123.         MESSAGE "RED VALUE IS INVALID"
  124.         RedFill = 255
  125.         GOTO RETRY
  126.     END IF
  127.     IF GreenFill > 255 OR GreenFill < 0 THEN
  128.         BEEP
  129.         MESSAGE "GREEN VALUE IS INVALID"
  130.         GreenFill = 255
  131.         GOTO RETRY
  132.     END IF
  133.     IF BlueFill > 255 OR BlueFill < 0 THEN
  134.         BEEP
  135.         MESSAGE "BLUE VALUE IS INVALID"
  136.         BlueFill = 255
  137.         GOTO RETRY
  138.     END IF
  139.  
  140. WITHOBJECT DRAW
  141.     ret = true
  142.     .UnSelectAll
  143.     .SelectNextObject 0
  144.     ID1& = .GetObjectsCDRStaticID()
  145.     CALL SearchAll(ID1&, 0)
  146.     .UnSelectAll
  147.     
  148. END WITHOBJECT
  149.  
  150. SUB SearchAll(ID, StartID)
  151. LocalID = ID
  152. LocalStart = StartID
  153. WITHOBJECT DRAW
  154.  
  155.     DIM Booltest as boolean            'Boolean set to false when its back to the first object
  156.     Booltest = TRUE
  157.     
  158.     REM For Each Object
  159.         DO WHILE Booltest
  160.             IF .GetObjectType() = 12 THEN         'Grouped objects cause problems.
  161.                 GroupID& = .GetObjectsCDRStaticID()
  162.                 .SelectNextObject -1
  163.                 IDNext& = .GetObjectsCDRStaticID()
  164.                 CALL SearchAll (IDNext, GroupID)                'must call function recursively if a group encountered
  165.                 .SelectNextObject 0                'Select Next object in next group
  166.             END IF
  167.             CALL SearchAndReplace        'SearchAndReplace is called for each object.
  168.                                     'Edit it if you want to change the functionality of the script
  169.             .SelectNextObject 0
  170.             IF .GetObjectsCDRStaticID() = LocalID THEN Booltest = False
  171.         LOOP
  172.     .SelectObjectOfCDRStaticID LocalStart
  173.     
  174. END WITHOBJECT
  175. END SUB
  176.  
  177. SUB SearchAndReplace
  178. WITHOBJECT DRAW
  179.     .GetUniformFillColor t&, Color1&, Color2&, Color3&, Color4&     'returns the color and type of the object
  180. REM Booleans FOR each color type
  181. REM Within tolerance OR ignored.
  182.     IF t = ColorType THEN                'check color type
  183.         RedTest = (ABS(Color1 - RedVal) <= RedTol) OR (RedIgnore = 1)
  184.         GreenTest = (ABS(Color2 - GreenVal) <= GreenTol) OR (GreenIgnore = 1)
  185.         BlueTest = (ABS(Color3 - BlueVal) <= BlueTol) OR (BlueIgnore = 1)
  186.         IF RedTest AND GreenTest AND BlueTest THEN                'If object is the right color
  187.             .ApplyUniformFillColor 5, RedFill%, GreenFill%, BlueFill%, 0
  188.         END IF
  189.     ELSE                'If object is wrong type
  190.         Message "Non RGB Object found and Ignored"
  191.     END IF
  192.  
  193. END WITHOBJECT
  194. END SUB
  195.