TheSwamp

Code Red => VB(A) => Topic started by: ML on November 13, 2007, 03:04:49 PM

Title: Clip Boundaries for a Raster
Post by: ML on November 13, 2007, 03:04:49 PM

I am having a bit of difficulty here, despite all my efforts
This is The VBA example, combined with some of my code
In the ClipPoints section, I kind of figured out what they are doing but after I insert my raster; the clip boundaries I set are not working.

I am inserting a raster at 0,0
Then I want to clip the raster to a 5', 5' Boundarie

Can someone tell me how I should correctly fill in the ClipPoints section (Points) to get that?

Thank you

Mark

Code: [Select]
Sub InstRast()

    Dim InsertPnt(0 To 2) As Double
    Dim scalefactor As Double
    Dim RotAngle As Double
    Dim Imgpth As String
    Dim Imgname As String
    Dim RastImg As AcadRasterImage
   
    Imgpth = "K:\AutoCAD\Work Related\"
    Imgname = "FtWashington600.tif"
   
    InsertPnt(0) = 0#: InsertPnt(1) = 0#: InsertPnt(2) = 0#
    scalefactor = 12#
    rotationAngle = 0
   
    On Error Resume Next
   
    Set RastImg = ThisDrawing.PaperSpace.AddRaster(Imgpth & Imgname, InsertPnt, scalefactor, RotAngle)
   
    RastImg.Name = Imgname
    RastImg.Name = Left(Imgname, Len(Imgname) - 4)
   
    If Err.Description = "Filer error" Then
        MsgBox ImageName & " could not be found."
        Exit Sub
    End If
   
    ZoomAll
       
    ' Establish the clip boundary with an array of points
    Dim clipPoints(0 To 9) As Double
    clipPoints(0) = 6: clipPoints(1) = 6.75
    clipPoints(2) = 7: clipPoints(3) = 6
    clipPoints(4) = 6: clipPoints(5) = 5
    clipPoints(6) = 5: clipPoints(7) = 6
    clipPoints(8) = 6: clipPoints(9) = 6.75
   
    ' Clip the image
    RastImg.ClipBoundary clipPoints
   
    ' Enable the display of the clip
    RastImg.ClippingEnabled = True
    ThisDrawing.Regen acActiveViewport
       
End Sub
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 13, 2007, 03:30:10 PM
5'sq. centered on the image, from the insertion point, or something else?

From the insertion point would basically be
Code: [Select]
Sub InstRast()

    Dim InsertPnt(0 To 2) As Double
    Dim scalefactor As Double
    Dim RotAngle As Double
    Dim Imgpth As String
    Dim Imgname As String
    Dim RastImg As AcadRasterImage
   
    Imgpth = "K:\AutoCAD\Work Related\"
    Imgname = "FtWashington600.tif"
   
    InsertPnt(0) = 0#: InsertPnt(1) = 0#: InsertPnt(2) = 0#
    scalefactor = 12#
    rotationAngle = 0
   
    On Error Resume Next
   
    Set RastImg = ThisDrawing.PaperSpace.AddRaster(Imgpth & Imgname, InsertPnt, scalefactor, RotAngle)
   
    RastImg.Name = Imgname
    RastImg.Name = Left(Imgname, Len(Imgname) - 4)
   
    If Err.Description = "Filer error" Then
        MsgBox ImageName & " could not be found."
        Exit Sub
    End If
   
    ZoomAll
       
    ' Establish the clip boundary with an array of points
    Dim clipPoints(0 To 9) As Double
    clipPoints(0) = 0: clipPoints(1) = 0
    clipPoints(2) = 0: clipPoints(3) = 60
    clipPoints(4) = 60: clipPoints(5) = 60
    clipPoints(6) = 60: clipPoints(7) = 0
    clipPoints(8) = 0: clipPoints(9) = 0
   
    ' Clip the image
    RastImg.ClipBoundary clipPoints
   
    ' Enable the display of the clip
    RastImg.ClippingEnabled = True
    ThisDrawing.Regen acActiveViewport
       
End Sub
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 13, 2007, 03:43:29 PM

Bob;

Yes from insertion is fine.
I noticed you handled it in inches, I just changed the 60 to 5 as we are working in feet.
That is great! Thank you

Now I see how it is working!

It is going in a rect. direction bottom to top, left to right.

And that is where they get the 10 points from.

2 (points(x+y) x 4 sides = 8 + back to 0,0 = 10


Code: [Select]
Dim clipPoints(0 To 9) As Double
    clipPoints(0) = 0: clipPoints(1) = 0
    clipPoints(2) = 0: clipPoints(3) = 5
    clipPoints(4) = 5: clipPoints(5) = 5
    clipPoints(6) = 5: clipPoints(7) = 0
    clipPoints(8) = 0: clipPoints(9) = 0

Thanks you

Mark
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 13, 2007, 03:50:25 PM
Wasn't sure what flavor you were so I went with inches.  I figured Civil would be smart enough to figure out the difference between feet and inches, Architects, probably not.

I don't think that it matters if you go clockwise or counter(anti)clockwise and I think it can be an irregular shape.  That's just a guess though, I haven't actually looked into it.  All you need to do is list XY coordinates to define a shape where the last point is the same as the first point.  The easiest way to do that is to think about how you would put a pline in without touching the mouse.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 13, 2007, 03:52:12 PM

Yes you can do an irregular shape
Try VBA's Example, it is strange

Mark

Code: [Select]
Sub Example_ClippingEnabled()
    ' This example adds a raster image in model space.
    ' It then clips the image based on a clip boundary,
    ' and toggles the display of the clipping.
   
    Dim insertionPoint(0 To 2) As Double
    Dim scalefactor As Double
    Dim rotationAngle As Double
    Dim imageName As String
    Dim rasterObj As AcadRasterImage
   
    imageName = "C:\AutoCAD\sample\downtown.jpg"
    insertionPoint(0) = 5#: insertionPoint(1) = 5#: insertionPoint(2) = 0#
    scalefactor = 2#
    rotationAngle = 0
   
    On Error Resume Next
    ' Creates a raster image in model space
    Set rasterObj = ThisDrawing.ModelSpace.AddRaster(imageName, insertionPoint, scalefactor, rotationAngle)
   
    If Err.Description = "Filer error" Then
        MsgBox imageName & " could not be found."
        Exit Sub
    End If
   
    ZoomAll
    MsgBox "Clip the image?", , "ClipBoundary Example"
   
    ' Establish the clip boundary with an array of points
    Dim clipPoints(0 To 9) As Double
    clipPoints(0) = 6: clipPoints(1) = 6.75
    clipPoints(2) = 7: clipPoints(3) = 6
    clipPoints(4) = 6: clipPoints(5) = 5
    clipPoints(6) = 5: clipPoints(7) = 6
    clipPoints(8) = 6: clipPoints(9) = 6.75
   
    ' Clip the image
    rasterObj.clipBoundary clipPoints
   
    ' Enable the display of the clip
    rasterObj.ClippingEnabled = True
     ThisDrawing.Regen acActiveViewport
   MsgBox "Turn off the display of the clipped image.", , "ClippingEnabled Example"
   
    ' Disable the display of the clip
    rasterObj.ClippingEnabled = False
    ThisDrawing.Regen acActiveViewport
    MsgBox "Display off.", , "ClippingEnabled Example"
   
End Sub
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 13, 2007, 03:55:16 PM
True.  Didn't actually mean irregular shape when I said it.  I meant more than four sided thingy.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 13, 2007, 04:25:50 PM

Oh good point

Evidentially 4 sides are 10 points.
I would imagine you can do more but not sure

In ACAD, you can try the imageclip command if you are realy curious and see what it gives you

Mark
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 13, 2007, 08:54:28 PM
Actually, 4 sides is 5 points.

Code: [Select]
1--------2
5        |
|        |
|        |
4--------3

Each point is defined by a coordinate.  Each coordinate is two ordinates (numbers), an X ordinate and a Y ordinate, so 0,1 is the first point, 2,3 the second, 4,5, the third, 6,7 the fourth, and 8,9 is the fifth which duplicates the first so that the boundary is closed.  Does that make sense to you?
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 14, 2007, 09:56:30 AM

Yes, of course it does and you are absolutely right
It is 5 point and 10 coorinates.

Thanks Bob! :)
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 14, 2007, 02:51:03 PM

Bob,
Let me ask you or anyone else this

I have this code

Code: [Select]
Dim llpnt As Variant 'lower left point
Dim urpnt As Variant 'upper right point

With ThisDrawing.Utility
 llpnt = .GetPoint(, vbCrLf & "Select Lower Left Point: ")
 urpnt = .GetPoint(, vbCrLf & "Select Upper Right Point: ")
End With

And I somehow need to make the lower left point and the upper right (picked) points of the raster = my 5' x 5' boundary that I defined with the clipboundary.
Any idea how I can make this happen?

Thank you

Mark
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 14, 2007, 03:07:24 PM
Sure.  What you want to do is basically this
Code: [Select]
Dim llpnt As Variant 'lower left point
Dim urpnt As Variant 'upper right point

With ThisDrawing.Utility
 llpnt = .GetPoint(, vbCrLf & "Select Lower Left Point: ")
 urpnt = .GetPoint(, vbCrLf & "Select Upper Right Point: ")
End With
Dim clipPoints(0 To 9) As Double
    clipPoints(0) = llpnt(0): clipPoints(1) = llpnt(1)
    clipPoints(2) = llpnt(0): clipPoints(3) = urpnt(1)
    clipPoints(4) = urpnt(0): clipPoints(5) = urpnt(1)
    clipPoints(6) = urpnt(0): clipPoints(7) = llpnt(1)
    clipPoints(8) = llpnt(0): clipPoints(9) = llpnt(1)
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 14, 2007, 03:17:41 PM

Yes sir!

That was the ticket!

Thank you so much Bob!

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 14, 2007, 03:50:49 PM
Bob,
If you don't mind one more question?

That method works great for making the clip boundary your picked points.

Now check this out:

Code: [Select]
Dim llpnt As Variant 'lower left point
Dim urpnt As Variant 'upper right point

With ThisDrawing.Utility
 llpnt = .GetPoint(, vbCrLf & "Select Lower Left Point: ")
 urpnt = .GetPoint(, vbCrLf & "Select Upper Right Point: ")
End With

mdpnt(0) = llpnt(0) + ((urpnt(0) - llpnt(0)) / 2) 'Midpoint (X) = The point in the far left direction - the point in the far right direction / 2
mdpnt(1) = llpnt(1) + ((urpnt(1) - llpnt(1)) / 2) 'Midpoint (Y) = The point in the far top direction - the point in the far bottom direction / 2
mdpnt(2) = 0

I have my midpoint of the two picked points calculated;

Now I would like to make my clip boundary 5' from the midpoint in the x and y direction
Giving me a 5' x 5' clipboundary from the midpoint of the two picked points

I tried using your method to get it but no luck so far

Any ideas?

Thank you again

Mark

Title: Re: Clip Boundaries for a Raster
Post by: ML on November 14, 2007, 03:51:26 PM

Do I still need 9 points?

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 14, 2007, 03:54:10 PM

Ooops sorry
It is midpoint +/- 30 in each direction

Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 14, 2007, 04:25:14 PM
Yes, 30 +- in each direction, All 4 directions for calcing the points
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 14, 2007, 04:30:04 PM

Do I still need 9 points?

Mark
and yes, you still need an array (0 to 9), ten numbers for a 4 sided shape.  You need to close AFAIK*



*caveat - everything I'm giving you here is from reading what you have and typing a response that seems logical to me.  I'm not playing along on the home version.  Everything I'm giving you, I'm giving as guidelines.  It is most definitely NOT test and most likely not functioning code.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 14, 2007, 06:07:01 PM

Cool

Thanks again guys!

Unfortunately I got pulled away for other things but I will certainly get back to it tomorrow

This is very cool stuff.

I appreciate all the help!

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 14, 2007, 11:32:25 PM

I thought I would give it a shot tonight but still no luck.
Starting from the midpoint, this is what I used but it did not work as I hoped

Code: [Select]
'Clip boundary = 2.5' from mdpnt to edges. 5' boundary
  clipPoints(0) = mdpnt(0) + 2.5: clipPoints(1) = mdpnt(1) + 2.5
  clipPoints(2) = mdpnt(0): clipPoints(3) = mdpnt(1)
  clipPoints(4) = mdpnt(0): clipPoints(5) = mdpnt(1) + 5
  clipPoints(6) = mdpnt(0) + 5: clipPoints(7) = mdpnt(1) + 5
  clipPoints(8) = mdpnt(0) + 5: clipPoints(9) = mdpnt(1)

Can someone please tell me where I am going wrong?

Thank you

Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 14, 2007, 11:36:17 PM
what did u declare ClipPoints as? Integer, double ?
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 14, 2007, 11:36:40 PM
Im also assuming your working in feet not inches
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 10:06:39 AM

Hey CM,

I declared them as:

Dim clipPoints(0 To 9) As Double

And yes, you are correct; I am working in feet.
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 10:12:45 AM
Can someone please tell me where I am going wrong?
It looks like you are close, but you need to use some negative numbers as well to get the left side of the MidPt

OK, lets say for arguments sake, your user picks 10,10 for LL and 90,80 for UR
The midpoint of those 2 points is (X1+X2)/2 , (Y1+Y2)/2 = 10+90=100/2=50, 10+80=90/2=45 so the MP is 50,45 (with me so far?)
Now to center a 60x60 clip boundary on the point 50,45 you need to add 30 and subtract 30 from the appropriate points
So LL is going to be 20,15 and UR is 80,75 Does this make sense so far?

Given those 2 points, we can derive UpperLeft= 20,75 and LowerRight=80,15
thus the ClipBoundary points are from LL counterclockwise in order of X & Y=
LL pt (20,15)
LR pt (80,15)
UR pt (80,75)
UL pt (20,75)
LL again to close (20,15)
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 10:15:20 AM

CM,
Let me give you more info;
This is not the entire module but the critical part:

OK, assume that the raster is already inserted,scaled and all of that stuff
Now we move onto prompting the user to pick two point on the raster

Code: [Select]
Dim llpnt As Variant  'lower left point
Dim urpnt As Variant  'upper right point
Dim mdpnt(0 To 2) As Double
Dim clipPoints(0 To 9) As Double

     
With ThisDrawing.Utility
 llpnt = .GetPoint(, vbCrLf & "Select Lower Left : ")
 urpnt = .GetPoint(, vbCrLf & "Select Upper Right: ")
End With

 mdpnt(0) = llpnt(0) + ((urpnt(0) - llpnt(0)) / 2) 'Midpoint (X) = (The point in the far left direction) - (The point in the far right direction) / 2
 mdpnt(1) = llpnt(1) + ((urpnt(1) - llpnt(1)) / 2) 'Midpoint (Y) = (The point in the far top direction) - (The point in the far bottom direction) / 2
 mdpnt(2) = 0 'Z = 0

[b]'Here is where I need help:[/b]
'Clip boundary = 2.5' from mdpnt to edges. 5' boundary
'  clipPoints(0) = mdpnt(0) - 2.5: clipPoints(1) = mdpnt(1) - 2.5
'  clipPoints(2) = mdpnt(0) + 0: clipPoints(3) = mdpnt(1) + 5
'  clipPoints(4) = mdpnt(0) + 5: clipPoints(5) = mdpnt(1) + 0
'  clipPoints(6) = mdpnt(0) + 0: clipPoints(7) = mdpnt(1) - 5
'  clipPoints(8) = mdpnt(0) - 5: clipPoints(9) = mdpnt(1) + 0

