.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

image attach

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
958 Views, 7 Replies

image attach

I want to attach an image at a certain scale and also clip it. I'm haven't managed yet to do this. See below for the code so far. What did I do wrong ? Thanks in advance.

{code}
_
Public Sub iim()
Dim myTransMan As DatabaseServices.TransactionManager
Dim myTrans As DatabaseServices.Transaction
Dim myDWG As ApplicationServices.Document
Dim myBT As DatabaseServices.BlockTable
Dim myBTR As DatabaseServices.BlockTableRecord
myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument
myTransMan = myDWG.TransactionManager
myTrans = myTransMan.StartTransaction
myBT = myDWG.Database.BlockTableId.GetObject(DatabaseServices.OpenMode.ForRead)
myBTR = myBT(DatabaseServices.BlockTableRecord.PaperSpace).GetObject(DatabaseServices.OpenMode.ForWrite)
Dim myIm As New RasterImage
Dim myRec As Geometry.Point2dCollection
myRec.Add(New Point2d(0, 0))
myRec.Add(New Point2d(100, 100))
myIm.Path = "c:\test.tif" ' readonly ????
myIm.Position = New Geometry.Point2d(0, 0) ' readonly ????
myIm.Scale = 10 ' readonly ????
myIm.ClipBoundaryType = ClipBoundaryType.Rectangle ' readonly ????
myIm.SetClipBoundary(ClipBoundaryType.Rectangle, myRec)
myBTR.AppendEntity(myIm)
myTrans.Commit()
myTrans.Dispose()
myTransMan.Dispose()
End Sub

{code}
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: Anonymous

Hi,

Sorry, I am only able to solve the file location property. Have you tried using RasterImageDef ?

{code}

RasterImageDef rasterImageDef = new RasterImageDef();

rasterImageDef.SourceFileName = "c:\test.tif";


{code}

I am not sure about how to set the scale and clip boundary type.
Message 3 of 8
Anonymous
in reply to: Anonymous

See this C# example:

http://www.caddzone.com/RasterImageSample.cs

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6349875@discussion.autodesk.com...
I want to attach an image at a certain scale and also clip it. I'm haven't
managed yet to do this. See below for the code so far. What did I do wrong ?
Thanks in advance.

{code}
_
Public Sub iim()
Dim myTransMan As DatabaseServices.TransactionManager
Dim myTrans As DatabaseServices.Transaction
Dim myDWG As ApplicationServices.Document
Dim myBT As DatabaseServices.BlockTable
Dim myBTR As DatabaseServices.BlockTableRecord
myDWG =
ApplicationServices.Application.DocumentManager.MdiActiveDocument
myTransMan = myDWG.TransactionManager
myTrans = myTransMan.StartTransaction
myBT =
myDWG.Database.BlockTableId.GetObject(DatabaseServices.OpenMode.ForRead)
myBTR =
myBT(DatabaseServices.BlockTableRecord.PaperSpace).GetObject(DatabaseServices.OpenMode.ForWrite)
Dim myIm As New RasterImage
Dim myRec As Geometry.Point2dCollection
myRec.Add(New Point2d(0, 0))
myRec.Add(New Point2d(100, 100))
myIm.Path = "c:\test.tif" ' readonly ????
myIm.Position = New Geometry.Point2d(0, 0) ' readonly ????
myIm.Scale = 10 ' readonly ????
myIm.ClipBoundaryType = ClipBoundaryType.Rectangle ' readonly ????
myIm.SetClipBoundary(ClipBoundaryType.Rectangle, myRec)
myBTR.AppendEntity(myIm)
myTrans.Commit()
myTrans.Dispose()
myTransMan.Dispose()
End Sub

{code}
Message 4 of 8
Anonymous
in reply to: Anonymous

Thank you Tony, you should write a book !

I've translated it in vb.net and than I added some code to clip the image. I now have an error. See the code below.

{code}
puntcol.Add(New Geometry.Point2d(142, 190))
puntcol.Add(New Geometry.Point2d(142, 160))
puntcol.Add(New Geometry.Point2d(185, 160))
puntcol.Add(New Geometry.Point2d(185, 190))
image.Orientation = New CoordinateSystem3d(New Point3d(100, 100, 0), New Vector3d(100, 0, 0), New Vector3d(0, 100, 0))
image.SetClipBoundary(ClipBoundaryType.Poly, puntcol)
{code}
Message 5 of 8
Anonymous
in reply to: Anonymous

You only say you have an error in the code,
not what the error is or what line causes it.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6350096@discussion.autodesk.com...
Thank you Tony, you should write a book !

I've translated it in vb.net and than I added some code to clip the image. I now
have an error. See the code below.

{code}
puntcol.Add(New Geometry.Point2d(142, 190))
puntcol.Add(New Geometry.Point2d(142, 160))
puntcol.Add(New Geometry.Point2d(185, 160))
puntcol.Add(New Geometry.Point2d(185, 190))
image.Orientation = New CoordinateSystem3d(New Point3d(100, 100, 0), New
Vector3d(100, 0, 0), New Vector3d(0, 100, 0))
image.SetClipBoundary(ClipBoundaryType.Poly, puntcol)
{code}
Message 6 of 8
Anonymous
in reply to: Anonymous

The error is: "exception was handled by user code" on line
image.SetClipBoundary(ClipBoundaryType.Poly, puntcol)"

I think it has something to do with my 2Dcollection.

In attach the full code (your code translated in vb.net. I have only added the code to set a clipboundery".
Message 7 of 8
Anonymous
in reply to: Anonymous

First, let's thank the bone head that's responsible for
the managed documentation for the RasterImage's
SetClipBoundary methods (the docs for both overloads
are indentical).

Read those docs carefully (for either overload, as both
are for the one you're using), and see if you can figure
out what's wrong with your code.

Here's a hint:

Your Point2dCollection has the wrong number of elements.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6350188@discussion.autodesk.com...
The error is: "exception was handled by user code" on line
image.SetClipBoundary(ClipBoundaryType.Poly, puntcol)"

I think it has something to do with my 2Dcollection.

In attach the full code (your code translated in vb.net. I have only added the
code to set a clipboundery".
Message 8 of 8
Anonymous
in reply to: Anonymous

Thanks Tony, your hint made everything clear.
I repeat: you should write a book !

By the way: I´ve completed the code with a pixeltomodeltranform because otherwise it did´t work as I wanted:

{code}
Dim puntcol As New Geometry.Point3dCollection
puntcol.Add(New Geometry.Point3d(75747.8714, 206277.0816, 0))
puntcol.Add(New Geometry.Point3d(77943.8713, 206277.0816, 0))
puntcol.Add(New Geometry.Point3d(77943.8713, 204592.2378, 0))
puntcol.Add(New Geometry.Point3d(75747.8714, 204592.2378, 0))
puntcol.Add(New Geometry.Point3d(75747.8714, 206277.0816, 0))
image.Orientation = New CoordinateSystem3d(New Point3d(74015.6, 198173.34, 0), New Vector3d(8000, 0, 0), New Vector3d(0, 9993.6548, 0))
Dim vers As New Geometry.Point2dCollection
Dim mat As Matrix3d
mat = image.PixelToModelTransform.Inverse()
Dim i As Integer
For i = 0 To puntcol.Count - 1
puntcol(i) = puntcol(i).TransformBy(mat)
vers.Add(puntcol(i).Convert2d(New Plane()))
Next i
image.SetClipBoundary(ClipBoundaryType.Poly, vers)
{code}

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost