-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathUtilities.bas
More file actions
553 lines (489 loc) · 14.8 KB
/
Utilities.bas
File metadata and controls
553 lines (489 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
Attribute VB_Name = "Utilities"
Sub ClearTransparency()
Dim sr As ShapeRange
Dim s As Shape
Dim i As Integer
Set sr = ActiveSelection.Shapes.All
Application.Optimization = True
For i = 1 To sr.Count
If sr(i).Transparency.Type <> cdrNoTransparency Then
sr(i).Transparency.ApplyNoTransparency
End If
Next i
Application.Optimization = False
ActiveWindow.Refresh
Application.Refresh
End Sub
Sub ConvertToRGB300()
ActiveSelection.ConvertToBitmapEx cdrRGBColorImage, False, False, 300, cdrNormalAntiAliasing, True, True, 95
End Sub
Sub RepeatToAllShape()
Dim s As Shape
For Each s In ActiveSelection.Shapes.All
s.CreateSelection
ActiveDocument.Repeat
Next s
End Sub
Sub UnlockContentPowerClip()
Dim pwc As PowerClip
Dim s As Shape
For Each s In ActiveSelection.Shapes.All
Set pwc = Nothing
Set pwc = s.PowerClip
If Not pwc Is Nothing Then
s.PowerClip.ContentsLocked = False
End If
Next s
End Sub
Sub LockContentPowerClip()
Dim pwc As PowerClip
Dim s As Shape
For Each s In ActiveSelection.Shapes.All
Set pwc = Nothing
Set pwc = s.PowerClip
If Not pwc Is Nothing Then
s.PowerClip.ContentsLocked = True
End If
Next s
End Sub
Sub ExtractPowerClip()
Dim aPage As Page
Dim aDoc As Document
Dim s As Shape
Dim pwc As PowerClip
For Each aDoc In Application.Documents
aDoc.Activate
For Each aPage In aDoc.Pages
For Each s In aPage.SelectableShapes
Set pwc = Nothing
Set pwc = s.PowerClip
If Not pwc Is Nothing Then
s.CreateSelection
pwc.ExtractShapes
s.Delete
End If
Next s
Next aPage
Next aDoc
End Sub
Sub RenamePage()
Dim aPage As Page
Dim l As Layer
Dim label As String
Dim labelnew As String
For Each aPage In ActiveDocument.Pages
label = aPage.Name
labelnew = Replace(label, "/", "-")
aPage.Name = labelnew
Next aPage
End Sub
Sub OffLayerByName()
Dim doc As Document
Dim aPage As Page
Dim l As Layer
For Each doc In Application.Documents
doc.Activate
For Each aPage In doc.Pages
For Each l In aPage.AllLayers
If l.Name = "LAK" Then 'name
l.Visible = False
l.Printable = False
End If
Next l
Next aPage
Next doc
End Sub
Sub InsertPageNumber()
Dim aPage As Page
Dim sNumber As Shape
Dim x As Double
Dim y As Double
x = ActiveShape.PositionX
y = ActiveShape.PositionY
For Each aPage In ActiveDocument.Pages
aPage.Activate
Set sNumber = aPage.ActiveLayer.CreateArtisticText(x, y, aPage.Index, cdrLanguageNone, cdrCharSetMixed, "Arial", 9, cdrFalse, cdrFalse, cdrNoFontLine, cdrCenterAlignment)
Next aPage
End Sub
Sub SignCityName()
Application.Optimization = True
Dim doc As Document
Dim aPage As Page
Dim l As Layer
Dim s1 As Shape
Dim x As Double
Dim y As Double
For Each doc In Application.Documents
doc.Activate
doc.Unit = cdrMillimeter
Set aPage = doc.Pages.First
For Each l In aPage.AllLayers
' l.Activate
' l.Editable = True
' l.SelectableShapes.All.Group
' If l.Name = "Ñëîé 1" Then
' x = aPage.LeftX + 14
' y = aPage.CenterY
' Set s1 = l.CreateArtisticText(x, y, "Òîìñê", cdrLanguageNone, cdrCharSetMixed, "Arial", 9, cdrTrue, cdrFalse, cdrNoFontLine, cdrCenterAlignment)
' s1.Fill.UniformColor.CMYKAssign 0, 0, 0, 100
' s1.Outline.SetNoOutline
' s1.Rotate 90
' l.SelectableShapes.All.Group
' End If
If l.Name = "stamp" Then
l.SelectableShapes.All.FirstShape.Outline.SetNoOutline
l.SelectableShapes.All.FirstShape.Fill.ApplyNoFill
End If
If l.Name = "ËÀÊ" Then
l.SelectableShapes.All.FirstShape.Outline.SetNoOutline
l.SelectableShapes.All.FirstShape.Fill.ApplyNoFill
' l.Printable = False
End If
Next l
Next doc
Application.Optimization = False
ActiveWindow.Refresh
Application.Refresh
End Sub
Sub CloseAllDocWithSave()
Dim doc As Document
For Each doc In Application.Documents
doc.Save
doc.Close
Next doc
End Sub
Sub CloseAllDocWithSaveOptions()
Dim opt As New StructSaveAsOptions
opt.EmbedICCProfile = False
opt.EmbedVBAProject = False
opt.Filter = cdrCDR
opt.IncludeCMXData = False
opt.Overwrite = True
opt.Range = cdrAllPages
opt.ThumbnailSize = cdr10KColorThumbnail
opt.Version = cdrVersion17
Dim doc As Document
For Each doc In Application.Documents
doc.SaveAs doc.fullFileName, opt
doc.Close
Next doc
End Sub
Sub CloseAllDocWithoutSave()
Dim doc As Document
For Each doc In Application.Documents
doc.Dirty = False
doc.Close
Next doc
End Sub
Sub RenameFileAndSave()
Dim doc As Document
Dim oldName As String
Dim newName As String
Dim Path As String
Dim colorCount As String
Dim docPageSize As String
For Each doc In Application.Documents
doc.Activate
doc.Unit = cdrMillimeter
Path = doc.filePath
oldName = doc.fileName
oldName = Left(oldName, (Len(oldName) - 4))
'size -1 mm
docPageSize = doc.Pages.First.BoundingBox.width - 2 & "x" & doc.Pages.First.BoundingBox.height - 2
'color
If doc.Pages.Count > 1 Then
colorCount = "4+4"
Else
colorCount = "4+0"
End If
newName = Path & oldName & "_" & colorCount & "_" & docPageSize & ".cdr"
doc.SaveAs newName
Next doc
End Sub
Sub PlaceAllToPowerClipOnAllDoc()
Application.Optimization = True
Dim doc As Document
Dim aPage As Page
For Each doc In Application.Documents
doc.Activate
doc.Unit = cdrMillimeter
For Each aPage In doc.Pages
aPage.Activate
PlaceAllToPowerClip aPage
Next aPage
Next doc
Application.Optimization = False
ActiveWindow.Refresh
Application.Refresh
End Sub
Sub PageSize()
Application.Optimization = True
Dim doc As Document
Dim aPage As Page
For Each doc In Application.Documents
doc.Activate
doc.Unit = cdrMillimeter
For Each aPage In doc.Pages
aPage.Activate
aPage.SizeWidth = aPage.SizeWidth - 4
aPage.SizeHeight = aPage.SizeHeight - 4
' aPage.SizeWidth = 214
' aPage.SizeHeight = 102
Next aPage
Next doc
Application.Optimization = False
ActiveWindow.Refresh
Application.Refresh
End Sub
Sub PasteClipBoardOnAllDoc()
If Clipboard.Empty And Clipboard.Valid Then
MsgBox "There is no data in the Clipboard."
Exit Sub
End If
Application.Optimization = True
Dim doc As Document
Dim aPage As Page
Dim s As Shape
For Each doc In Application.Documents
doc.Activate
doc.Unit = cdrMillimeter
For Each aPage In doc.Pages 'paste on all page
aPage.Activate
Set s = aPage.ActiveLayer.Paste
' s.OrderToBack 'order
Next aPage
' Set aPage = doc.Pages(1) 'paste only this page
' aPage.Activate
' Set s = aPage.ActiveLayer.Paste
' s.OrderToBack 'order
Next doc
Application.Optimization = False
ActiveWindow.Refresh
Application.Refresh
End Sub
Sub PasteOnAllPages()
Dim p As Page
For Each p In ActiveDocument.Pages
p.Activate
p.ActiveLayer.Paste
Next p
End Sub
Sub PlaceAllToPowerClip(aPage As Page)
Dim aSel As ShapeRange
Dim shPowerClip As Shape
Dim sL As Integer
Dim sT As Integer
Dim sr As Integer
Dim sB As Integer
Dim aLayer As Layer
Dim guideL As Boolean
guideL = False
If aPage.GuidesLayer.Editable Then
guideL = True
aPage.GuidesLayer.Editable = False
aPage.GuidesLayer.Printable = False
End If
sL = aPage.BoundingBox.Left
sT = aPage.BoundingBox.Top
sr = aPage.BoundingBox.Right
sB = aPage.BoundingBox.Bottom
For Each aLayer In aPage.Layers
If aLayer.Editable Then
If aLayer.Shapes.All.Count > 0 Then
Set aSel = aLayer.Shapes.All
Set shPowerClip = aLayer.CreateRectangle(sL, sT, sr, sB)
shPowerClip.Outline.SetNoOutline
aSel.AddToPowerClip shPowerClip, cdrFalse
End If
End If
Next aLayer
aPage.GuidesLayer.Editable = guideL
End Sub
Sub GroupAllPages()
Dim p As Page
For Each p In ActiveDocument.Pages
p.Activate
If p.SelectableShapes.Count > 0 Then
p.SelectableShapes.All.Group
End If
Next p
End Sub
Sub UnGroupAllPages()
Dim p As Page
For Each p In ActiveDocument.Pages
p.Shapes.All.UngroupAll
Next p
End Sub
Sub UnGroupAllDoc()
Dim d As Document
Dim p As Page
For Each d In Documents
d.Activate
For Each p In d.Pages
p.Activate
p.Shapes.All.UngroupAll
Next p
Next d
End Sub
Sub ConvertToCurves()
Dim d As Document
Dim p As Page
For Each d In Documents
d.Activate
For Each p In d.Pages
p.Activate
p.Shapes.All.ConvertToCurves
Next p
Next d
End Sub
Sub MoveOnNewLayerOnAllPages()
Dim p As Page
Dim l As Layer
Dim l2 As Layer
Dim sr As ShapeRange
For Each p In ActiveDocument.Pages
p.Activate
Set l = p.CreateLayer("Layer1")
Set sr = p.SelectableShapes.All
sr.MoveToLayer l
sr.Group
For Each l2 In p.Layers
If l.Name <> l2.Name And l2.Index <> 0 Then
l2.Delete
End If
Next l2
Next p
End Sub
Sub MoveOnNewDocument()
Dim cDoc As Document
Dim newDoc As Document
Dim sr As ShapeRange
Set cDoc = ActiveDocument
Set newDoc = CreateDocument()
newDoc.InsertPages cDoc.Pages.Count - 1, False, 1
iPage = 1
For i = 1 To cDoc.Pages.Count
cDoc.Pages(i).Activate
cDoc.Pages(i).SelectableShapes.All.Copy
newDoc.Pages(i).Activate
newDoc.Pages(i).Name = cDoc.Pages(i).Name
newDoc.Pages(i).Orientation = cDoc.Pages(i).Orientation
newDoc.ActivePage.SetSize cDoc.ActivePage.SizeWidth, cDoc.ActivePage.SizeHeight
newDoc.Pages(i).ActiveLayer.Paste
Next i
End Sub
Sub TotalArea()
Dim s As Shape
Dim sum As Long
For Each s In ActiveSelection.Shapes
sum = sum + s.BoundingBox.height * s.BoundingBox.width
Next s
MsgBox sum
End Sub
Sub MainExportToPDF(doc As Document)
With doc.PDFSettings
.PublishRange = pdfWholeDocument
' .PageRange = "1"
.Author = ""
.Subject = ""
.Keywords = ""
.BitmapCompression = 1 ' CdrPDFVBA.pdfLZW
' .JPEGQualityFactor = 2
.TextAsCurves = True
' .EmbedFonts = True
' .EmbedBaseFonts = True
' .TrueTypeToType1 = True
' .SubsetFonts = True
' .SubsetPct = 80
.CompressText = True
.Encoding = 1 ' CdrPDFVBA.pdfBinary
.DownsampleColor = False
.DownsampleGray = False
.DownsampleMono = False
' .ColorResolution = 300
' .MonoResolution = 1200
' .GrayResolution = 300
.Hyperlinks = False
.Bookmarks = False
.Thumbnails = False
.Startup = 0 ' CdrPDFVBA.pdfPageOnly
.ComplexFillsAsBitmaps = False
.Overprints = False
.Halftones = False
.MaintainOPILinks = False
.FountainSteps = 256
.EPSAs = 0 ' CdrPDFVBA.pdfPostscript
.pdfVersion = 9 ' CdrPDFVBA.pdfVersion17_Acrobat9
.IncludeBleed = False
' .Bleed = 31750
.Linearize = False
.CropMarks = False
.RegistrationMarks = False
.DensitometerScales = False
.FileInformation = False
.ColorMode = pdfNative
' .UseColorProfile = True
' .ColorProfile = 1 ' CdrPDFVBA.pdfSeparationProfile
.EmbedFilename = ""
.EmbedFile = False
.JP2QualityFactor = 2
.TextExportMode = 0 ' CdrPDFVBA.pdfTextAsUnicode
.PrintPermissions = 0 ' CdrPDFVBA.pdfPrintPermissionNone
.EditPermissions = 0 ' CdrPDFVBA.pdfEditPermissionNone
.ContentCopyingAllowed = False
' .OpenPassword = ""
' .PermissionPassword = ""
.EncryptType = 3 ' CdrPDFVBA.pdfEncryptTypeAES256
.OutputSpotColorsAs = 0 ' CdrPDFVBA.pdfSpotAsSpot
' .OverprintBlackLimit = 95
End With
Dim fileName As String
Dim filePath As String
Dim fullFileName As String
fileName = doc.fileName
filePath = doc.filePath
fileName = Left(fileName, (Len(fileName) - 4))
fullFileName = filePath & fileName & ".pdf"
doc.PublishToPDF fullFileName
End Sub
Sub ExportAllToPDF()
Dim doc As Document
For Each doc In Documents
MainExportToPDF doc
Next doc
End Sub
Sub ConvertToGray(sr As ShapeRange)
Dim s As Shape
For Each s In sr
If s.Type = cdrGroupShape Then
ConvertToGray s.Shapes.All
End If
If s.Type = cdrBitmapShape Then
s.Bitmap.ConvertTo cdrGrayscaleImage
s.Bitmap.ApplyBitmapEffect "Automatically adjust color and contrast", "AutoEqualizeEffect "
s.Bitmap.ConvertTo cdrCMYKColorImage
End If
Next s
End Sub
Sub ConvertToGraySelectedShapes()
ConvertToGray ActiveSelection.Shapes.All
End Sub
Sub ConvertToCMYKProfile(sr As ShapeRange)
Dim s As Shape
For Each s In sr
If s.Type = cdrGroupShape Then
ConvertToCMYKProfile s.Shapes.All
End If
If s.Type = cdrBitmapShape Then
s.Bitmap.ConvertTo cdrLABImage
s.Bitmap.ConvertTo cdrCMYKColorImage
End If
Next s
End Sub
Sub ConvertToCMYKProfileAllPages()
Dim p As Page
For Each p In ActiveDocument.Pages
p.Activate
ConvertToCMYKProfile p.SelectableShapes.All
Next p
End Sub