'Clip the image
RastImg.ClipBoundary clipPoints
   
'Enable the display of the clip
RastImg.ClippingEnabled = True
 
 
ThisDrawing.Regen acActiveViewport

Thanks
Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 10:23:33 AM
Code: [Select]
...
 mdpnt(0) = llpnt(0) + ((urpnt(0) - llpnt(0)) / 2) 'Midpoint (X) = (The point in the far left direction) - (The point in the far right direction) / 2
 mdpnt(1) = llpnt(1) + ((urpnt(1) - llpnt(1)) / 2) 'Midpoint (Y) = (The point in the far top direction) - (The point in the far bottom direction) / 2
 mdpnt(2) = 0 'Z = 0
.....
Thanks
Mark
This is where I see a problem.  I am having trouble following your logic in deriving the MP.  You just need (X1+X2)/2   Not (X1+(X2-X1))/2
I think your creating to small a number there.  Try changing to just (X1+X2)/2
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 10:27:05 AM
Here is another thought, AND I dont know if this can be done through code!!  What if you just "drew" a rectangle through code, Which would need the MP and width/height both of which would be 60.  Can you pick existing rectangle and make a clipping window?
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 10:30:52 AM
OK,

I do understand your explanations CM and thank you.
As far as the midpoint; it seems to be working fine.
I'm not sure if you tried that code that I sent you yesterday; but here it is again.
Using this code, pick 2 simple points, like a 5' x 5' rectangle, lower left and upper right points, then look at your immediate window.
I think you will find that the midpoint is being calculated fine.
I will also try again to make sure

Mark

Code: [Select]
Sub Getpoints()

Dim llpnt As Variant 'lower left point
Dim urpnt As Variant 'upper right point
Dim xpnts As Variant
Dim ypnts As Variant
Dim mdpnt(0 To 2) As Double

With ThisDrawing.Utility
 llpnt = .GetPoint(, vbCrLf & "Select Lower Left Limits of your Project Area: ")
 urpnt = .GetPoint(, vbCrLf & "Select Upper Right Limits of your Project Area: ")
End With

xpnts = llpnt(0) + urpnt(0)
ypnts = llpnt(1) + urpnt(1)

mdpnt(0) = llpnt(0) + ((urpnt(0) - llpnt(0)) / 2) 'Midpoint (X) = (The point in the far left direction) - (The point in the far right direction) / 2
mdpnt(1) = llpnt(1) + ((urpnt(1) - llpnt(1)) / 2) 'Midpoint (Y) = (The point in the far top direction) - (The point in the far bottom direction) / 2
mdpnt(2) = 0 'Z = 0

Debug.Print "Lower left point: "; llpnt(0) & "," & llpnt(1)
Debug.Print "Upper right point: "; urpnt(0) & "," & urpnt(1)
Debug.Print "Xpoints: "; xpnts
Debug.Print "Ypoints: "; ypnts
Debug.Print "Midpoint: "; mdpnt(0) & "," & mdpnt(1)

End Sub
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 10:33:14 AM

I think what you are suggesting is this:

Code: [Select]
NewMidpnt = llpnt(0) + urpnt(0)\2
NewMidpnt = llpnt(1) + urpnt(1)\2
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 10:40:10 AM

This is pretty cool too for getting points returned to you in the immediate window

Code: [Select]
Sub GetpointsAll()

Dim pnt1 As Variant
Dim pnt2 As Variant
Dim pnt3 As Variant
Dim pnt4 As Variant
Dim pnt5 As Variant
Dim pnt6 As Variant
Dim pnt7 As Variant
Dim pnt8 As Variant
Dim pnt9 As Variant

On Error Resume Next
With ThisDrawing.Utility
 pnt1 = .GetPoint(, vbCrLf & "pnt1 ")
 pnt2 = .GetPoint(, vbCrLf & "pnt2 ")
 pnt3 = .GetPoint(, vbCrLf & "pnt3 ")
 pnt4 = .GetPoint(, vbCrLf & "pnt4 ")
 pnt5 = .GetPoint(, vbCrLf & "pnt5 ")
 pnt6 = .GetPoint(, vbCrLf & "pnt6 ")
 pnt7 = .GetPoint(, vbCrLf & "pnt7 ")
 pnt8 = .GetPoint(, vbCrLf & "pnt8 ")
 pnt9 = .GetPoint(, vbCrLf & "pnt9 ")
End With


Debug.Print "Pnt1: "; pnt1(0) & "," & pnt1(1)
Debug.Print "Pnt2: "; pnt2(0) & "," & pnt2(1)
Debug.Print "Pnt3: "; pnt3(0) & "," & pnt3(1)
Debug.Print "Pnt4: "; pnt4(0) & "," & pnt4(1)
Debug.Print "Pnt5: "; pnt5(0) & "," & pnt5(1)
Debug.Print "Pnt6: "; pnt6(0) & "," & pnt6(1)
Debug.Print "Pnt7: "; pnt7(0) & "," & pnt7(1)
Debug.Print "Pnt8: "; pnt8(0) & "," & pnt8(1)
Debug.Print "Pnt9: "; pnt9(0) & "," & pnt9(1)

End Sub


The On Error Resume Next takes care of un picked points, you will just need to enter through any points you don't pick
So, for example; if you pick Pnt1,Pnt2,Pnt3 and Pnt4; you will need to press enter 5 times to get to the end of the sub.
I'm sure I could do more to address un picked points but this was just down and dirty to get some results

Mark
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 15, 2007, 11:04:27 AM
Try this on for size.
Code: [Select]
Sub GetpointsAll()

Dim pnt As Variant
Dim i As Integer
On Error GoTo Boom
i = 1
Do
  pnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "pnt" & i)
  Debug.Print "Pnt" & i & ": "; pnt(0) & "," & pnt(1)
  i = i + 1
Loop

Boom:
  Select Case Err.Number
    Case Else
      Debug.Print Err.Number
      Err.Clear
      Exit Sub
  End Select
End Sub
will work if you need 1 or 100
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 11:18:13 AM

Very Cool Bob, thank you!
I still need to figure out this clipboundary from midpoint problem but I appreciate you modifying the pnt code; it works great and it will be very useful for some things,

I changed the label Boom to NoPoint
On Error Goto NoPoint    LOL

Make sense?  :)

Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 11:29:13 AM

I think what you are suggesting is this:

Code: [Select]
NewMidpnt = llpnt(0) + urpnt(0)\2
NewMidpnt = llpnt(1) + urpnt(1)\2
yes and no
you need () around the LL and UR to prevent UR(0)/2  +  LL(0) from happening
Code: [Select]
NewMidpnt = (llpnt(0) + urpnt(0))\2
NewMidpnt = (llpnt(1) + urpnt(1))\2
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 11:32:23 AM
Also look at / vs \
One of those is integer division which will round off your answer to a whole number
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 11:41:44 AM
OK CM

With your method

You want this:
Code: [Select]
mdpnt(0) = (llpnt(0) + urpnt(0)) / 2
mdpnt(1) = (llpnt(1) + urpnt(1)) / 2
To get your actual value

It looks like the \ operator will round to a whole number

Mark

Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 15, 2007, 11:42:55 AM
Sorry, just went to the last post, missed a few, but was under the impression you had that taken care of.

Code: [Select]
Dim llpnt As Variant  'lower left point
Dim urpnt As Variant  'upper right point
Dim mdpnt(0 To 1) As Double
Dim clipPoints(0 To 9) As Double

     
With ThisDrawing.Utility
 llpnt = .GetPoint(, vbCrLf & "Select Lower Left : ")
 urpnt = .GetPoint(, vbCrLf & "Select Upper Right: ")
End With

 mdpnt(0) = (urpnt(0) + llpnt(0)) / 2 'Midpoint (X) = (The point in the far left direction) - (The point in the far right direction) / 2
 mdpnt(1) = llpnt(1) + llpnt(1)) / 2 'Midpoint (Y) = (The point in the far top direction) - (The point in the far bottom direction) / 2

[b]'Here is where I need help:[/b]
'Clip boundary = 2.5' from mdpnt to edges. 5' boundary
  clipPoints(0) = mdpnt(0) - 2.5: clipPoints(1) = mdpnt(1) - 2.5
  clipPoints(2) = mdpnt(0) - 2.5: clipPoints(3) = mdpnt(1) + 2.5
  clipPoints(4) = mdpnt(0) + 2.5: clipPoints(5) = mdpnt(1) + 2.5
  clipPoints(6) = mdpnt(0) + 2.5: clipPoints(7) = mdpnt(1) - 2.5
  clipPoints(8) = mdpnt(0) - 2.5: clipPoints(9) = mdpnt(1) + -2.5

'Bob Note
'It looks from what you had there, that you still don't understand what you're after
'it looks like you are giving directions for the shape relative to the last point
'That's not what you need to do here.  What you need are the absolute ordinates for each one
'Don't think of it as drawing lines, think of it as plotting points on a graph that
'the command will connect like a dot to dot.  All you are supplying are the dots.

'Clip the image
RastImg.ClipBoundary clipPoints
   
'Enable the display of the clip
RastImg.ClippingEnabled = True
 
 
ThisDrawing.Regen acActiveViewport

[edit]Duh's got the right of it \ gives you an integer / gives you a floating point.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 12:06:46 PM

BOB!

You are the man!

Oh I see!  :-o
I read your note, thank you for that too! In this case, you are defining (as you said "like plotting points on a graph") "all" points from the midpoint and building the boundary around the midpoint.
As you said, I am treating it like I am drawing a series of lines to build my boundary.
Whereas the way (proper way) you are doing it is giving the absolute coords from the midpoint and acad is connecting the dots to make the boundary (rectangle)
Very cool indeed!

Thank you again   :-)

Mark
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 15, 2007, 01:15:41 PM
Glad you're getting it.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 01:36:45 PM

Yes sir!

Thank you and thank you for the points code as well.
I like the way you handled that, looping through and incrementing the pnt variable by 1 each time.

Mark
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 15, 2007, 02:08:53 PM
Thanks
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 02:21:50 PM

No thank you :)
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 02:23:34 PM
You know what would be cool would be to make a function that had 3 arguments, 2 pts and 1 size.  You could pick your points, pass those to the function, and ask user how big the clipping should be, and have the function return the array of points back to your main function
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 02:24:42 PM
Conceptually I had the right idea; that was to use the midpoint to build the boundary but getting there was a B***H  LOL

Thanks guys!

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 02:28:09 PM

CM
That sounds cool but I think we hit that already, only not with a function

Wouldn't this method kind of do that?

User just picks points on the raster and it is clipped accordingly

Code: [Select]
'Clip boundary = picked points (llpnt and urpnt)
 clipPoints(0) = llpnt(0): clipPoints(1) = llpnt(1)
 clipPoints(2) = llpnt(0): clipPoints(3) = urpnt(1)
 clipPoints(4) = urpnt(0): clipPoints(5) = urpnt(1)
 clipPoints(6) = urpnt(0): clipPoints(7) = llpnt(1)
 clipPoints(8) = llpnt(0): clipPoints(9) = llpnt(1)
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 02:29:33 PM
Yes, but we have hard coded the 5x5. what if we want to change the size of the clipping on the fly
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 02:51:23 PM

Your idea is really cool but this code here
Code: [Select]
'Clip boundary = picked points (llpnt and urpnt)
 clipPoints(0) = llpnt(0): clipPoints(1) = llpnt(1)
 clipPoints(2) = llpnt(0): clipPoints(3) = urpnt(1)
 clipPoints(4) = urpnt(0): clipPoints(5) = urpnt(1)
 clipPoints(6) = urpnt(0): clipPoints(7) = llpnt(1)
 clipPoints(8) = llpnt(0): clipPoints(9) = llpnt(1)
Is not hardcoding a 5 x5; it is creating the clip boundary based off of the lower left and upper right picked points.

So, bascially your function only needs to fill in the values for the variables llpnt and urpnt; I think

So; if the user inputs 10 x 10; then we need to retrieve that data and do the math on llpnt and urpnt
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 02:57:13 PM
By selecting the lower left and upper right; we already have all the coords that we need
So again, it is just filling in

Code: [Select]
'Clip boundary = picked points (llpnt and urpnt)
 clipPoints(0) = llpnt(0): clipPoints(1) = llpnt(1)
 clipPoints(2) = llpnt(0): clipPoints(3) = urpnt(1)
 clipPoints(4) = urpnt(0): clipPoints(5) = urpnt(1)
 clipPoints(6) = urpnt(0): clipPoints(7) = llpnt(1)
 clipPoints(8) = llpnt(0): clipPoints(9) = llpnt(1)

with the proper coords

User inputs 10 x 10
We grab that and do 10 -/+ llpnt and urpnt to get the clip boundary, I think :)

I am loosing my ability to think at this point  :-(

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 03:03:32 PM


I think what we really need is VBAnonymous Meetings  LOL
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 15, 2007, 03:05:18 PM
Beware the pseudocodiness of it
Code: [Select]
numbah = thisdrawing.utility.getreal ("How big a square ya after, Bucko?: ")

  clipPoints(0) = mdpnt(0) - numbah/2: clipPoints(1) = mdpnt(1) - numbah/2
  clipPoints(2) = mdpnt(0) - numbah/2: clipPoints(3) = mdpnt(1) + numbah/2
  clipPoints(4) = mdpnt(0) + numbah/2: clipPoints(5) = mdpnt(1) + numbah/2
  clipPoints(6) = mdpnt(0) + numbah/2: clipPoints(7) = mdpnt(1) - numbah/2
  clipPoints(8) = mdpnt(0) - numbah/2: clipPoints(9) = mdpnt(1) + -numbah/2
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 03:08:33 PM

Bob; if you keep this up; I will be asking for your phone number LOL; just kidding  :-D

Of course, now I need to go try this  :-)

Mark

Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 15, 2007, 03:11:30 PM

Bob; if you keep this up; I will be asking for your phone number LOL; just kidding  :-D

Of course, now I need to go try this  :-)

Mark


It's going to take some tweaking, that was just a nudge.  You'll need to bump up your error handling so that it knows what to do when somebody types in something that's not a number.  You might want to put in a default size so they can hit enter to get the default.  You might also want to give them an option to do a rectangle instead of square.  Then again, maybe not.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 03:13:02 PM

That's funny; using the midpoint was my idea originally although I needed your guys help on how to build around it; however I failed to think of that in this (CM's idea) application.

I keep getting stuck on the upper and lower points.

The midpoint is definetely THE most logical place to work from.

So, Hats off to Bob again!  :-)

Mark
Title: Re: Clip Boundaries for a Raster
Post by: Maverick® on November 15, 2007, 03:26:48 PM
Bob; if you keep this up; I will be asking for your phone number

Like that hasn't been on how many bar napkins and toilet stalls west of the Mississippi.
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 15, 2007, 03:29:00 PM
A couple of other thoughts to throw out to you.  with the two point selection method, you could just check the distance, round to the nearest whole number, and clip.  For a midpoint centered clip, you can just get them to pick a center point and distance instead of two points.
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 15, 2007, 03:29:38 PM
Bob; if you keep this up; I will be asking for your phone number

