OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   fill type (http://forum.oberonplace.com/showthread.php?t=417)

jwknight 04-03-2004 11:07

fill type
 
Hi,

I'm new to VBA and i'm struggling to find out the fill type of a curve i need to select.

I know that its a 2-color pattern fill but i don't know how to find which type of pattern it is.

If anybody could help i would be most grateful,

Many Thanks

Alex 04-03-2004 13:47

Re: fill type
 
You can inspect Canvas.Index property of the pattern fill. It returns you the index of the pattern in the pattern list. For example, the brick pattern is the pattern #4 in the list (by default). So you can use it to find all shapes that has the brick pattern:

Code:

Sub FindPatternFills()
    Dim s As Shape
    Dim sr As New ShapeRange
    Dim nCanvasIndex As Long
   
    nCanvasIndex = 4 ' Brick pattern
   
    For Each s In ActivePage.Shapes
        If s.Fill.Type = cdrPatternFill Then
            If s.Fill.Pattern.Type = cdrTwoColorPattern Then
                If s.Fill.Pattern.Canvas.Index = nCanvasIndex Then
                    sr.Add s
                End If
            End If
        End If
    Next s
   
    If sr.Count = 0 Then
        MsgBox "There are no object with brick pattern fill", vbCritical
    Else
        sr.CreateSelection
    End If
End Sub

Unfortunately this only works if the pattern applied to a shape is present in the current CorelDRAW's pattern list. If you create your own pattern, apply it to shape, save the file and give it to another user, he won't see the pattern in the list (even though the shape will still have the proper fill), and Canvas.Index will return 0.

In this case you can get to the Canvas.Data property of the pattern fill which returns the bitmap pattern as an encoded string. Depending on the pattern size and complexity, the string can be very simple (for small regular patterns) to huge (for large rather irregular ones). You can create the shape and apply the pattern to it, then get the string by using:

Code:

ActiveShape.Fill.Pattern.Canvas.Data
Store (hard code) the string in the code and compare each fill with your data string until you find your objects.

Here is the same code as above which looks for the brick pattern, but it actually looks for the actual pattern, rather then its entry number in the pattern list:

Code:

Sub FindPatternFills2()
    Dim s As Shape
    Dim sr As New ShapeRange
    Dim sCanvasData As String
   
    ' The brick pattern data string
    sCanvasData = "%%8A'#9Da 'Y%)(J'Y%()J'Y%)(J'Y%() '"
   
    For Each s In ActivePage.Shapes
        If s.Fill.Type = cdrPatternFill Then
            If s.Fill.Pattern.Type = cdrTwoColorPattern Then
                If s.Fill.Pattern.Canvas.Data = sCanvasData Then
                    sr.Add s
                End If
            End If
        End If
    Next s
   
    If sr.Count = 0 Then
        MsgBox "There are no object with brick pattern fill", vbCritical
    Else
        sr.CreateSelection
    End If
End Sub

I hope this helps.


All times are GMT -5. The time now is 08:49.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com