I'm trying to write a macro and it's driving me nuts.
I have a specific shape that I need to place two dots or ellipses on at specific points. When I have my shape aligned to the bottom center of my page the macro works fine but if the shape is anywhere else and often this is the case, the dots won't place right.
I need two black dots both to be .125" x .125", filled black, no outline
dots are centered horizontally and placed vertically as shown. my code at the bottom
Sub SwiftCreekHoles()Dim sr As ShapeRange, srGroup As New ShapeRange, srGroup2 As New ShapeRange Dim x As Double, y As Double, w As Double, h As Double Set sr = ActiveSelectionRange If sr.Count = 0 Then Exit Sub ActiveDocument.BeginCommandGroup "SwiftCreekHoles" sr.GetBoundingBox x, y, w, h srGroup.Add ActiveLayer.CreateEllipse(x, y, 0.125, 0.125) 'top hole srGroup.Move x + w / 2 - 0.0625, y + h - 3.0625 ActiveSelection.Fill.UniformColor.CMYKAssign 45, 45, 45, 100 srGroup2.Add ActiveLayer.CreateEllipse(x, y, 0.125, 0.125) 'bottom hole srGroup2.Move w / 2 - 0.0625, 3.7875 ActiveSelection.Fill.UniformColor.CMYKAssign 45, 45, 45, 100End Sub
Myron,
I suspect that you want to use CreateEllipse2, not CreateEllipse.
I'm sure this isn't the slickest, but I think it works:
Sub foo() Dim sr As ShapeRange Dim s1 As Shape Dim s2 As Shape Set sr = ActiveSelectionRange If sr.Count = 0 Then Exit Sub For Each s1 In sr Set s2 = ActiveLayer.CreateEllipse2(s1.CenterX, s1.BottomY + 3.85, 0.125, 0.125) s2.Fill.UniformColor.CMYKAssign 45, 45, 45, 100 Set s2 = ActiveLayer.CreateEllipse2(s1.CenterX, s1.BottomY + 9, 0.125, 0.125) s2.Fill.UniformColor.CMYKAssign 45, 45, 45, 100 Next s1End Sub
One additional tip:
Go to Tools/Options/Editor and check 'Auto Quick Info'.Then if you enter a command like Set Sh1 = ActiveLayer.CreateEllipse you get - after entering the opening bracket a list with all needed and optional parameters. In this case Left As Double, Top As Double, Right As Double, Bottom As Double, StartAngel as Double=90, EndAngel as Double=90, [Pie as Boolean = False]. With this option you see the aim of the value you enter right now. This helps really, if you are using functions you are not really familiar with.
If you also switch on Tools/Options/Editor and check 'Auto List Members' and write a dot after e.g. ActiveDocument, then you get a list with all Properties and Methods available for this kind of object. If you enter e.g. behind ActiveDocument.Unit the equal sign = the you also get a list with all enumerated values available for this property.This features helps really if you are working with methods and properties you are not really familiar with.
CreateEllipse2 needs only 3 parameters CenterX, CenterY and Radius1, If Radius2 is omitted, Radius1 is used and you get a circle. Radius2 should be used to force an ellipse.
NudeFan said:CreateEllipse2 needs only 3 parameters CenterX, CenterY and Radius1, If Radius2 is omitted, Radius1 is used and you get a circle. Radius2 should be used to force an ellipse.
Good tip; thanks!
I wasn't familiar with ellipse creation, and started with what Myron was already working with. I could see that it needed to be changed to CreateEllipse2 to use the coordinates he was using, but I didn't notice that Radius2 was an optional parameter.
Good tips, too, on using 'Auto Quick Info' and 'Auto List Members'. I depend heavily on those. I just didn't look closely enough this time.