Like that hasn't been on how many bar napkins and toilet stalls west of the Mississippi.
West of the Mississippi?  I've got national renown.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 03:29:51 PM
WAIT!

Bob

With your code

Code: [Select]
numbah = thisdrawing.utility.getreal ("How big a square ya after, Bucko?: ")

  clipPoints(0) = mdpnt(0) - numbah/2: clipPoints(1) = mdpnt(1) - numbah/2
  clipPoints(2) = mdpnt(0) - numbah/2: clipPoints(3) = mdpnt(1) + numbah/2
  clipPoints(4) = mdpnt(0) + numbah/2: clipPoints(5) = mdpnt(1) + numbah/2
  clipPoints(6) = mdpnt(0) + numbah/2: clipPoints(7) = mdpnt(1) - numbah/2
  clipPoints(8) = mdpnt(0) - numbah/2: clipPoints(9) = mdpnt(1) + -numbah/2

We will still need

Code: [Select]
Dim llpnt As Variant 'lower left point
Dim urpnt As Variant 'upper right point
Dim mdpnt(0 To 2) As Double
Dim clipPoints(0 To 9) As Double
      
With ThisDrawing.Utility
 llpnt = .GetPoint(, vbCrLf & "Select Lower Left Point: ")
 urpnt = .GetPoint(, vbCrLf & "Select Upper Right Point: ")
End With
  
mdpnt(0) = (llpnt(0) + urpnt(0)) / 2 'Midpoint (X) = (The far left picked point + the far right picked point) / 2
mdpnt(1) = (llpnt(1) + urpnt(1)) / 2 'Midpoint (Y) = (The far bottom picked point + the far top picked point) / 2
mdpnt(2) = 0

To get our midpoint; based off of the picked points in the above code, correct?

So, we get our picked points, figure out the midpnt (all done), then with Bob's "new" code, we get the boundary size;
the boundary size gets divided by 2 and gets built around the midpoint in all 4 directions at that (the divided) size
Very clever!

Mark

Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 03:35:04 PM
Bob is on the right track of what I was thinking.  Bob, how do you do the default thing???  In LISP I know you use <> to define it, but I never learned how in VBA
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 15, 2007, 03:35:39 PM
Did everyone hear the click as the pieces fell into place?
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 03:36:12 PM

Bob

Thankfully, I don't swing that way, but I will work for code  :-D


Also, your above idea is also very clever.
Pick center point and get size.


Mark

Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 15, 2007, 03:37:58 PM
Bob is on the right track of what I was thinking.  Bob, how do you do the default thing???  In LISP I know you use <> to define it, but I never learned how in VBA
You use error handling with VBA I throw the <crap> into my prompt so it looks familiar to Johnny Caduserguy but it's handle with the error trapping.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 03:38:27 PM

Quote
Did everyone hear the click as the pieces fell into place?

I'm sorry I must have missed it but I hear the click in my e-mail every time there is a new post  :-)
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 03:38:49 PM
A couple of other thoughts to throw out to you.  with the two point selection method, you could just check the distance, round to the nearest whole number, and clip.  For a midpoint centered clip, you can just get them to pick a center point and distance instead of two points.
This actually is less coding, and allows the user to "center" the clipping box based on a selected point.  Much easier and cleaner if you ask me
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 03:40:10 PM
Bob is on the right track of what I was thinking.  Bob, how do you do the default thing???  In LISP I know you use <> to define it, but I never learned how in VBA
You use error handling with VBA I throw the <crap> into my prompt so it looks familiar to Johnny Caduserguy but it's handle with the error trapping.
So you trap NULL?
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 03:41:06 PM
do you use a form of initget? and set bits to allow null entry, and then trap for the null?
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 03:51:10 PM
Quote
This actually is less coding, and allows the user to "center" the clipping box based on a selected point.  Much easier and cleaner if you ask me

It is actually a very clever idea but it still all boils down to "what" is the need

In my application; it needs to be fitted into a 5 x 5 box on a title block; so yes, they could have said I prefer to have this area centered but that is ok; then can still pick a very small or specific area on the raster and the 5 x 5 will get made with that area is basically centered.
I think this offers a lot of flexibility as they have the window option.

I am curious to try that dynamic boundary code though

Mark

Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 04:08:15 PM
ill write something up for you
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 04:09:51 PM
OK Guys

Here is the total accumulation of what we had done; hopefully others can benefit from it.
Bob, your last method is the last one in the code; the rest are commented out
It is really cool!
The user can type in the size and it is created.
The only thing I noticed is that it did not regenerate on bigger sizes; not sure why.
Mark

Code: [Select]
Sub InstRast()
 
Dim RastImg As AcadRasterImage
Dim Imgpth As String
Dim Imgname As String
Dim InsertPnt(0 To 2) As Double, scalefactor As Double, RotAngle As Double


Imgpth = "Path"
Imgname = "filename"
 
InsertPnt(0) = 0#: InsertPnt(1) = 0#: InsertPnt(2) = 0#
scalefactor = 1
RotAngle = 0
       
On Error GoTo Errorhandler
Set RastImg = ThisDrawing.PaperSpace.AddRaster(Imgpth & Imgname, InsertPnt, scalefactor, RotAngle)

RastImg.Name = Imgname
RastImg.Name = Left(Imgname, Len(Imgname) - 4)


RastImg.scalefactor = 12

'Move Points
 Dim Point1(0 To 2) As Double
 Dim Point2(0 To 2) As Double
 Point1(0) = 8: Point1(1) = 0: Point1(2) = 0
 Point2(0) = 0: Point2(1) = 0: Point2(2) = 0
 
'Move Raster
 RastImg.Move Point1, Point2

   
Errorhandler:
   If Err.Description = "File access error" Then
    If MsgBox("Can not find image file") Then
     Exit Sub
    End If
   End If
   
   
Dim llpnt As Variant 'lower left point
Dim urpnt As Variant 'upper right point
Dim mdpnt(0 To 2) As Double
Dim clipPoints(0 To 9) As Double

     
With ThisDrawing.Utility
 llpnt = .GetPoint(, vbCrLf & "Select Lower Left Point: ")
 urpnt = .GetPoint(, vbCrLf & "Select Upper Right Point: ")
End With

 
mdpnt(0) = (llpnt(0) + urpnt(0)) / 2 'Midpoint (X) = (The far left picked point + the far right picked point) / 2
mdpnt(1) = (llpnt(1) + urpnt(1)) / 2 'Midpoint (Y) = (The far bottom picked point + the far top picked point) / 2
mdpnt(2) = 0
 
'FINITE
'Create a 5 x 5 clip boundary
'  clipPoints(0) = 0: clipPoints(1) = 0
'  clipPoints(2) = 0: clipPoints(3) = 5
'  clipPoints(4) = 5: clipPoints(5) = 5
'  clipPoints(6) = 5: clipPoints(7) = 0
'  clipPoints(8) = 0: clipPoints(9) = 0

'Clip boundary = 2.5 from the mdpnt of the raster's picked points to the boundary coords.
'  clipPoints(0) = mdpnt(0) - 2.5: clipPoints(1) = mdpnt(1) - 2.5
'  clipPoints(2) = mdpnt(0) - 2.5: clipPoints(3) = mdpnt(1) + 2.5
'  clipPoints(4) = mdpnt(0) + 2.5: clipPoints(5) = mdpnt(1) + 2.5
'  clipPoints(6) = mdpnt(0) + 2.5: clipPoints(7) = mdpnt(1) - 2.5
'  clipPoints(8) = mdpnt(0) - 2.5: clipPoints(9) = mdpnt(1) + -2.5

'DYNAMIC
'Clip boundary = picked points (llpnt + urpnt)
'  clipPoints(0) = llpnt(0): clipPoints(1) = llpnt(1)
'  clipPoints(2) = llpnt(0): clipPoints(3) = urpnt(1)
'  clipPoints(4) = urpnt(0): clipPoints(5) = urpnt(1)
'  clipPoints(6) = urpnt(0): clipPoints(7) = llpnt(1)
'  clipPoints(8) = llpnt(0): clipPoints(9) = llpnt(1)

'Clip boundary =  user defined size
  Dim Bndsize As Integer
  Bndsize = ThisDrawing.Utility.GetReal("What size boundary would you like?: ")

  clipPoints(0) = mdpnt(0) - Bndsize / 2: clipPoints(1) = mdpnt(1) - Bndsize / 2
  clipPoints(2) = mdpnt(0) - Bndsize / 2: clipPoints(3) = mdpnt(1) + Bndsize / 2
  clipPoints(4) = mdpnt(0) + Bndsize / 2: clipPoints(5) = mdpnt(1) + Bndsize / 2
  clipPoints(6) = mdpnt(0) + Bndsize / 2: clipPoints(7) = mdpnt(1) - Bndsize / 2
  clipPoints(8) = mdpnt(0) - Bndsize / 2: clipPoints(9) = mdpnt(1) + -Bndsize / 2
   
     
'Clip the image
 RastImg.ClipBoundary clipPoints
   
'Enable the display of the clip
 RastImg.ClippingEnabled = True
 
 
 ThisDrawing.Regen acActiveViewport
 
End Sub

Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 04:17:28 PM
guess you beat me to it, Ill just chec thru yours
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 04:19:50 PM
the only thing I see, which has no effect on the running of the code b/c order of operation is correct is
Code: [Select]
clipPoints(0) = mdpnt(0) - Bndsize / 2While it is correct, I would personally use () to make it clearer to someone reading it that Bndsize/2 comes before MP-
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 04:20:15 PM
clipPoints(0) = mdpnt(0) - (Bndsize / 2)
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 15, 2007, 04:21:54 PM
The only thing I noticed is that it did not regenerate on bigger sizes; not sure why.
what if you place a breakpoint, does it stop there?
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 15, 2007, 04:28:40 PM
You might try thowing a RastImg.Update in there, not sure if it will help.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 04:29:16 PM
Haven't tried that but I certainly can

Here you go sir

Code: [Select]
clipPoints(0) = mdpnt(0) - (Bndsize / 2): clipPoints(1) = mdpnt(1) - (Bndsize / 2)
  clipPoints(2) = mdpnt(0) - (Bndsize / 2): clipPoints(3) = mdpnt(1) + (Bndsize / 2)
  clipPoints(4) = mdpnt(0) + (Bndsize / 2): clipPoints(5) = mdpnt(1) + (Bndsize / 2)
  clipPoints(6) = mdpnt(0) + (Bndsize / 2): clipPoints(7) = mdpnt(1) - (Bndsize / 2)
  clipPoints(8) = mdpnt(0) - (Bndsize / 2): clipPoints(9) = mdpnt(1) + -(Bndsize / 2)
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 05:01:14 PM


Bob

RastImg.Update

Did not help


Mark
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 15, 2007, 05:03:15 PM
You're gonna make me open autocad, aren't you?
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 06:29:21 PM

LOL

No, I'm sure not

I think we have worked you enough today  LOL

Tomorrow is a new day!  :-)

Mark

Title: Re: Clip Boundaries for a Raster
Post by: ML on November 15, 2007, 07:10:13 PM

Actually
I opened ACAD  LOL

I think (not sure) it has something to do with the getreal method but I am not sure.

I tried Declaring the variable as Integer then I realized that is only good if where want a whole number.

Then I tried as Variant and it works sometimes but not others.

So, I'm sure we will get it

Mark
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 15, 2007, 07:21:54 PM
The opening acad wasn't a knock on you.  I'm working in Revit at the moment so I've just been guessing.  I'm 98% sure that getreal returns a double.
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 16, 2007, 09:31:12 AM
yes
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 16, 2007, 09:33:31 AM
GetInteger gets an Integer whilst GetReal gets a Double
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 16, 2007, 09:36:17 AM
Quote
Then I tried as Variant and it works sometimes but not others.
I think it might be here
Code: [Select]
  Dim Bndsize As Integer
  Bndsize = ThisDrawing.Utility.GetReal("What size boundary would you like?: ")
You are declaring an Integer, but asking for a Double

I would change it to Dim BndSize as Double
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 16, 2007, 11:12:56 AM

Hey Bob
It wasn't taken as such  :-)
I thought you were on your way home but still curious.

I know I have closed down, went to the men's room, got all my stuff together and said, hummmm, let me turn CAD on real quick; then 2 hours went by. So, once I shutdown; I really do try to "shutdown"  :-)
Revit huh? That sounds really cool! So you do 3D Modeling then?

CM, thank you for that little tip, I will use getreal and try using Double as my data type.
Do you think that is what is causing this method
Code: [Select]
  clipPoints(0) = mdpnt(0) - (Bndsize / 2): clipPoints(1) = mdpnt(1) - (Bndsize / 2)
  clipPoints(2) = mdpnt(0) - (Bndsize / 2): clipPoints(3) = mdpnt(1) + (Bndsize / 2)
  clipPoints(4) = mdpnt(0) + (Bndsize / 2): clipPoints(5) = mdpnt(1) + (Bndsize / 2)
  clipPoints(6) = mdpnt(0) + (Bndsize / 2): clipPoints(7) = mdpnt(1) - (Bndsize / 2)
  clipPoints(8) = mdpnt(0) - (Bndsize / 2): clipPoints(9) = mdpnt(1) + -(Bndsize / 2)
To work sometimes and not others?
Have you tried this method yet?

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 16, 2007, 11:20:50 AM

Yes sir (CM) my friend,
You nailed it! It seems to be wroking perfect now
We want Bndsize as Double

Code: [Select]
Dim Bndsize As Double
Bndsize = ThisDrawing.Utility.GetReal("What size boundary would you like?: ")

Bob, that method was a really cool idea!

Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 16, 2007, 11:25:48 AM
To work sometimes and not others?
Mark
Yes, but you know that b/c you just posted faster than me.  By having it as integer you had a 50% chance it would round off to the correct number, and 50% it didn't.  By using Double, you are getting the correct number and processing it from there
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 16, 2007, 11:31:23 AM

Yep

Very cool indeed!

So, you guys rastered out or what?

Mark
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 16, 2007, 11:36:53 AM
trying to get more work done today.  Where are you at now in terms of things working/not working?
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 16, 2007, 01:58:22 PM

Bob! You mean you don't work for us? LOL  J/K
Everything as far as I can see is working A OK.
Very nice indeed.

I am really impressed by the dynamic boundary creations.

This discussion has really helped me learn more about getting, using and manipulating points.
And creating boundaries of course.

Now, I am thinking about putting the raster into a selection set in case I need to do something with after the user exits the sub or whatever.

After that, I think I will leave good enough alone.

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 16, 2007, 03:56:53 PM

Hey guys,

Let me throw this out there.

I noticed if I pick 2 points on the raster and the slection is less then 5' x 5' then only an image frame will display.

I know, "NO S**T, right?

Well, I am not sure that the user would understand why this is happening; so I am wondering if we can do something that will say, if picked boundary is less then 5' x 5' or in Bob's other code where the user types in the boundary size, can we catch that error?

I don't think we can say:
Select Case ClipPoints
 etc. etc.
End Select

However I could be wrong

THanks

Mark

Thanks
Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 19, 2007, 01:13:35 PM

I am going to attempt to answer my own question here:

"After" or "when" the raster is inserted; I believe we can get the height and width of the raster.
After we have that, we can write some code that will say: If the boundary is > then the height and width of the inserted raster, then
Handle Error

Title: Re: Clip Boundaries for a Raster
Post by: ML on November 19, 2007, 01:16:00 PM

