OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Corel User Forums > CorelDRAW > Macros/Add-ons

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 20-01-2008, 18:45
jahmer
Guest
 
Posts: n/a
Default Trouble wtih shape names.

I struggling with accessing name of shapes.

1) Why is it that this code works for an ungrouped shape, but won't return me a name when the object is a group? (I am trying to save the name to use later rather retyping it on the regroup function, thus the global variable)
Code:
Public myLastUngroupName As String
Public Sub bUngroup()
    Dim saveshapename As String
    Dim grp1 As ShapeRange
    Dim OrigSelection As ShapeRange
    Set OrigSelection = ActiveSelectionRange
    
    saveshapename = OrigSelection(1).ObjectData("Name").Value
    myLastUngroupName = saveshapename
    MsgBox ">mylastungroup is " & myLastUngroupName & ">saveshapename is " & saveshapename
   
    Set grp1 = ActiveSelectionRange.UngroupEx
End Sub
2) why do I have to do this code to get the name of a selected item
Code:
    Dim newname         As String
    newname = ActiveSelectionRange(2).ObjectData("Name").Value
rather than
Code:
    Dim s      As Shape
    s.name = ActiveSelectionRange(2).name

3) Can you have multiple shape ranges and active selected ranges? I am trying to process each shape in an ActiveSelectionRange and then based on criteria (e.i. if their name is "engrave") add them to another shaperange for processing later (combine or contour). I have read alot in here about dropping the shapes in lists, but then how do I reselect them later? I am trying to treat Shaperanges as lists for use later, but am I just using it improperly?
Reply With Quote
  #2  
Old 20-01-2008, 19:08
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

1. because there is only 1 object, the group itself, but you can use a list of ungroupped shapes without ungroupping them actually:
Code:
dim SR as shaperange
set SR=ActiveSelection.Shapes.FindShapes()
2. .......WHAT's the value of s here? - s.name = ActiveSelectionRange(2).name - you have to assign s to some actual shape:
Code:
dim s as shape
set s=ActiveSelectionRange(3)
s.name=ActiveSelectionRange(2).name
Anyway this is looking very clumsy, what's the real goal?

3. no need to select anything in order to process shapes, just use shaperange objects.
Code:
dim SRengrave as shapeRange, SR2 as shaperange, SR3 as shapeRange
set SRengrave=ActiveSelection.Shapes.FindShapes("engrave")
set SR2=ActiveSelection.Shapes.FindShapes("Name2")
set SR3=new ShapeRange: SR3.AddRange SR2: SR3.Add SRengrave(1)
........
When you finished the processing you can use SR.CreateSelection to select new objects.
Reply With Quote
  #3  
Old 21-01-2008, 19:00
jahmer
Guest
 
Posts: n/a
Default Group Name

Thanks xos for the quick response.

The objectives of the macro:
For either a shape or a group:
combine anything with "lines" in the name (group only)
combine & contour everything else (body), copy original fill, delete original, rename shape putting "x-" in front of it
rename the group putting an "x-" in front of the existing name (group only)

Here is what I want:

For a Group
Before macro
Leaf (group)
lines-bottom (shape)
lines-top (shape)
leaf body (shape)
After macro
x-Leaf (group)

line (shape)
x-leaf body (result of contoured shape)
If object is just a shape, not a group then
Before
Leaf body (shape)
After
x-leaf body (result of contoured shape)[/indent]
Here is my code so far

Code:
Public Sub aCountour()
'   Hotkey alt J
'  1) make sure selection has only 1 object
'  2) rename shapes with the "line" somewhere in the name to "line" so we can find them later
'  3) set range srLine by finding "line" names, set srBody range so there are no lines in it
'  4) combine srLine items, combine srBody items
'  5) countour sBody and separate
'  6) fill contour with original color & delete original, rename to original name + "x-"
'  7) rename group with " x-" on the front
    
    Dim srSelect    As ShapeRange, srLine As ShapeRange, srBody As ShapeRange
    Dim sLine       As Shape, sBody As Shape, sSearch As Shape
    Dim eContour    As Effect
    Dim newname     As String
    Dim groupSelected As String
    
