How can I RoundUp the rectangle to the nearest whole number? So when a rectangle that is an odd size i.e. 40.1"w x 12.135"h, it'll Round to 41 & 13.
________________________________
dLeeway = 0.5sr.Add ActiveLayer.CreateRectangle2(x - dLeeway, y - dLeeway, w + dLeeway * 2, h + dLeeway * 2)
Usually if you want to round up from x.5 you add 0.5 to the dimension. In this case add 0.999 to the dimension
dLeeway = 0.5
FinalWidth = int(w + dLeeway * 2 + 0.999)
FinalHeight = int(h + dLeeway * 2 + 0.999)sr.Add ActiveLayer.CreateRectangle2(x - dLeeway, y - dLeeway, FinalWidth, FinalHeight)
Rounds good but now the x & y are off.
Meaning it's what, not holding the center point?
Dim PrevRefPoint As cdrReferencePoint
Dim FinalWidth as int
Dim FinalHeight as int
PrevRefPoint = ActiveDocument.ReferencePoint
ActiveDocument.ReferencePoint = cdrCenter
ActiveDocument.ReferencePoint = PrevRefPoint
Unfortunately, there's a lot more to my macro and trying to figure out where to put the code is driving me nuts, in between designing signs, but perhaps it would be best to show the whole macro or even just a mockup of what the end result should be. Most of my code was copied from my other maros and kind of pieced together.
So far the x,y is still off no matter where I place it.
Myron said:but perhaps it would be best to show the whole macro or even just a mockup of what the end result should be
Describing what you want as an end result is a great place to start.
It can also help to describe what you are starting with.
It's easy to get tangled up in the "and this was how I was trying to get there" part!
I have a macro that's been working fine for years, just trying to both streamline it and make the Registration marks a minimal of .5" from the printed shapes
Here's a sample where I show how I might go about creating a rectangle around the shaperange, rounding up both the width and height, and adding "leeway" on each side.
I'm using ShapeRange.GetBoundingBox in part because it includes an option for including Outlines when calculating the size of the bounding box. I'm not using that here, so it's working off of "wireframe" dimensions, but change "False" to "True" in that line, and Outlines will be included in the calculation.
After creating the rectangle based on the bounding box, I use Shape.SetSizeEx to set the final width and height without moving the center.
For rounding the width and height, I'm using a function that I mentioned in an earlier post. In this example, I'm rounding up to the nearest 0.1".
Sub test_rectangle() Dim sRect As Shape Dim dblX As Double Dim dblY As Double Dim dblWidth As Double Dim dblHeight As Double Const dblLeeway As Double = 0.5 Const lngRoundingDecPl As Long = 1 ActiveSelectionRange.GetBoundingBox dblX, dblY, dblWidth, dblHeight, False Set sRect = ActiveLayer.CreateRectangle2(dblX, dblY, dblWidth, dblHeight) sRect.SetSizeEx sRect.CenterX, sRect.CenterY, JQ_RoundUp(sRect.SizeWidth, lngRoundingDecPl) + 2 * dblLeeway, JQ_RoundUp(sRect.SizeHeight, lngRoundingDecPl) + 2 * dblLeeway End Sub Function JQ_RoundUp(Number As Double, NumDecPl As Long) As Double Dim dblTemp As Double On Error GoTo ErrHandler dblTemp = Number * 10 ^ NumDecPl If dblTemp > Int(dblTemp) Then JQ_RoundUp = (Int(dblTemp) + 1) / 10 ^ NumDecPl Else JQ_RoundUp = Number End If ExitFunc: Exit Function ErrHandler: MsgBox "Error occurred: " & Err.Description & vbCrLf & vbCrLf & "JQ_RoundUp()" Resume ExitFunc End Function
I thought this needed it own thread. :-)
How would I do this? - Code snippets feedback - Developer Area - CorelDRAW Community
Happy coding,
-Shelby