ACtually, I noticed an error is not returned, you are just left with an imageframe with none of the image showing, so we would probably need to return a message to the user:

Msgbox " The specified boundary is too large etc. etc."

Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 19, 2007, 01:42:08 PM
I would say post the image you are working with so we can all play along
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 19, 2007, 01:46:32 PM

You're a trooper my friend :)

We'll do
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 19, 2007, 02:23:43 PM
Just for the sake of completion, maybe the image and the dwg.  Oh, and the most upest to date code
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 19, 2007, 02:43:45 PM

Hey guys,

I am posting the lastest code, but in all due respect; wouldn't the same errors occur on your machines once you have the latest code?

If you really want to simulate what I am doing, all you need to do is draw a 5' X 5' rectangle in paperspace; then point the path (imgpath) in the code to a known raster on your machine and we should all then be on the same page.

Actually, I just changed the variable imgpath = ThisDrawing.Path & "\"
So now you can just place any raster in the same directory as your .dwg file and it should be found.
Variable imgname needs to equal your file name

Also, I think the best example to use is the first one under Dynamic; it is the only one "not" commented out

Thanks,

Mark

Code: [Select]
Public Sub InstRast()
 
Dim Imgpth As String
Dim Imgname As String
Dim InsertPnt(0 To 2) As Double, scalefactor As Double, RotAngle As Double

ThisDrawing.ActiveSpace = acPaperSpace

Imgpth = ThisDrawing.Path & "\"
Imgname = "FtWashington600.tif"
 
InsertPnt(0) = 0#: InsertPnt(1) = 0#: InsertPnt(2) = 0#
scalefactor = 1
RotAngle = 0
       
On Error GoTo Errorhandler
Set RastImg = ThisDrawing.PaperSpace.AddRaster(Imgpth & Imgname, InsertPnt, scalefactor, RotAngle)

RastImg.Name = Imgname
RastImg.Name = Left(Imgname, Len(Imgname) - 4)


RastImg.scalefactor = 12

 
'Move Points
 Dim MPointN(0 To 2) As Double 'Negative
 Dim MPointP(0 To 2) As Double 'Positive
 MPointN(0) = 8: MPointN(1) = 0: MPointN(2) = 0
 MPointP(0) = 0: MPointP(1) = 0: MPointP(2) = 0
 
'Move Raster
 RastImg.Move MPointN, MPointP
 
   
Dim llpnt As Variant 'lower left point
Dim urpnt As Variant 'upper right point
Dim mdpnt(0 To 2) As Double
Dim ClipPoints(0 To 9) As Double

     
With ThisDrawing.Utility
 llpnt = .GetPoint(, vbCrLf & "Select Lower Left Point: ")
 urpnt = .GetPoint(, vbCrLf & "Select Upper Right Point: ")
End With

 
mdpnt(0) = (llpnt(0) + urpnt(0)) / 2 'Midpoint (X) = (The far left picked point + the far right picked point) / 2
mdpnt(1) = (llpnt(1) + urpnt(1)) / 2 'Midpoint (Y) = (The far bottom picked point + the far top picked point) / 2
mdpnt(2) = 0

 
   
'FINITE
'Create a 5 x 5 clip boundary
'  clipPoints(0) = 0: clipPoints(1) = 0
'  clipPoints(2) = 0: clipPoints(3) = 5
'  clipPoints(4) = 5: clipPoints(5) = 5
'  clipPoints(6) = 5: clipPoints(7) = 0
'  clipPoints(8) = 0: clipPoints(9) = 0

'Clip boundary = 2.5 from the mdpnt of the raster's picked points to the boundary coords.
  'ClipPoints(0) = mdpnt(0) - 2.5: ClipPoints(1) = mdpnt(1) - 2.5
  'ClipPoints(2) = mdpnt(0) - 2.5: ClipPoints(3) = mdpnt(1) + 2.5
  'ClipPoints(4) = mdpnt(0) + 2.5: ClipPoints(5) = mdpnt(1) + 2.5
  'ClipPoints(6) = mdpnt(0) + 2.5: ClipPoints(7) = mdpnt(1) - 2.5
  'ClipPoints(8) = mdpnt(0) - 2.5: ClipPoints(9) = mdpnt(1) + -2.5

'DYNAMIC
'Clip boundary = picked points (llpnt and urpnt)
  ClipPoints(0) = llpnt(0): ClipPoints(1) = llpnt(1)
  ClipPoints(2) = llpnt(0): ClipPoints(3) = urpnt(1)
  ClipPoints(4) = urpnt(0): ClipPoints(5) = urpnt(1)
  ClipPoints(6) = urpnt(0): ClipPoints(7) = llpnt(1)
  ClipPoints(8) = llpnt(0): ClipPoints(9) = llpnt(1)

'Clip boundary =  user defined (uniform) size
'  Dim Bndsize As Double
'  Bndsize = ThisDrawing.Utility.GetReal("What size boundary would you like?: ")
'
'  ClipPoints(0) = mdpnt(0) - (Bndsize / 2): ClipPoints(1) = mdpnt(1) - (Bndsize / 2)
'  ClipPoints(2) = mdpnt(0) - (Bndsize / 2): ClipPoints(3) = mdpnt(1) + (Bndsize / 2)
'  ClipPoints(4) = mdpnt(0) + (Bndsize / 2): ClipPoints(5) = mdpnt(1) + (Bndsize / 2)
'  ClipPoints(6) = mdpnt(0) + (Bndsize / 2): ClipPoints(7) = mdpnt(1) - (Bndsize / 2)
'  ClipPoints(8) = mdpnt(0) - (Bndsize / 2): ClipPoints(9) = mdpnt(1) + -(Bndsize / 2)
 
     
'Clip the image
 RastImg.ClipBoundary ClipPoints
 
   
'Enable the display of the clip
 RastImg.ClippingEnabled = True
 
 
 'Create Selection Set for Raster
 Dim Sset As AcadSelectionSet
 
 Set Sset = ThisDrawing.SelectionSets.Add("Image")
 Sset.Select acSelectionSetLast
 
 Debug.Print "Selection Set " & "("; Sset.Name; ")" & " was created"
 
 With Sset
 End With
       
 ThisDrawing.SelectionSets.Item("Image").Delete
 

Errorhandler:
   If Err.Description = "File access error" Then
    If MsgBox("Can not find image file") Then
     Exit Sub
    End If
   End If
 
End Sub

Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 19, 2007, 02:55:20 PM
Hey guys,
I am posting the lastest code, but in all due respect; wouldn't the same errors occur on your machines once you have the latest code?

Yes, but its much easier to trouble shoot when we can "SEE" the error instead of relying on you to explain it. (NoOffense but a pic is worth....)
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 19, 2007, 02:57:18 PM
ok, so far I ahve made 2 changes. 1-I hardpathed my imgpath var to c:\ where I put image, No big deal.  2-I am dropping line 1 of

RastImg.Name = Imgname
RastImg.Name = Left(Imgname, Len(Imgname) - 4)

to just have the second line as the first is not helpful
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 19, 2007, 02:57:50 PM
I understand CM but there is no error being generated.
If you pick off the raster, the imageframe will still appear but no image will be visible "unless" you drag the imageframe manually.

Do me a favor CM; try to pick 2 points on your raster; make sure one point is off the raster and please tell me if the same thing happens to you?

It could possibly be a setting that I am not aware of

Thank you,
Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 19, 2007, 03:00:16 PM

Good catch

I probably only need the second one correct?

I def. need the second one as I am trimming off the .tif extension

Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 19, 2007, 03:02:26 PM
OK, so if the image is inserted at a scale of 1 the corner to corner dist is
Delta X = 7.6500,  Delta Y = 11.6033

Why are we inserting it at -8,0,0?

Scaled up 12 times yields
Delta X = 91.8000,  Delta Y = 139.2400 for distances

So is this image in Feet or Inches?  Looks like it should be feet, but we scaled it up so Im not sure now
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 19, 2007, 03:03:34 PM
This also goes back to our early discussion as to why ACAD gives rasters a unique/weird name on insert using VBA

When you manually insert a raster, it will adopt the default file name but you can then change the raster name after it is inserted.

Same with xrefs

This is why we "need" to say
RastImg.Name = Imgname
or
RastImg.Name = Left(Imgname, Len(Imgname) - 4)

Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 19, 2007, 03:04:37 PM
The image is clipped on what ever points we pick, even if off the page.  what you need to do is check the 2 points and make sure they are B/T ins and UR of image
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 19, 2007, 03:05:14 PM
This also goes back to our early discussion as to why ACAD gives rasters a unique/weird name on insert using VBA

When you manually insert a raster, it will adopt the default file name but you can then change the raster name after it is inserted.

Same with xrefs

This is why we "need" to say
RastImg.Name = Imgname
or
RastImg.Name = Left(Imgname, Len(Imgname) - 4)

Mark

yes, but not both.  Just the second is needed
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 19, 2007, 03:07:13 PM
Do a IF LLpnt(0) > ImageIns AND LLpnt(0)< UR(0) then
If LL(1)>ImgIns(1) and LL(1)<UR(1) then
proceed to second point
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 19, 2007, 03:07:56 PM
I moved it over 8' to get it off of 0,0 and to the side of the title block.
After the user does their thing, they can move it to the nec. (5' x 5' square) spot on the tblock.
Once we are certain where this rectangle will permanently reside, then I will make the adjustments.

As far as the scale; it is what my boss asked me to do, so I did it.

I believe it is to bring the image up to feet.

We do work in feet as we are a Civil Firm

Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 19, 2007, 03:08:09 PM
That will help you guarentee the picked points are "on" the raster, not off the pic
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 19, 2007, 03:12:10 PM
Just out of curiousity, what are the dims of x and y on your image before its clipped?  is it close to the numbers I posted above?  I just measured the dist between 2 streets, and its like 2 units, so are we dealing with a scaled up scaled raster?
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 19, 2007, 03:12:54 PM
The grid measures ~10x13
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 19, 2007, 03:37:14 PM

CM

I am not sure where you are going with that method?

I like the idea of grabbing the height and width of the raster on insert, then we can say:

Code: [Select]
If llpnt + urpnt > then The height + width of the inserted raster x The scale
 Then What do you think?
End If

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 19, 2007, 03:40:18 PM

Ok the raster that I e-mailed you is the unscaled version.
Yes we are scaling that raster up by 12

Mark

I am also trying to fugure something out in Excel VBA AHHHHHHHHHHHH


LOL

Mark

Title: Re: Clip Boundaries for a Raster
Post by: ML on November 19, 2007, 03:40:57 PM

Oh yes,

You have the exact same distance on the raster that I get

Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 19, 2007, 05:23:45 PM
So basically, what I see is that we need to make sure LL and UR points are ON the raster, regardless of the size of the clip window, and if not, reprompt for new points.  I'll try to work something up for that tomorrow
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 09:32:29 AM

Yes sir

Actually the user needs to make sure they pick on the raster but yes, you got it.
We need to account for the fact that they did not.

It sounds like you are on the right track exactly.

There is no hurry my friend. It is just an added bonus, nice to have type thing

Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 10:54:06 AM
ML, give this a shot, pick everywhere you can think of.  The msgboxs will come out of the finished code, just there for testing purposes.  Also, you will need to edit the image name and path b/c I hardcoded mine
Code: [Select]
Option Explicit
Public Sub InstRast()

      Dim Imgpth As String
      Dim Imgname As String
      Dim InsertPnt(0 To 2) As Double, scalefactor As Double, RotAngle As Double
      Dim RastImg As AcadRasterImage
      ThisDrawing.ActiveSpace = acPaperSpace

[color=red]      Imgpth = "c:\"
      Imgname = "FtWashington600.tif"[/color]

      InsertPnt(0) = 0#: InsertPnt(1) = 0#: InsertPnt(2) = 0#
      scalefactor = 1
      RotAngle = 0

      On Error GoTo Errorhandler
      Set RastImg = ThisDrawing.PaperSpace.AddRaster(Imgpth & Imgname, InsertPnt, scalefactor, RotAngle)

      'RastImg.Name = Imgname
      RastImg.Name = Left(Imgname, Len(Imgname) - 4)

      'RastImg.scalefactor = 1
      RastImg.scalefactor = 12


      'Move Points
      Dim MPointN(0 To 2) As Double      'Negative
      Dim MPointP(0 To 2) As Double      'Positive
      MPointN(0) = 8: MPointN(1) = 0: MPointN(2) = 0
      MPointP(0) = 0: MPointP(1) = 0: MPointP(2) = 0

      'Move Raster
      RastImg.Move MPointN, MPointP



      [color=red]Dim ImgUR(2) As Double
      ImgUR(0) = RastImg.Origin(0) + RastImg.ImageWidth: ImgUR(1) = RastImg.Origin(1) + RastImg.ImageHeight: ImgUR(2) = 0[/color]


      Dim llpnt As Variant      'lower left point
      Dim urpnt As Variant      'upper right point
      Dim mdpnt(0 To 2) As Double
      Dim ClipPoints(0 To 9) As Double






PickPoints:
      With ThisDrawing.Utility
            llpnt = .GetPoint(, vbCrLf & "Select Lower Left Point: ")
            urpnt = .GetPoint(, vbCrLf & "Select Upper Right Point: ")
      End With


    [color=red]  If llpnt(0) > RastImg.Origin(0) And llpnt(0) < ImgUR(0) Then
            If llpnt(1) > RastImg.Origin(1) And llpnt(1) < ImgUR(1) Then
                  If urpnt(0) > RastImg.Origin(0) And urpnt(0) < ImgUR(0) Then
                        If urpnt(1) > RastImg.Origin(1) And urpnt(1) < ImgUR(1) Then
                              MsgBox "Good picks"
                        Else
                              MsgBox "Please repick inside Raster IMage"
                              GoTo PickPoints
                        End If
                  Else
                        MsgBox "Please repick inside Raster IMage"
                        GoTo PickPoints
                  End If
            Else
                  MsgBox "Please repick inside Raster IMage"
                  GoTo PickPoints
            End If
      Else
            MsgBox "Please repick inside Raster IMage"
            GoTo PickPoints
      End If