'  1) make sure selection has only 1 object
    Set srSelect = ActiveSelectionRange
    Set srBody = srSelect
   
    If srSelect.Count <> 1 Then
        MsgBox "!!!!! Select at 1 object only !!!!!!!!"
        Exit Sub
    End If
    If srSelect(1).Type = cdrGroupShape Then
         groupSelected = "Y"
    Else
         groupSelected = "N"
    endif
  
'  2) rename shapes with the "line" somewhere in the name to "line" so we can find them later
    If groupSelected = "Y" Then
        Optimization = True
        ActiveDocument.BeginCommandGroup
        For Each sSearch In srSelect
        If InStr(sSearch.Name, "line", vbTextCompare) Then
            sSearch.Name = "line"
        Next
        
        ActiveDocument.EndCommandGroup
        Optimization = False
        
        Refresh
        CorelScript.RedrawScreen
    
'  3) set range srLine by finding "line" names, set srBody range so there are no lines in it
        Set srLine = ActiveSelection.Shapes.FindShapes(Name:="line")
        srBody.RemoveRange srLine
       
'  4) combine srLine items, combine srBody items
        Set sLine = srLine.Combine
        Set sBody = srBody.Combine
    End If    'group selected

' 5) Contour  & separate                                                      Outline Color            Fill Color
'     ** TODO steamline fill color with sBody color
    Set eContour = sBody.CreateContour(cdrContourOutside, 0.002, 1, , CreateRGBColor(255, 0, 0), CreateRGBColor(0, 0, 10))
    eContour.Separate
    
' 6) fill contour with original color & delete original, rename to original name + "x-"
    eContour.Fill = sBody.Fill
    eContour.Name = "x-" & sBody.Name
    sBody.Delete

' 7) rename group if there is one
    If groupSelected = "Y" Then
        srSelect(1).Name = "x-" & srSelect(1).Name
    End If
   
End Sub
Here are my issues

2a) I can get this code working for a non grouped selection (thanks from the previous post , but not for a grouped item. I guess I could
Dim srTemp as Shaperange
srTemp = srSelect
srTemp.ungroupex since the original selection is in srSelect, but I don't know how to process otherwise, and I need that group name for regrouping (see 7)

Code:
   
        Optimization = True
        ActiveDocument.BeginCommandGroup
        For Each sSearch In srSelect
             If InStr(1, sSearch.Name, "line", vbTextCompare) Then
                  sSearch.Name = "line"
            End If
        Next sSearch
        ActiveDocument.EndCommandGroup
        Optimization = False
       Refresh
        CorelScript.RedrawScreen
2b) after running this, my object manager is hosed. I can't see new objects anymore. It created a [graphic1] document. Is that from a previous error I had when fixing the Instr? Somewhere it created a new document and positioned me there, but didn't refresh the screen with document I was working in. So when I thought I was adding objects, it was really doing it graphic1, which wasn't shown.

3)set ranges after inst in 2
Just for clarification, briefly explain why,
Code:
'this is the correct way
Set srLine = ActiveSelection.Shapes.FindShapes(Name:="line")

'incorrect way A
Set srLine = ActiveSelectionRange.FindShapes(Name:="line")

'incorrect way B
srSelect = ActiveSelectionRange
Set srLine = srSelect.FindShapes(Name:="line")

''incorrect way C but I don't know why?
Dim srTemp As ShapeRange
Set srTemp = ActiveSelection
Set srLine = srTemp.Shapes.FindShapes(Name:="line")
ActiveSelection not ActiveSelectionRange, and it can't be substituted (I'm guesing this is a classic rookie mistake).