[/color]





      mdpnt(0) = (llpnt(0) + urpnt(0)) / 2      'Midpoint (X) = (The far left picked point + the far right picked point) / 2
      mdpnt(1) = (llpnt(1) + urpnt(1)) / 2      'Midpoint (Y) = (The far bottom picked point + the far top picked point) / 2
      mdpnt(2) = 0



      'FINITE
      'Create a 5 x 5 clip boundary
      '  clipPoints(0) = 0: clipPoints(1) = 0
      '  clipPoints(2) = 0: clipPoints(3) = 5
      '  clipPoints(4) = 5: clipPoints(5) = 5
      '  clipPoints(6) = 5: clipPoints(7) = 0
      '  clipPoints(8) = 0: clipPoints(9) = 0

      'Clip boundary = 2.5 from the mdpnt of the raster's picked points to the boundary coords.
      'ClipPoints(0) = mdpnt(0) - 2.5: ClipPoints(1) = mdpnt(1) - 2.5
      'ClipPoints(2) = mdpnt(0) - 2.5: ClipPoints(3) = mdpnt(1) + 2.5
      'ClipPoints(4) = mdpnt(0) + 2.5: ClipPoints(5) = mdpnt(1) + 2.5
      'ClipPoints(6) = mdpnt(0) + 2.5: ClipPoints(7) = mdpnt(1) - 2.5
      'ClipPoints(8) = mdpnt(0) - 2.5: ClipPoints(9) = mdpnt(1) + -2.5

      'DYNAMIC
      'Clip boundary = picked points (llpnt and urpnt)
      ClipPoints(0) = llpnt(0): ClipPoints(1) = llpnt(1)
      ClipPoints(2) = llpnt(0): ClipPoints(3) = urpnt(1)
      ClipPoints(4) = urpnt(0): ClipPoints(5) = urpnt(1)
      ClipPoints(6) = urpnt(0): ClipPoints(7) = llpnt(1)
      ClipPoints(8) = llpnt(0): ClipPoints(9) = llpnt(1)

      'Clip boundary =  user defined (uniform) size
      '  Dim Bndsize As Double
      '  Bndsize = ThisDrawing.Utility.GetReal("What size boundary would you like?: ")
      '
      '  ClipPoints(0) = mdpnt(0) - (Bndsize / 2): ClipPoints(1) = mdpnt(1) - (Bndsize / 2)
      '  ClipPoints(2) = mdpnt(0) - (Bndsize / 2): ClipPoints(3) = mdpnt(1) + (Bndsize / 2)
      '  ClipPoints(4) = mdpnt(0) + (Bndsize / 2): ClipPoints(5) = mdpnt(1) + (Bndsize / 2)
      '  ClipPoints(6) = mdpnt(0) + (Bndsize / 2): ClipPoints(7) = mdpnt(1) - (Bndsize / 2)
      '  ClipPoints(8) = mdpnt(0) - (Bndsize / 2): ClipPoints(9) = mdpnt(1) + -(Bndsize / 2)


      'Clip the image
      RastImg.ClipBoundary ClipPoints


      'Enable the display of the clip
      RastImg.ClippingEnabled = True


      'Create Selection Set for Raster
      Dim Sset As AcadSelectionSet

      Set Sset = ThisDrawing.SelectionSets.Add("Image")
      Sset.Select acSelectionSetLast

      Debug.Print "Selection Set " & "("; Sset.Name; ")" & " was created"

      With Sset
      End With

      ThisDrawing.SelectionSets.Item("Image").Delete


Errorhandler:
      If Err.Description = "File access error" Then
            If MsgBox("Can not find image file") Then
                  Exit Sub
            End If
      End If

End Sub
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 10:55:49 AM
Also you will need to remove the COLOR code from above to make it work.  I highlighted (DUH) the parts I changed
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 10:57:35 AM
This brings up a good question for you guys, how to NOT use the GoTo as I know its the bain of good programming.  I have seen a way to not use it, but I just cant remember where it was.  Maybe 808 remembers, cuz I think he gave it to me
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 20, 2007, 11:57:21 AM
This brings up a good question for you guys, how to NOT use the GoTo as I know its the bain of good programming.  I have seen a way to not use it, but I just cant remember where it was.  Maybe 808 remembers, cuz I think he gave it to me
I vaguely remember what you're talking about but not in detail.  I'll try to remember.  Pretty crazy busy this week though.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 12:26:57 PM

I'm not so sure, even though I would never claim to be a great programmer (or even formally trained) by any stretch however I have been using Go to for a longtime and it has always been a reliable source for me.

I did notice that you are using it 4 times, in which case I may consider having a separate Sub for The Go to which is only the Pickpoints in this case; so, do we, don't we?

Is calling a sub 4 possible times any better or different then using Go to 4 times ????

I just tried your code CM,  it seems to be working real well; I do need to put it through some more tests.

That is cool that there is a Raster.origin method
So far it looks good

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 12:29:02 PM
CM

The color coding did not effect the code at all; nor should it.
When copying and pasting, we are only grabbing the text, not the text formatting.
Therefore what you did is fine :)

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 12:30:02 PM

I have an easy answer to The Goto question;
It is called Google :)

Let me see what I can find

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 12:59:15 PM

CM

Good Job Man! It looks like it is working really well.
I might clean it up a bit and do a few things but you did a nice job.

It is definitely working as i hoped, thank you!

Oh, here is some bonus code if you want it?
I like to see these little things, it helps me to know what is going on.


Code: [Select]
'These coords are prior to picking your points
 Debug.Print "Raster Origin X = " & RastImg.Origin(0)
 Debug.Print "Raster Origin Y = " & RastImg.Origin(1)
 Debug.Print "Raster Width = " & RastImg.ImageWidth
 Debug.Print "Raster Height = " & RastImg.ImageHeight

I placed it under your

Code: [Select]
Dim ImgUR(2) As Double
ImgUR(0) = RastImg.Origin(0) + RastImg.ImageWidth: ImgUR(1) = RastImg.Origin(1) + RastImg.ImageHeight: ImgUR(2) = 0

code

Mark

Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 01:23:14 PM
I did notice that you are using it 4 times, in which case I may consider having a separate Sub for The Go to which is only the Pickpoints in this case; so, do we, don't we?  Is calling a sub 4 possible times any better or different then using Go to 4 times ????
we are not calling it 4 times, only once IF one of the X or Y values falls outside the image boundary
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 01:26:42 PM
Yes, that is true

Sorry

Did you figure out the alternative to Go To?

We could put

Code: [Select]
With ThisDrawing.Utility
  llpnt = .GetPoint(, vbCrLf & "Select Lower Left Point: ")
   urpnt = .GetPoint(, vbCrLf & "Select Upper Right Point: ")
End With

in place of each Go To but does that make anymore sense?

Maybe?

Not sure

Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 01:57:39 PM
we cant put that in instead of the goto b/c if that second set of picks were also bogus, we would be past the checking of coords, and it wouldn't know it
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 02:01:53 PM

I'm sorry
I have been trying to study your code but I keep getting distracted :)

Let me take a closer look

Mark
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 20, 2007, 02:07:06 PM
OK, I just put all of about 30 seconds thought into this but what about somefin like
[psueudocode]
do until pntsValid
With ThisDrawing.Utility
  llpnt = .GetPoint(, vbCrLf & "Select Lower Left Point: ")
   urpnt = .GetPoint(, vbCrLf & "Select Upper Right Point: ")
End With
      If llpnt(0) > RastImg.Origin(0) And llpnt(0) < ImgUR(0) Then
            If llpnt(1) > RastImg.Origin(1) And llpnt(1) < ImgUR(1) Then
                  If urpnt(0) > RastImg.Origin(0) And urpnt(0) < ImgUR(0) Then
                        If urpnt(1) > RastImg.Origin(1) And urpnt(1) < ImgUR(1) Then
                              pntsvalid = true
                        Else
                           ThisDrawing.utility.prompt "At least one of those points was teh suck." & vbcrlf
                        end if
                  end if
            end if
      end if
loop[/psuedocode]
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 02:29:35 PM
I like the idea, let me code that up
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 03:06:38 PM
This is what I came up with.  Comments to improve it welcome
Code: [Select]
PickPoints:
      '      With ThisDrawing.Utility
      '            llpnt = .GetPoint(, vbCrLf & "Select Lower Left Point: ")
      '            urpnt = .GetPoint(, vbCrLf & "Select Upper Right Point: ")
      '      End With
      Dim Check As Boolean
      Check = False
      Do While Check = False
            With ThisDrawing.Utility
                  llpnt = .GetPoint(, vbCrLf & "Select Lower Left Point: ")
                  urpnt = .GetPoint(, vbCrLf & "Select Upper Right Point: ")
            End With
            If llpnt(0) > RastImg.Origin(0) And llpnt(0) < ImgUR(0) Then
                  If llpnt(1) > RastImg.Origin(1) And llpnt(1) < ImgUR(1) Then
                        If urpnt(0) > RastImg.Origin(0) And urpnt(0) < ImgUR(0) Then
                              If urpnt(1) > RastImg.Origin(1) And urpnt(1) < ImgUR(1) Then
                                    Check = True
                              Else
                                    MsgBox "Please repick inside Raster IMage"
                                    Check = False
                              End If
                        Else
                              MsgBox "Please repick inside Raster IMage"
                              Check = False
                        End If
                  Else
                        MsgBox "Please repick inside Raster IMage"
                        Check = False
                  End If
            Else
                  MsgBox "Please repick inside Raster IMage"
                  Check = False
            End If
      Loop
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 03:07:40 PM
I left the PickPoints: and the old pick points there while testing.  Those can be removed from final code
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 03:28:17 PM

CM

It is prompting me twice for my points with The Boolean Method

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 04:00:35 PM

CM,

Check this out
I modified your code slightly
Hope you don't mind
It makes a lot more sense to me now
Mark

Code: [Select]
If llpnt(0) > RastImg.Origin(0) And llpnt(0) < RastImg.ImageWidth Then
      If llpnt(1) > RastImg.Origin(1) And llpnt(1) < RastImg.ImageHeight Then
       If urpnt(0) > RastImg.Origin(0) And urpnt(0) < RastImg.ImageWidth Then
        If urpnt(1) > RastImg.Origin(1) And urpnt(1) < RastImg.ImageHeight Then
         MsgBox "Good picks"
        Else
         MsgBox "Please repick inside Raster IMage"
         GoTo PickPoints
        End If
       Else
        MsgBox "Please repick inside Raster IMage"
        GoTo PickPoints
       End If
      Else
       MsgBox "Please repick inside Raster IMage"
       GoTo PickPoints
      End If
     Else
      MsgBox "Please repick inside Raster IMage"
      GoTo PickPoints
    End If
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 04:44:22 PM
This gets rid of the goto s
Code: [Select]
Option Explicit
Public Sub InstRast()

      Dim Imgpth As String
      Dim Imgname As String
      Dim InsertPnt(0 To 2) As Double, scalefactor As Double, RotAngle As Double
      Dim RastImg As AcadRasterImage
      ThisDrawing.ActiveSpace = acPaperSpace
      Imgpth = "c:\"
      Imgname = "FtWashington600.tif"
      InsertPnt(0) = 0#: InsertPnt(1) = 0#: InsertPnt(2) = 0#
      scalefactor = 1
      RotAngle = 0
      On Error GoTo Errorhandler
      Set RastImg = ThisDrawing.PaperSpace.AddRaster(Imgpth & Imgname, InsertPnt, scalefactor, RotAngle)
      RastImg.Name = Left(Imgname, Len(Imgname) - 4)
      RastImg.scalefactor = 12
      'Move Points
      Dim MPointN(0 To 2) As Double      'Negative
      Dim MPointP(0 To 2) As Double      'Positive
      MPointN(0) = 8: MPointN(1) = 0: MPointN(2) = 0
      MPointP(0) = 0: MPointP(1) = 0: MPointP(2) = 0
      'Move Raster
      RastImg.Move MPointN, MPointP
      Dim ImgUR(2) As Double
      ImgUR(0) = RastImg.Origin(0) + RastImg.ImageWidth: ImgUR(1) = RastImg.Origin(1) + RastImg.ImageHeight: ImgUR(2) = 0
      Dim llpnt As Variant      'lower left point
      Dim urpnt As Variant      'upper right point
      Dim mdpnt(0 To 2) As Double
      Dim ClipPoints(0 To 9) As Double
      Dim Check As Boolean
      Check = False
      Do While Check = False
            llpnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Select Lower Left Point: ")
            urpnt = ThisDrawing.Utility.GetCorner(llpnt, vbCrLf & "Select Upper Right Point: ")
            If llpnt(0) > RastImg.Origin(0) And llpnt(0) < ImgUR(0) Then
                  If llpnt(1) > RastImg.Origin(1) And llpnt(1) < ImgUR(1) Then
                        If urpnt(0) > RastImg.Origin(0) And urpnt(0) < ImgUR(0) Then
                              If urpnt(1) > RastImg.Origin(1) And urpnt(1) < ImgUR(1) Then
                                    Check = True
                              Else
                                    MsgBox "Please repick inside Raster IMage"
                                    Check = False
                              End If
                        Else
                              MsgBox "Please repick inside Raster IMage"
                              Check = False
                        End If
                  Else
                        MsgBox "Please repick inside Raster IMage"
                        Check = False
                  End If
            Else
                  MsgBox "Please repick inside Raster IMage"
                  Check = False
            End If
      Loop
      mdpnt(0) = (llpnt(0) + urpnt(0)) / 2      'Midpoint (X) = (The far left picked point + the far right picked point) / 2
      mdpnt(1) = (llpnt(1) + urpnt(1)) / 2      'Midpoint (Y) = (The far bottom picked point + the far top picked point) / 2
      mdpnt(2) = 0
      'FINITE
      'Create a 5 x 5 clip boundary
      '  clipPoints(0) = 0: clipPoints(1) = 0
      '  clipPoints(2) = 0: clipPoints(3) = 5
      '  clipPoints(4) = 5: clipPoints(5) = 5
      '  clipPoints(6) = 5: clipPoints(7) = 0
      '  clipPoints(8) = 0: clipPoints(9) = 0

      'Clip boundary = 2.5 from the mdpnt of the raster's picked points to the boundary coords.
      'ClipPoints(0) = mdpnt(0) - 2.5: ClipPoints(1) = mdpnt(1) - 2.5
      'ClipPoints(2) = mdpnt(0) - 2.5: ClipPoints(3) = mdpnt(1) + 2.5
      'ClipPoints(4) = mdpnt(0) + 2.5: ClipPoints(5) = mdpnt(1) + 2.5
      'ClipPoints(6) = mdpnt(0) + 2.5: ClipPoints(7) = mdpnt(1) - 2.5
      'ClipPoints(8) = mdpnt(0) - 2.5: ClipPoints(9) = mdpnt(1) + -2.5

      'DYNAMIC
      'Clip boundary = picked points (llpnt and urpnt)
      ClipPoints(0) = llpnt(0): ClipPoints(1) = llpnt(1)
      ClipPoints(2) = llpnt(0): ClipPoints(3) = urpnt(1)
      ClipPoints(4) = urpnt(0): ClipPoints(5) = urpnt(1)
      ClipPoints(6) = urpnt(0): ClipPoints(7) = llpnt(1)
      ClipPoints(8) = llpnt(0): ClipPoints(9) = llpnt(1)

      'Clip boundary =  user defined (uniform) size
      '  Dim Bndsize As Double
      '  Bndsize = ThisDrawing.Utility.GetReal("What size boundary would you like?: ")
      '
      '  ClipPoints(0) = mdpnt(0) - (Bndsize / 2): ClipPoints(1) = mdpnt(1) - (Bndsize / 2)
      '  ClipPoints(2) = mdpnt(0) - (Bndsize / 2): ClipPoints(3) = mdpnt(1) + (Bndsize / 2)
      '  ClipPoints(4) = mdpnt(0) + (Bndsize / 2): ClipPoints(5) = mdpnt(1) + (Bndsize / 2)
      '  ClipPoints(6) = mdpnt(0) + (Bndsize / 2): ClipPoints(7) = mdpnt(1) - (Bndsize / 2)
      '  ClipPoints(8) = mdpnt(0) - (Bndsize / 2): ClipPoints(9) = mdpnt(1) + -(Bndsize / 2)

      'Clip the image
      RastImg.ClipBoundary ClipPoints
      'Enable the display of the clip
      RastImg.ClippingEnabled = True
      'Create Selection Set for Raster
      Dim Sset As AcadSelectionSet
      Set Sset = ThisDrawing.SelectionSets.Add("Image")
      Sset.Select acSelectionSetLast
      Debug.Print "Selection Set " & "("; Sset.Name; ")" & " was created"
      With Sset
      End With
      ThisDrawing.SelectionSets.Item("Image").Delete
Errorhandler:
      If Err.Description = "File access error" Then
            If MsgBox("Can not find image file") Then
                  Exit Sub
            End If
      End If
End Sub
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 04:46:49 PM
Twice?  very interesting.  I just tested and I can do 1 set of picks if I play by the rules.  Of course if I pick anywhere outside the boundary, it will prompt me til I make 2 good picks inside the boundary
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 04:57:59 PM
Code: [Select]
If llpnt(0) > RastImg.Origin(0) And llpnt(0) < RastImg.ImageWidth Then
      If llpnt(1) > RastImg.Origin(1) And llpnt(1) < RastImg.ImageHeight Then

llpnt(1) < RastImg.ImageHeight is only comparing the Y of LLpnt against the height of the image.  Assume image was 10x10 and origin was 60,60,0?
your LL of image is 60,60,0 and UR of image is 70,70,0 right? now if you test a point picked at 65,65,0, your test llpnt(1) < RastImg.ImageHeight
 will fail b/c 65 is not < 10
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 05:01:05 PM
Basically, if your image is ALWAYS inserted at 0,0,0 the code will work b/c image.width and the X value of image.width are equal.  If your image is ever moved from 0,0,0 then you will need to add Image.width + Image.Origin(X)
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 05:04:49 PM
If you copy the code from 4 posts up, and change the hard coded paths only, does it work or crash?  If it crashes, can you F8 thru it and tell me where it crashes.
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 05:10:37 PM
I also made a few more changes highlighted below
Code: [Select]
Option Explicit
Public Sub InstRast()

      Dim Imgpth As String
      Dim Imgname As String
      Dim InsertPnt(0 To 2) As Double, scalefactor As Double, RotAngle As Double
      Dim RastImg As AcadRasterImage
      ThisDrawing.ActiveSpace = acPaperSpace
      Imgpth = "c:\"
      Imgname = "FtWashington600.tif"
      InsertPnt(0) = 0#: InsertPnt(1) = 0#: InsertPnt(2) = 0#
      scalefactor = 1
      RotAngle = 0
      On Error GoTo Errorhandler
      Set RastImg = ThisDrawing.PaperSpace.AddRaster(Imgpth & Imgname, InsertPnt, scalefactor, RotAngle)
      RastImg.Name = Left(Imgname, Len(Imgname) - 4)
      RastImg.scalefactor = 12
      'Move Points
      Dim MPointN(0 To 2) As Double      'Negative
      Dim MPointP(0 To 2) As Double      'Positive
      MPointN(0) = 8: MPointN(1) = 0: MPointN(2) = 0
      MPointP(0) = 0: MPointP(1) = 0: MPointP(2) = 0
      'Move Raster
      RastImg.Move MPointN, MPointP
      Dim ImgUR(2) As Double
      ImgUR(0) = RastImg.Origin(0) + RastImg.ImageWidth: ImgUR(1) = RastImg.Origin(1) + RastImg.ImageHeight: ImgUR(2) = 0
      Dim llpnt As Variant      'lower left point
      Dim urpnt As Variant      'upper right point
      Dim mdpnt(0 To 2) As Double
      Dim ClipPoints(0 To 9) As Double
      Dim Check As Boolean
      Check = False
      Do While Check = False
[color=red]            llpnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Select Lower Left Point: ")
            urpnt = ThisDrawing.Utility.GetCorner(llpnt, vbCrLf & "Select Upper Right Point: ")[/color]
            If llpnt(0) > RastImg.Origin(0) And llpnt(0) < ImgUR(0) Then
                  If llpnt(1) > RastImg.Origin(1) And llpnt(1) < ImgUR(1) Then
                        If urpnt(0) > RastImg.Origin(0) And urpnt(0) < ImgUR(0) Then
                              If urpnt(1) > RastImg.Origin(1) And urpnt(1) < ImgUR(1) Then
                                    Check = True
                              Else
                                    MsgBox "Please repick inside Raster IMage"
                                    Check = False
                              End If
                        Else
                              MsgBox "Please repick inside Raster IMage"
                              Check = False
                        End If
                  Else
                        MsgBox "Please repick inside Raster IMage"
                        Check = False
                  End If
            Else
                  MsgBox "Please repick inside Raster IMage"
                  Check = False
            End If
      Loop
      mdpnt(0) = (llpnt(0) + urpnt(0)) / 2      'Midpoint (X) = (The far left picked point + the far right picked point) / 2
      mdpnt(1) = (llpnt(1) + urpnt(1)) / 2      'Midpoint (Y) = (The far bottom picked point + the far top picked point) / 2
      mdpnt(2) = 0
      'FINITE
      'Create a 5 x 5 clip boundary
      '  clipPoints(0) = 0: clipPoints(1) = 0
      '  clipPoints(2) = 0: clipPoints(3) = 5
      '  clipPoints(4) = 5: clipPoints(5) = 5
      '  clipPoints(6) = 5: clipPoints(7) = 0
      '  clipPoints(8) = 0: clipPoints(9) = 0

      'Clip boundary = 2.5 from the mdpnt of the raster's picked points to the boundary coords.
      'ClipPoints(0) = mdpnt(0) - 2.5: ClipPoints(1) = mdpnt(1) - 2.5
      'ClipPoints(2) = mdpnt(0) - 2.5: ClipPoints(3) = mdpnt(1) + 2.5
      'ClipPoints(4) = mdpnt(0) + 2.5: ClipPoints(5) = mdpnt(1) + 2.5
      'ClipPoints(6) = mdpnt(0) + 2.5: ClipPoints(7) = mdpnt(1) - 2.5
      'ClipPoints(8) = mdpnt(0) - 2.5: ClipPoints(9) = mdpnt(1) + -2.5

      'DYNAMIC
      'Clip boundary = picked points (llpnt and urpnt)
      ClipPoints(0) = llpnt(0): ClipPoints(1) = llpnt(1)
      ClipPoints(2) = llpnt(0): ClipPoints(3) = urpnt(1)
      ClipPoints(4) = urpnt(0): ClipPoints(5) = urpnt(1)
      ClipPoints(6) = urpnt(0): ClipPoints(7) = llpnt(1)
      ClipPoints(8) = llpnt(0): ClipPoints(9) = llpnt(1)

      'Clip boundary =  user defined (uniform) size
      '  Dim Bndsize As Double
      '  Bndsize = ThisDrawing.Utility.GetReal("What size boundary would you like?: ")
      '
      '  ClipPoints(0) = mdpnt(0) - (Bndsize / 2): ClipPoints(1) = mdpnt(1) - (Bndsize / 2)
      '  ClipPoints(2) = mdpnt(0) - (Bndsize / 2): ClipPoints(3) = mdpnt(1) + (Bndsize / 2)
      '  ClipPoints(4) = mdpnt(0) + (Bndsize / 2): ClipPoints(5) = mdpnt(1) + (Bndsize / 2)
      '  ClipPoints(6) = mdpnt(0) + (Bndsize / 2): ClipPoints(7) = mdpnt(1) - (Bndsize / 2)
      '  ClipPoints(8) = mdpnt(0) - (Bndsize / 2): ClipPoints(9) = mdpnt(1) + -(Bndsize / 2)

      'Clip the image
      RastImg.ClipBoundary ClipPoints
      'Enable the display of the clip
      RastImg.ClippingEnabled = True
      'Create Selection Set for Raster
      Dim Sset As AcadSelectionSet
      Set Sset = ThisDrawing.SelectionSets.Add("Image")
      Sset.Select acSelectionSetLast
      Debug.Print "Selection Set " & "("; Sset.Name; ")" & " was created"
      With Sset
      End With
      ThisDrawing.SelectionSets.Item("Image").Delete
Errorhandler:
      If Err.Description = "File access error" Then
            If MsgBox("Can not find image file") Then
                  Exit Sub
            End If
      End If
End Sub
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 05:12:21 PM
I got rid of the extra 2 lines from the With, and changed to GetCorner so the user can "see" where they are picking
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 05:30:08 PM

CM,

I just copied the whole thing down from your post
All seems to be working really well now

Very nice job!

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 05:31:44 PM

I'm sorry?

What 2 withs?

Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 05:34:10 PM
Code: [Select]
[color=red]With ThisDrawing.Utility[/color]
  llpnt = .GetPoint(, vbCrLf & "Select Lower Left Point: ")
   urpnt = .GetPoint(, vbCrLf & "Select Upper Right Point: ")
[color=red]End With[/color]
became
Code: [Select]
            llpnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Select Lower Left Point: ")
            urpnt = ThisDrawing.Utility.[color=red]GetCorner(llpnt[/color], vbCrLf & "Select Upper Right Point: ")
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 20, 2007, 05:35:04 PM
I just eliminated 2 lines of code, the first was the start of the With statement, the second was the EndWith
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 05:39:34 PM

Very good idea!

That works really well!

CM, have you notice that if you pick on the upper right endpoint that you get an error?

The endpoint should be considered part of the image

Mark
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 20, 2007, 06:14:16 PM
That's because it testing for </> not =</=>
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 06:19:09 PM

CM

Please correct me if I am wrong:

Can't we get away with this?

Code: [Select]
Do While Check = False
      llpnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Select Lower Left Point: ")
      urpnt = ThisDrawing.Utility.GetCorner(llpnt, vbCrLf & "Select Upper Right Point: ")
     
       If llpnt(0) > RastImg.Origin(0) And llpnt(0) < ImgUR(0) Then
        If llpnt(1) > RastImg.Origin(1) And llpnt(1) < ImgUR(1) Then
         If urpnt(0) > RastImg.Origin(0) And urpnt(0) < ImgUR(0) Then
          If urpnt(1) > RastImg.Origin(1) And urpnt(1) < ImgUR(1) Then
           Pnts = True
          Else
           MsgBox "Pick points inside the raster image"
           Check = False
         End If
        End If
       End If
      End If
 Loop

I would think we only need these lines of code
Code: [Select]
Else
 MsgBox "Pick points inside the raster image"
 Pnts = False

Once ?

Mark



Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 06:19:56 PM

Sorry I meant check = False
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 06:21:59 PM

Bob

So you are saying 
If I put the = sign in, then that will take care of the endpoint problem?

Mark
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 20, 2007, 06:30:53 PM



I would think we only need these lines of code
Code: [Select]
Else
 MsgBox "Pick points inside the raster image"
 Pnts = False

Once ?

Mark




Nope.  If you only have it once, it will only work if it fails in that place.  You need to account for failure on each of you IF statements.


Bob

So you are saying 
If I put the = sign in, then that will take care of the endpoint problem?

Mark
More like
Code: [Select]
       If llpnt(0) > RastImg.Origin(0) And llpnt(0) < ImgUR(0) ElseIf llpnt(0) = RastImg.Origin(0) And llpnt(0) = ImgUR(0) Then
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 06:32:47 PM

Yes Bob you were correct, great catch!

CM,

You need the = sign in your operations in case the user picks on an endpoint in which case the condition would be <> or = to the far (end) points else (as is) you get an error if they pick an endpoint.

Code: [Select]
If llpnt(0) >= RastImg.Origin(0) And llpnt(0) <= ImgUR(0) Then
 If llpnt(1) >= RastImg.Origin(1) And llpnt(1) <= ImgUR(1) Then
  If urpnt(0) >= RastImg.Origin(0) And urpnt(0) <= ImgUR(0) Then
   If urpnt(1) >= RastImg.Origin(1) And urpnt(1) <= ImgUR(1) Then

Also, I did see why we need the message 3 times in case either one of those conditions are not met.

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 06:35:23 PM

Bob

You beat me to the draw but I think the method I posted works fine too

Please correct me if I am wrong

Thank you

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 06:55:04 PM

One last note guys; then my brain is effectively done for the day.

If you place the selection set code

Code: [Select]
'Create Selection Set for Raster
  Dim Sset As AcadSelectionSet
     
  Set Sset = ThisDrawing.SelectionSets.Add("Image")
  Sset.Select acSelectionSetLast
     
  Debug.Print "Selection Set " & "("; Sset.Name; ")" & " was created"
     
  With Sset
   'Do whatever you'd like here
  End With

Right after CM's loop but "before" the clip boundaries are created, it makes the undo feature in ACAD very effective.

Still, delete the selection set

Code: [Select]
ThisDrawing.SelectionSets.Item("Image").Delete

Right before the Error handler code, unless of course you need it for some reason.

Even though the selection set is deleted, it is still looked at as the last selected item in ACAD and if the user wanted to undo the clip, just do an undo.

Pretty cool

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 07:01:10 PM

I thought it might help to post the code as it stands right now so that we can all be on the same page

CM, I changed a few minor things, just the formatting to the way I use to having it and may be a variable name but all of your methods are exactly the same. I added the = sign in your conditions also.
Please take note of where I placed the selection set code also
Mark

Code: [Select]
Public Sub InstRast()

     Dim RastImg As AcadRasterImage
     Dim Imgpth As String
     Dim Imgname As String
     
     Dim InsertPnt(0 To 2) As Double, scalefactor As Double, RotAngle As Double
     
     ThisDrawing.ActiveSpace = acPaperSpace
     
     Imgpth = ThisDrawing.Path & "\"
     Imgname = "FtWashington600.tif"
     
     InsertPnt(0) = 0#: InsertPnt(1) = 0#: InsertPnt(2) = 0#
     scalefactor = 1
     RotAngle = 0
     
     On Error GoTo Errorhandler
     Set RastImg = ThisDrawing.PaperSpace.AddRaster(Imgpth & Imgname, InsertPnt, scalefactor, RotAngle)
     
     RastImg.Name = Left(Imgname, Len(Imgname) - 4)
     RastImg.scalefactor = 12
     
    'Move Points
     Dim MPointN(0 To 2) As Double 'Negative
     Dim MPointP(0 To 2) As Double 'Positive
     MPointN(0) = 8: MPointN(1) = 0: MPointN(2) = 0
     MPointP(0) = 0: MPointP(1) = 0: MPointP(2) = 0
     
    'Move Raster
     RastImg.Move MPointN, MPointP
     
     Dim ImgUR(2) As Double
     
     ImgUR(0) = RastImg.Origin(0) + RastImg.ImageWidth
     ImgUR(1) = RastImg.Origin(1) + RastImg.ImageHeight
     ImgUR(2) = 0
     
     Dim llpnt As Variant 'lower left point
     Dim urpnt As Variant 'upper right point
     Dim mdpnt(0 To 2) As Double
     Dim ClipPoints(0 To 9) As Double
     
    'Getpoints on raster and check if the user picks within the raster boundaries
     Dim Pnts As Boolean
               
     Pnts = False
     
     Do While Pnts = False
      llpnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Select Lower Left Point: ")
      urpnt = ThisDrawing.Utility.GetCorner(llpnt, vbCrLf & "Select Upper Right Point: ")
     
       If llpnt(0) >= RastImg.Origin(0) And llpnt(0) <= ImgUR(0) Then
        If llpnt(1) >= RastImg.Origin(1) And llpnt(1) <= ImgUR(1) Then
         If urpnt(0) >= RastImg.Origin(0) And urpnt(0) <= ImgUR(0) Then
          If urpnt(1) >= RastImg.Origin(1) And urpnt(1) <= ImgUR(1) Then
           Pnts = True
          Else
           MsgBox "Pick points inside the raster image"
           Pnts = False
          End If
         Else
          MsgBox "Pick points inside the raster image"
          Pnts = False
         End If
        Else
         MsgBox "Pick points inside the raster image"
         Pnts = False
        End If
       Else
        MsgBox "Pick points inside the raster image"
        Pnts = False
       End If
      Loop
     
      mdpnt(0) = (llpnt(0) + urpnt(0)) / 2 'Midpoint (X) = (The far left picked point + the far right picked point) / 2
      mdpnt(1) = (llpnt(1) + urpnt(1)) / 2 'Midpoint (Y) = (The far bottom picked point + the far top picked point) / 2
      mdpnt(2) = 0
     
     'Create Selection Set for Raster
      Dim Sset As AcadSelectionSet
     
      Set Sset = ThisDrawing.SelectionSets.Add("Image")
      Sset.Select acSelectionSetLast
     
      Debug.Print "Selection Set " & "("; Sset.Name; ")" & " was created"
     
      With Sset
      End With
           
         
     'FINITE
     'Create a 5 x 5 clip boundary
      'clipPoints(0) = 0: clipPoints(1) = 0
      'clipPoints(2) = 0: clipPoints(3) = 5
      'clipPoints(4) = 5: clipPoints(5) = 5
      'clipPoints(6) = 5: clipPoints(7) = 0
      'clipPoints(8) = 0: clipPoints(9) = 0

     'Clip boundary = 2.5 from the mdpnt of the raster's picked points to the boundary coords.
      ClipPoints(0) = mdpnt(0) - 2.5: ClipPoints(1) = mdpnt(1) - 2.5
      ClipPoints(2) = mdpnt(0) - 2.5: ClipPoints(3) = mdpnt(1) + 2.5
      ClipPoints(4) = mdpnt(0) + 2.5: ClipPoints(5) = mdpnt(1) + 2.5
      ClipPoints(6) = mdpnt(0) + 2.5: ClipPoints(7) = mdpnt(1) - 2.5
      ClipPoints(8) = mdpnt(0) - 2.5: ClipPoints(9) = mdpnt(1) + -2.5

     'DYNAMIC
     'Clip boundary = picked points (llpnt and urpnt)