5) & 6a) I can't see the distinction. What is the correct way?
this doesn't work
Code:
Set eContour = sBody.CreateContour(cdrContourOutside, 0.002, 1, , CreateRGBColor(255, 0, 0), CreateRGBColor(0, 0, 10))
eContour.Separate
    
' 6) fill contour with original color & delete original, rename to original name + "x-"
MsgBox "econtour type =" & eContour.Type
  
eContour.Fill = sBody.Fill
I get error message "the referenced object no longer exist in this document" on msgbox

but this does
Code:
    Set eContour = OrigSelection(1).CreateContour(cdrContourOutside, 0.002, 1, , CreateRGBColor(255, 0, 0), CreateRGBColor(0, 0, 10))
    
    eContour.Separate.AddToSelection

    newname = ActiveSelectionRange(2).ObjectData("Name").Value
    newname = "x-" & newname
    ActiveSelectionRange(1).ObjectData("Name").Value = newname
    
    ActiveSelectionRange(1).Fill = ActiveSelectionRange(2).Fill
Very cumbersome. I don't like that because it makes assumption about ActiveSelectionRange(1) & (2) which may not be true (an inside contour may change the index).
Help!

6b) This doesn't work for either a group or shape
Code:
eContour.Name = "x-" & sBody.Name

nor this code from another macro (but it works for a shape, not a group)
Code:
Dim s As Shape
    Set s = ActiveSelectionRange(1)
    MsgBox ">selection name is" & s.Name
or this for a group (again, from another macro)
Code:
  Dim newname         As String 
   newname = ActiveSelectionRange(2).ObjectData("Name").Value
    newname = "x-" & newname
    ActiveSelectionRange(1).ObjectData("Name").Value = newname
Isn't s.name data type a string? I have tried concatentating 2 string constants and the name is reassigned correctly, but when I add s.name in the concatenation it doesn't.

Which leads to the last code issue: Renaming a group
Code:
' 7) rename group if there is one
    If groupSelected = "Y" Then
        srSelect(1).Name = "x-" & srSelect(1).Name
    End If
I am also concerned that if I have to ungroup to srSelect to get the inst to work, then I have to regroup the selection and save the name before ungrouping. Either way, I have to change the group name.


cdrShapeType question.
7 is a group, 8 is selection. What would it be is a group is selected?

And finally. . . .
I have noticed that sometimes I need to use Set and sometimes I can get by without it. Is there a rule of thumb for its use? Something like properties don't need it, but methods do?

Thanks for any help you can give me.
Reply With Quote
  #4  
Old 21-01-2008, 19:34
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

Quote:
Originally Posted by jahmer View Post
2a) I can get this code working for a non grouped selection (thanks from the previous post , but not for a grouped item.
How about this: set srSelect = srSelect.ungroupex

Quote:
2b) after running this, my object manager is hosed.
Remove the Optimization=true and Optimization=false

Quote:
3)set ranges after inst in 2
Just for clarification, briefly explain why, ................ ActiveSelection not ActiveSelectionRange, and it can't be substituted (I'm guesing this is a classic rookie mistake).
ActiveSelection is a Shape object, which contains .Shapes property which in turn has .FindShapes method. In X3 it's possible to address this method this way as well: ActiveSelectionRange.Shapes.FindShapes

Quote:
5) & 6a) I can't see the distinction. What is the correct way?
You should copy the properties prior to deleting the original object, because Shape object in code only references the existing shape, it does not hold a copy of it inside the variable, so when you delete the shape from document the variable *points* to nowhere.

Quote:
6b) This doesn't work for either a group or shape
Probably you have to separate shapes first, then rename
Quote:
Which leads to the last code issue: Renaming a group................... I am also concerned that if I have to ungroup to srSelect to get the inst to work, then I have to regroup the selection and save the name before ungrouping. Either way, I have to change the group name.
yes, ungroupping loses the group's name

Quote:
cdrShapeType question. 7 is a group, 8 is selection. What would it be is a group is selected?
it'll be cdrGroupShape. 8 is a special value, and is reserved for a variable holding the Selection type object, there is no real object in document of such type.