'      ClipPoints(0) = llpnt(0): ClipPoints(1) = llpnt(1)
'      ClipPoints(2) = llpnt(0): ClipPoints(3) = urpnt(1)
'      ClipPoints(4) = urpnt(0): ClipPoints(5) = urpnt(1)
'      ClipPoints(6) = urpnt(0): ClipPoints(7) = llpnt(1)
'      ClipPoints(8) = llpnt(0): ClipPoints(9) = llpnt(1)

     'Clip boundary =  user defined (uniform) size
      'Dim Bndsize As Double
      'Bndsize = ThisDrawing.Utility.GetReal("What size boundary would you like?: ")
     
      'ClipPoints(0) = mdpnt(0) - (Bndsize / 2): ClipPoints(1) = mdpnt(1) - (Bndsize / 2)
      'ClipPoints(2) = mdpnt(0) - (Bndsize / 2): ClipPoints(3) = mdpnt(1) + (Bndsize / 2)
      'ClipPoints(4) = mdpnt(0) + (Bndsize / 2): ClipPoints(5) = mdpnt(1) + (Bndsize / 2)
      'ClipPoints(6) = mdpnt(0) + (Bndsize / 2): ClipPoints(7) = mdpnt(1) - (Bndsize / 2)
      'ClipPoints(8) = mdpnt(0) - (Bndsize / 2): ClipPoints(9) = mdpnt(1) + -(Bndsize / 2)

    'Clip the image
      RastImg.ClipBoundary ClipPoints
     
    'Enable the display of the clip
      RastImg.ClippingEnabled = True
     

      ThisDrawing.SelectionSets.Item("Image").Delete
     
     
Errorhandler:
      If Err.Description = "File access error" Then
       If MsgBox("Can not find image file") Then
        Exit Sub
       End If
      End If
End Sub

Title: Re: Clip Boundaries for a Raster
Post by: ML on November 20, 2007, 07:11:21 PM

OK
I stand corrected by myself  :-(
The selection set is not why the undo feature is working; it works regardless. DALP!
Of course there may be other reasons to keep it in there; it is completely up to your guys

Kirk out

Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 21, 2007, 09:01:53 AM
Wow, you guys stayed late last night.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 21, 2007, 09:12:43 AM

Yes sir

No rest for the weary



Title: Re: Clip Boundaries for a Raster
Post by: ML on November 21, 2007, 10:58:22 AM

Hey guys,
I know this is a little bit obsessive but I am just curious;
If I select the lower left (llpnt) and the upper right (urpnt) points of the raster,
I have the results printing to the Immediate Window -->
Take note of the results, which are the correct points
Code: [Select]
'Return picked points
  Debug.Print "The lower left picked points = " & llpnt(0) & ", " & llpnt(1)
  Debug.Print "The upper right picked points = " & urpnt(0) & ", " & urpnt(1)

'From Immediate Window
The lower left picked points = -8, 0
The upper right picked points = -0.3500000000012, 11.6033333333333

However, if I use the code that Bob gave me:
Code: [Select]
Sub Getpoints()

Dim Pnt As Variant
Dim i As Integer

On Error GoTo NoPoint

Do
  Pnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Pnt" & i)
  Debug.Print "Pnt" & i & ": "; Pnt(0) & "," & Pnt(1)
  i = i + 1
Loop

NoPoint:
  If Err.Number Then
   Err.Clear
   Exit Sub
  End If
End Sub
To get my points;
The lower left points (llpnt) are being returned as
-8,-1.34354333214404E-15

Does anybody know why this is happening?

In Bob's code, do we need to have a round function?
In both modules; the same exact method is being used but the results are different?

Mark


Title: Re: Clip Boundaries for a Raster
Post by: ML on November 21, 2007, 11:25:34 AM

In this example:

Code: [Select]
Sub Getpoints_xymid()

Dim llpnt As Variant 'lower left point
Dim urpnt As Variant 'upper right point
Dim xpnts As Variant
Dim ypnts As Variant
Dim mdpnt(0 To 2) As Double

With ThisDrawing.Utility
 llpnt = .GetPoint(, vbCrLf & "Select Lower Left Point: ")
 urpnt = .GetCorner(llpnt, vbCrLf & "Select Upper Right Point: ")
End With

mdpnt(0) = (llpnt(0) + urpnt(0)) / 2 'Midpoint (X) = (The far left picked point + the far right picked point) / 2
mdpnt(1) = (llpnt(1) + urpnt(1)) / 2 'Midpoint (Y) = (The far bottom picked point + the far top picked point) / 2
mdpnt(2) = 0
xpnts = llpnt(0) + urpnt(0)
ypnts = llpnt(1) + urpnt(1)


Debug.Print "Lower left points: "; llpnt(0) & "," & llpnt(1)
Debug.Print "Upper right points: "; urpnt(0) & "," & urpnt(1)
Debug.Print "Midpoints: "; mdpnt(0) & "," & mdpnt(1) & vbCrLf
Debug.Print "Xpoints (0) + (1) = "; xpnts
Debug.Print "Ypoints (0) + (1) = "; ypnts

End Sub

Check out the results:

Lower left points: -8,-1.34354333214404E-15
Upper right points: -0.3500000000012,11.6033333333333
Midpoints: -4.1750000000006,5.80166666666667

Xpoints (0) + (1) = -8.3500000000012
Ypoints (0) + (1) =  11.6033333333333

The Y Points are being calculated correctly as Xpoint (1) should = 0
Still, look here, look at Lower left points:
It is giving me -1.34354333214404E-15 instead of 0
WTF!

The question is why?

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 21, 2007, 11:32:10 AM

Sorry guys

The code should read like this

Code: [Select]
Debug.Print "Lower left points: "; llpnt(0) & "," & llpnt(1)
Debug.Print "Upper right points: "; urpnt(0) & "," & urpnt(1) & vbCrLf
Debug.Print "Xpoints (0) + (0) = "; xpnts
Debug.Print "Ypoints (1) + (1) = "; ypnts & vbCrLf
Debug.Print "Midpoints: "; mdpnt(0) & "," & mdpnt(1)

The correction is:
Xpoints (0) + (0) = "; xpnts
Ypoints (1) + (1) = "; ypnts

Still the prior post does has the correct numbers, it was just the way I was displaying the string (in the immediate window) that was wrong

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 21, 2007, 02:08:32 PM

Hey guys

Just when you thought it was OVER; I have yet one more idea

OK,

If the raster already exists in the drawing, then we can still utilize this code.
I have most of it written
I just need help with the line in red.

Thanks

Mark

Code: [Select]
Sub InstRast3()

Dim RastImg As AcadRasterImage
Dim Obj As AcadObject
Dim Objname As String
 
 
For Each Obj In ThisDrawing.PaperSpace
 If Obj.ObjectName = "AcDbRasterImage" Then
  [color=red]'Objname = 'Need this code[/color]
  Set RastImg = ThisDrawing.PaperSpace.Item(Objname)
 End If
Next Obj
 
 
 Dim ImgLmts(2) As Double
 ImgLmts(0) = RastImg.Origin(0) + RastImg.ImageWidth
 ImgLmts(1) = RastImg.Origin(1) + RastImg.ImageHeight
 ImgLmts(2) = 0
     
 Dim llpnt As Variant 'lower left point
 Dim urpnt As Variant 'upper right point
 Dim mdpnt(0 To 2) As Double
 Dim ClipPoints(0 To 9) As Double
 
'Prompt for pick points on raster and check if the user picks within the raster boundaries
 Dim PntLmts As Boolean
       
 PntLmts = False
 
 Do While PntLmts = False
  llpnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Select Lower Left Point: ")
  urpnt = ThisDrawing.Utility.GetCorner(llpnt, vbCrLf & "Select Upper Right Point: ")
 
   If llpnt(0) >= RastImg.Origin(0) And llpnt(0) <= ImgLmts(0) Then
    If llpnt(1) >= RastImg.Origin(1) And llpnt(1) <= ImgLmts(1) Then
     If urpnt(0) >= RastImg.Origin(0) And urpnt(0) <= ImgLmts(0) Then
      If urpnt(1) >= RastImg.Origin(1) And urpnt(1) <= ImgLmts(1) Then
       PntLmts = True
      Else
       MsgBox "The pick points must be on the raster image " & vbCrLf & _
       "Please try again"
       PntLmts = False
      End If
     Else
      MsgBox "The pick points must be on the raster image " & vbCrLf & _
      "Please try again"
      PntLmts = False
     End If
    Else
     MsgBox "The pick points must be on the raster image " & vbCrLf & _
     "Please try again"
     PntLmts = False
    End If
   Else
    MsgBox "The pick points must be on the raster image " & vbCrLf & _
    "Please try again"
    PntLmts = False
   End If
  Loop
 
  mdpnt(0) = (llpnt(0) + urpnt(0)) / 2 'Midpoint (X) = (The far left picked point + the far right picked point) / 2
  mdpnt(1) = (llpnt(1) + urpnt(1)) / 2 'Midpoint (Y) = (The far bottom picked point + the far top picked point) / 2
  mdpnt(2) = 0
 
 'Create Selection Set for Raster
  Dim Sset As AcadSelectionSet
 
  Set Sset = ThisDrawing.SelectionSets.Add("Image")
  Sset.Select acSelectionSetLast
 
  'Debug.Print "Selection Set " & "("; Sset.Name; ")" & " was created"
 
  With Sset
   'Do whatever
  End With
 
 'Clip boundary = picked points (llpnt and urpnt)
  ClipPoints(0) = llpnt(0): ClipPoints(1) = llpnt(1)
  ClipPoints(2) = llpnt(0): ClipPoints(3) = urpnt(1)
  ClipPoints(4) = urpnt(0): ClipPoints(5) = urpnt(1)
  ClipPoints(6) = urpnt(0): ClipPoints(7) = llpnt(1)
  ClipPoints(8) = llpnt(0): ClipPoints(9) = llpnt(1)

 'Clip the image
  RastImg.ClipBoundary ClipPoints
     
 'Enable the display of the clip
  RastImg.ClippingEnabled = True
     
 'Delete Selection Set
  ThisDrawing.SelectionSets.Item("Image").Delete
     
 'Return picked points
  Debug.Print "The lower left picked points = " & llpnt(0) & ", " & llpnt(1)
  Debug.Print "The upper right picked points = " & urpnt(0) & ", " & urpnt(1)
     
Errorhandler:
 If Err.Description = "File access error" Then
  If MsgBox("Can not find image file") Then
   Exit Sub
  End If
 End If
 

End Sub
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 21, 2007, 02:53:22 PM
Code: [Select]
For Each Obj In ThisDrawing.PaperSpace
 If Obj.ObjectName = "AcDbRasterImage" Then
  Set RastImg = ThisDrawing.PaperSpace.Item(Objname)
    Objname = rastimg.name

 End If
Next Obj
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 21, 2007, 02:56:36 PM
Does AcadObject work for this or should it be ACADEntity? Also, why not use a filtered selection set.  Probably won't matter but if there are a bunch of thingies in your dwg it will be quicker.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 21, 2007, 03:03:43 PM

Hi Bob

Thank you;

Yes, Acadobject or Object will work
From what I have been taught and have learned:
If we declared
Obj as AcadEntity

Then, it will literally interate through EVERY single AutoCAD entity
Lines, blocks, text, polylines, circles and on and on as opposed to just saying
Find the "object" (typeof) (typename =) I need and do something with it

I could do a filtered selection set but these two methods would work in a similar fashion i would think as with this method we are interating for a specific object type not through a drawing of entity types

Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 21, 2007, 03:04:50 PM
808, I dont know, I thought it required the object
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 21, 2007, 03:06:58 PM
I could do a filtered selection set but these two methods would work in a similar fashion i would think as with this method we are interating for a specific object type not through a drawing of entity types
Actually, without the filter, you will process every object in paperspace.  Given that paperspace doesn't usually have tons of items, it should go quickly.  If however you were processing modelspace, a filtered selection set would be the way to go
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 21, 2007, 03:18:19 PM

Bob

This won't work
Code: [Select]
For Each Obj In ThisDrawing.PaperSpace
 If Obj.ObjectName = "AcDbRasterImage" Then
  Set RastImg = ThisDrawing.PaperSpace.Item(Objname)
    Objname = rastimg.name
 End If
Next Obj

How are we going to know what objname to set too?
I am able to confirm that there is a raster in paperspace but I need to grab its name

Mark
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 21, 2007, 03:20:56 PM
I think you want
Set RastImg = Obj
ObjName=RastImg.Name
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 21, 2007, 03:21:26 PM
doh!  yep, that's what I meant.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 21, 2007, 03:24:11 PM
I agree with that CM

Shouldn't looping through objects be quicker then looping through entities?

I am not so sure that entities and objects are looked at the same.

Myself and Keith B had this discussion once and he actually taught me to use object as opposed to entity when interating for a specific object "type"

You know me by now
"The less code the better"

When it comes to programming, if I can turn 5 lines into 3, I will do it.

Mark



Title: Re: Clip Boundaries for a Raster
Post by: ML on November 21, 2007, 03:30:09 PM

Yes sir! CM, you are the man!
And so is Bob of course :)

Well, yet here is one more method.

If Raster already exists in drawing (Paperspace in my scenario) then prompt for clipboundary points.

Code: [Select]
Sub MkRastCBnd()

Dim RastImg As AcadRasterImage
Dim Obj As AcadObject
Dim Objname As String
   
   
For Each Obj In ThisDrawing.PaperSpace
 If Obj.ObjectName = "AcDbRasterImage" Then
  Set RastImg = Obj
  Objname = RastImg.Name
 End If
Next Obj
 
 
 Dim ImgLmts(2) As Double
 ImgLmts(0) = RastImg.Origin(0) + RastImg.ImageWidth
 ImgLmts(1) = RastImg.Origin(1) + RastImg.ImageHeight
 ImgLmts(2) = 0
     
 Dim llpnt As Variant 'lower left point
 Dim urpnt As Variant 'upper right point
 Dim mdpnt(0 To 2) As Double
 Dim ClipPoints(0 To 9) As Double
 
'Prompt for pick points on raster and check if the user picks within the raster boundaries
 Dim PntLmts As Boolean
       
 PntLmts = False
 
 Do While PntLmts = False
  llpnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Select Lower Left Point: ")
  urpnt = ThisDrawing.Utility.GetCorner(llpnt, vbCrLf & "Select Upper Right Point: ")
 
   If llpnt(0) >= RastImg.Origin(0) And llpnt(0) <= ImgLmts(0) Then
    If llpnt(1) >= RastImg.Origin(1) And llpnt(1) <= ImgLmts(1) Then
     If urpnt(0) >= RastImg.Origin(0) And urpnt(0) <= ImgLmts(0) Then
      If urpnt(1) >= RastImg.Origin(1) And urpnt(1) <= ImgLmts(1) Then
       PntLmts = True
      Else
       MsgBox "The pick points must be on the raster image " & vbCrLf & _
       "Please try again"
       PntLmts = False
      End If
     Else
      MsgBox "The pick points must be on the raster image " & vbCrLf & _
      "Please try again"
      PntLmts = False
     End If
    Else
     MsgBox "The pick points must be on the raster image " & vbCrLf & _
     "Please try again"
     PntLmts = False
    End If
   Else
    MsgBox "The pick points must be on the raster image " & vbCrLf & _
    "Please try again"
    PntLmts = False
   End If
  Loop
 
  mdpnt(0) = (llpnt(0) + urpnt(0)) / 2 'Midpoint (X) = (The far left picked point + the far right picked point) / 2
  mdpnt(1) = (llpnt(1) + urpnt(1)) / 2 'Midpoint (Y) = (The far bottom picked point + the far top picked point) / 2
  mdpnt(2) = 0
 
 'Create Selection Set for Raster
  Dim Sset As AcadSelectionSet
 
  Set Sset = ThisDrawing.SelectionSets.Add("Image")
  Sset.Select acSelectionSetLast
 
  'Debug.Print "Selection Set " & "("; Sset.Name; ")" & " was created"
 
  With Sset
   'Do whatever
  End With
 
 'Clip boundary = picked points (llpnt and urpnt)
  ClipPoints(0) = llpnt(0): ClipPoints(1) = llpnt(1)
  ClipPoints(2) = llpnt(0): ClipPoints(3) = urpnt(1)
  ClipPoints(4) = urpnt(0): ClipPoints(5) = urpnt(1)
  ClipPoints(6) = urpnt(0): ClipPoints(7) = llpnt(1)
  ClipPoints(8) = llpnt(0): ClipPoints(9) = llpnt(1)

 'Clip the image
  RastImg.ClipBoundary ClipPoints
     
 'Enable the display of the clip
  RastImg.ClippingEnabled = True
     
 'Delete Selection Set
  ThisDrawing.SelectionSets.Item("Image").Delete
     
 'Return picked points
  Debug.Print "The lower left picked points = " & llpnt(0) & ", " & llpnt(1)
  Debug.Print "The upper right picked points = " & urpnt(0) & ", " & urpnt(1)
     
Errorhandler:
 If Err.Description = "File access error" Then
  If MsgBox("Can not find image file") Then
   Exit Sub
  End If
 End If
 

End Sub
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 21, 2007, 03:31:44 PM

And make the boundary of course!     :-P
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 21, 2007, 03:36:01 PM

I forgot:

We should also add Bob's other nice piece of code into this module

Code: [Select]
'Clip boundary =  user defined (uniform) size
  Dim Bndsize As Double
  Bndsize = ThisDrawing.Utility.GetReal("What size boundary would you like?: ")
 
  ClipPoints(0) = mdpnt(0) - (Bndsize / 2): ClipPoints(1) = mdpnt(1) - (Bndsize / 2)
  ClipPoints(2) = mdpnt(0) - (Bndsize / 2): ClipPoints(3) = mdpnt(1) + (Bndsize / 2)
  ClipPoints(4) = mdpnt(0) + (Bndsize / 2): ClipPoints(5) = mdpnt(1) + (Bndsize / 2)
  ClipPoints(6) = mdpnt(0) + (Bndsize / 2): ClipPoints(7) = mdpnt(1) - (Bndsize / 2)
  ClipPoints(8) = mdpnt(0) - (Bndsize / 2): ClipPoints(9) = mdpnt(1) + -(Bndsize / 2)
Title: Re: Clip Boundaries for a Raster
Post by: David Hall on November 21, 2007, 10:31:39 PM
Always use enough lines of code to make it the most efficient.  If that means an extra 10 to save 90% of the clock cycles, thats lines worth typing
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 23, 2007, 04:12:22 PM

CM

Did you try the code for if the raster exists?

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 23, 2007, 04:20:44 PM

So, that is cool; now we can insert and create the boundary or create the boundary after it is inserted.

I wonder if you or Bob caught my previous posts on points?

If you go back about 5 or 6, you should see them.

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 28, 2007, 03:24:12 PM
Hey Guys,

I also wanted to toss this in
Just to clarify; my initial intent was to insert the raster at -8 in the X direction so that it was off the title block for the users to pick their points. I originally used the move method for that but I changed it. Instead, I it at -8,0,0
Then you can fill in the move section when/if you know where the raster will permanently reside

Mark

Code: [Select]
Sub InstRastMkCBnd()

Dim RastImg As AcadRasterImage
Dim Imgpath as String, Imgname as String     
Dim InsertPnt(0 To 2) As Double, Scalefactor As Double, RotAngle As Double


Imgpth = ThisDrawing.Path & "\"  'assumes Image File is in the same directory as your drawing
Imgname = "Filename.ext"

ThisDrawing.ActiveSpace = acPaperSpace

InsertPnt(0) = -8#: InsertPnt(1) = 0#: InsertPnt(2) = 0#
scalefactor = 1
RotAngle = 0

'On Error GoTo Errorhandler
Set RastImg = ThisDrawing.PaperSpace.AddRaster(Imgpth & Imgname, InsertPnt, Scalefactor, RotAngle)

RastImg.Name = Left(Imgname, Len(Imgname) - 4)

RastImg.scalefactor = 12

'Move Points
 Dim MPointN(0 To 2) As Double 'Negative
 Dim MPointP(0 To 2) As Double 'Positive
 MPointN(0) = 0: MPointN(1) = 0: MPointN(2) = 0
 MPointP(0) = 0: MPointP(1) = 0: MPointP(2) = 0
 
'Move Raster
 RastImg.Move MPointN, MPointP
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 28, 2007, 04:26:08 PM

So, that is cool; now we can insert and create the boundary or create the boundary after it is inserted.

I wonder if you or Bob caught my previous posts on points?

If you go back about 5 or 6, you should see them.

Mark
Sorry, which posts on points?
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 28, 2007, 04:36:27 PM

Hey Bob
Just go back one page
I was just a little confused about something but it is no big deal.

Title: Re: Clip Boundaries for a Raster
Post by: ML on November 28, 2007, 04:46:44 PM

Bob

Also, if I may; I have another question for you.

In the method (see top of this page) where we grab an existing raster, then picks our points

What would we do in the case that there are multiple rasters?

I suppose we could interate through paper (or opt the user for space) and ask the user which one (raster) they want to use and set obj = the user picked raster.

After they clip that one, prompt for the next one, etc. etc.

Mark


Code: [Select]
Sub MkCBnd()

Dim RastImg As AcadRasterImage
Dim Obj As AcadObject
Dim Objname As String
   
ThisDrawing.ActiveSpace = acPaperSpace
   
For Each Obj In ThisDrawing.PaperSpace
 If Obj.ObjectName = "AcDbRasterImage" Then
  Set RastImg = Obj
 End If
Next Obj
 
If RastImg Is Nothing Then
 MsgBox "There are no image files in this drawing"
 Exit Sub
Else
'Lower left points of the raster + the image width and height
 Dim ImgLmts(2) As Double
 ImgLmts(0) = RastImg.Origin(0) + RastImg.ImageWidth
 ImgLmts(1) = RastImg.Origin(1) + RastImg.ImageHeight
 ImgLmts(2) = 0
End If
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 28, 2007, 05:07:03 PM
I'll have to look into the points thing when I have some time to play in acad.  As to the most recent though, the easiest way would be to do a filtered selection set.  If there's one, continue.  If there's more than one, prompt for a selection.  Another option would be just to let the user pick the clip boundary and iterate through the rasters, running the check for containment on each.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 28, 2007, 05:19:28 PM

What do you think would be the best method for them to select each raster without getting into userforms and all that crazy stuff?
I could return each raster with a msgbox but then there is no method to select one; even an input box, there would have to type in the one they want.

With a combobox (if I want to go there) we could return all rasters and allow them to select one.

What do you think? Is there a way without getting into forms?

Thanks

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 28, 2007, 05:21:37 PM

You would still prefer a filtered selection set over the method I am using, huh? :)
I do realize that we are looping through all objects but the time it is taking is so miniscal that it really is fine

Mark
Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 28, 2007, 05:36:06 PM
Not my program, I don't have a preference.  If asked for a solution to a problem, I gave you what to me seemed the most logical and straightforward method.  You could do a message box with yes/no buttons for each.  Your users will hate you.  You can do the form you mentioned.  Lots of ways to skin a cat.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 28, 2007, 05:45:37 PM

Absolutely and I respect your suggestions and appreciate all your help :)

I was actually pretty much done with the whole project then I ran into a situation today where no rasters exisited so I addressed that, then I thought, what if there is more then one in the drawing?

As you know, we can not account for every little thing.

At this point, I think I will leave good enough alone.

Thanks again,

Mark



Title: Re: Clip Boundaries for a Raster
Post by: Bob Wahr on November 28, 2007, 05:50:46 PM
cool dat.
Title: Re: Clip Boundaries for a Raster
Post by: ML on November 28, 2007, 05:55:29 PM

:)
Title: Re: Clip Boundaries for a Raster
Post by: ML on December 04, 2007, 04:25:54 PM

Hey guys

Another question:

We already have our midpoint

Code: [Select]
Dim mdpnt(0 To 2) As Double
mdpnt(0) = (llpnt(0) + urpnt(0)) / 2 'Midpoint (X)
mdpnt(1) = (llpnt(1) + urpnt(1)) / 2 'Midpoint (Y)
mdpnt(2) = 0

And the code to move the raster

Code: [Select]
'Move Points
 Dim MPointN(0 To 2) As Double 'Negative
 Dim MPointP(0 To 2) As Double 'Positive
 MPointN(0) = 0: MPointN(1) = 0: MPointN(2) = 0
 MPointP(0) = 0: MPointP(1) = 0: MPointP(2) = 0
 
'Move Raster
RastImg.Move MPointN, MPointP

Now, what if we want to move the raster from the midpoint that we already have to another midpoint else where, let's say in the middle of a 5'x5' square.

How would we do this:

I realize, we can have midpnt1 and a midpnt2

The question is more, how do we do the actual move with the raster.

Note: Also, this is after it has been clipped

Thanks,

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on December 04, 2007, 04:30:55 PM

It looks like we somehow need a way to say move FROM midpnt1

Code: [Select]
Dim mdpnt1 (0 To 2) As Double
mdpnt1(0) = (llpnt(0) + urpnt(0)) / 2 'Midpoint (X)
mdpnt1(1) = (llpnt(1) + urpnt(1)) / 2 'Midpoint (Y)
mdpnt1(2) = 0

Code: [Select]
To Midpnt2 (0 to 2) as Double  'To be determined
Mdpnt2 (0)=
Mdpnt2 (1)=
Mdpnt2 (2)=

So, how does that translate into here?

Code: [Select]
'Move Raster
RastImg.Move Midpnt1 (this is from), Midpnt2 (this is to)

Mark
Title: Re: Clip Boundaries for a Raster
Post by: ML on December 05, 2007, 11:19:33 AM

When you look go to the end of the .move method, it prompts you for a From Point, To Point
In the scenario we originally used, we are giving it the negative and positive coords to move to.

Code: [Select]
RastImg.Move MPointN, MPointP

In the above question, I am looking to truly go from a From Point (mdpnt), to a To Point (mdpnt1)
Just not quite sure how to get it; I have tried a few things but no luck?

Anyone?

Mark

Title: Re: Clip Boundaries for a Raster
Post by: David Hall on December 05, 2007, 02:36:59 PM
What have you tried?
Title: Re: Clip Boundaries for a Raster
Post by: ML on December 05, 2007, 03:46:34 PM

Hey CM,
Good to see you back!

So far, I am just grasping for straws, time permitting.

I have tried something like this:

Code: [Select]
'Test Move Points
 Dim mdpnt1N(0 To 2) As Double
 Dim mdpnt1P(0 To 2) As Double
 mdpnt1N(0) = 0: mdpnt1N(1) = 0: mdpnt1N(2) = 0
 mdpnt1P(0) = 2.5: mdpnt1P(1) = 2.5: mdpnt1P(2) = 0

'Test Move Raster
 RastImg.Move mdpnt, mdpnt1N, mdpnt1P

So, I was trying to use our existing mdpnt which we know is constant each time we define our points to a mid point of a rectangle on a title block; that is where the clipped raster will end up.
So, that would be cool; after the user chooses their points, it will magically get moved to the necessary location for them, assuming I can get it to work.

I think after the move method, we can only use 2 variables and I am using 3 above which did not work for me.

The other thing is that the mdpnt will never be the same, so how do we address that?

We could say mdpnt = RastImg.Origin then perform the move; assuming that will first shift the clipped image to the original raster origin before performing the move.

What do you think?

Thanks


Mark

Title: Re: Clip Boundaries for a Raster
Post by: ML on January 14, 2008, 10:52:57 AM
For those who are interested:
Here is how I finally moved the clipped raster to where I needed it to be on the drawing:

Mark

Code: [Select]
'***Move the raster***
 'Use the midpoint of the raster as the base point
  Dim Pnt As Variant
  Pnt = mdpnt
 
 '0,0
  Dim ZeroZero(0 To 2) As Double
  ZeroZero(0) = 0: ZeroZero(1) = 0: ZeroZero(2) = 0
     
 'Specify the distance you want to move the raster (midpoint) from 0,0
  Dim DestPnt(0 To 2) As Double
  DestPnt(0) = ZeroZero(0) + 9.83
  DestPnt(1) = ZeroZero(1) + 16.83
  DestPnt(2) = 0
   
 'Move the clipped raster to it's destination
  RastImg.Move Pnt, DestPnt