Quote:
And finally. . . .
I have noticed that sometimes I need to use Set and sometimes I can get by without it. Is there a rule of thumb for its use? Something like properties don't need it, but methods do?
Everything of object type requires SET for your own variables declared or implicitly created in your code (in case you have no explicit DIM declarations). However object model allows omitting of SET in case you assign an object property of some object type from CorelDRAW object model, and other referenced (default are: CorelDRAW, MSForms, StdOle) libraries, for example .Layer is an object property of Shape object, so it's possible to shortcut: MyShape1.Layer = ActiveLayer
Reply With Quote
  #5  
Old 22-01-2008, 16:05
jahmer
Guest
 
Posts: n/a
Default Thanks ox

Once again thanks for the quick response.

Still don't understand this

this doesn't work for a group

Code:
dim oldGroupName as string
oldGroupName =  ActiveSelectionRange(1).ObjectData("Name").Value
this does work for a group
Code:
ActiveSelectionRange(1).ObjectData("Name").Value = "newname"
So I had to do this
Code:
If ActiveSelectionRange(1).Type = cdrGroupShape Then
dim s as shape
      For Each s In ActiveSelection.Shapes
          oldGroupName = s.Name
      Next s
endif

Also, my screen/object manager still gets hosed
I have turned optimize off in the troubled code and wrote this little macro to reset but it isn't working. What is the trick?
Code:
Public Sub redraw()
      Optimization = False
      refresh
      CorelScript.RedrawScreen
 MsgBox "Done redrawing "
End Sub
Its has been a few years since I have coded, but its coming back (slowly). I now am using locals window, stepping and immediate for debuggin, but still a bit frustrated.
Thanks again. Forums like this are are just incredible.
Reply With Quote
  #6  
Old 22-01-2008, 16:14
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

Quote:
Originally Posted by jahmer View Post
this doesn't work for a group
I can't understand why you are using ObjectData for fetching of names.
Should be just this: oldGroupName = ActiveSelectionRange(1).Name
Quote:
Also, my screen/object manager still gets hosed
Screenshot, please
Reply With Quote
  #7  
Old 23-01-2008, 08:49
jahmer
Guest
 
Posts: n/a
Default This doesn't work for a group, I have tried numerous times

The reason is that it doesn't work for a group. (but it is ok for a shape)

Code:
Public Sub oldgroupname()
Dim oldgroupname As String
oldgroupname = ActiveSelectionRange(1).Name
MsgBox "name " & oldgroupname
End Sub
Try it. It's not working for me.
Reply With Quote
  #8  
Old 23-01-2008, 08:54
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

it's working here, v12sp1 & X3sp2
Reply With Quote
  #9  
Old 23-01-2008, 09:53
jahmer
Guest
 
Posts: n/a
Default Group Name

I have upgraded to x3sp2. It works now for a group when a name has been changed from the original name "Group of n Objects", but doesn't work when you don't change the default name. I am guessing that the object doesn't really have a name, and "group of n objects" is put in object manager, but not in the shape definition.

I have burned 15 hours on that. Live and learn, thanks again.
Reply With Quote
  #10  
Old 23-01-2008, 10:12
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

yes, that's true
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Symbol shape is not found in a group squonk CorelDRAW/Corel DESIGNER VBA 1 14-06-2007 07:32
CorelDRAW X3 VBA Code - Shape & Color LIster JudyHNM Code Critique 2 05-04-2007 15:02
Any idea what's wrong with this shape? jemmyell CorelDRAW/Corel DESIGNER VBA 4 08-05-2006 19:15
Howto uniquely identify a shape in VBA code jemmyell CorelDRAW/Corel DESIGNER VBA 9 11-02-2005 22:05
activeselection cloning s_federici CorelDRAW/Corel DESIGNER VBA 2 05-11-2004 10:59


All times are GMT -5. The time now is 06:55.


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