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

error in code

5 REPLIES 5
Reply
Message 1 of 6
ashish.agarwal
302 Views, 5 Replies

error in code

Hi -
I am trying to change the path of all raster images to relative.

this is the code . I am getting an error - A namespace does not directly contain members such as fields ot methods in line 1.

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput

Namespace ImageTest
{
Public Class ImageCmds
{
Public Sub LoadImageProperties()
Dim db As New Database(False, True)



//'This DWG file contains images attached from C:\My Documents
db.ReadDwgFile("c:\temp\testimage.dwg", IO.FileShare.ReadWrite, False, Nothing)
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager
Dim ta As Transaction = tm.StartTransaction
Dim rasterImageDef As RasterImageDef
Dim dictEntry As System.Collections.DictionaryEntry
Dim nod As DBDictionary
Dim imageDict As DBDictionary



nod = CType(tm.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead, False), DBDictionary)



imageDict = CType(tm.GetObject(nod.GetAt("ACAD_IMAGE_DICT"), OpenMode.ForRead, False), DBDictionary)



Dim imagePath As String



For Each dictEntry In imageDict



Dim obj As DBObject



obj = tm.GetObject(CType(dictEntry.Value(), ObjectId), OpenMode.ForRead, False)



//'the next is needed to get the raster image path



If obj.GetRXClass.IsDerivedFrom(Autodesk.AutoCAD.Runtime.RXClass.GetClass(GetType(RasterImageDef))) Then



//'create a RasterImageDef wrapper



rasterImageDef = CType(Autodesk.AutoCAD.Runtime.DisposableWrapper.Create(GetType(RasterImageDef), obj.UnmanagedObject, False), RasterImageDef)



imagePath = rasterImageDef.SourceFileName



MsgBox(imagePath)



//'Strip off the filename, looking for the lask backslash, repath it to the temp folder
imagePath = "C:\temp\\" + imagePath.Substring(imagePath.LastIndexOf(Chr(92)) + 1)

//'Make sure the def object is open for write, then set the filename to the new location

rasterImageDef.UpgradeOpen()

rasterImageDef.SourceFileName = imagePath

imagePath = rasterImageDef.SourceFileName

// 'Just to double-check, let's get the filename and show it

MsgBox(imagePath)

End If

Next

ta.Commit()

ta.Dispose()

db.Dispose()

End Sub

End Class
}
End Namespace
}

Thanks
Ashish
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: ashish.agarwal

Hi. Those of us using newsreaders cannot read code
posted via the web.

Feel free to attach it as a .txt file.

--
http://www.caddzone.com

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

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6133339@discussion.autodesk.com...
Hi - I am trying to change the path of all raster images to relative. this
is the code . I am getting an error - A namespace does not directly contain
members such as fields ot methods in line 1. Imports
Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices Imports
Autodesk.AutoCAD.EditorInput Namespace ImageTest { Public Class ImageCmds
{ Public Sub LoadImageProperties() Dim db As New Database(False, True)
//'This DWG file contains images attached from C:\My Documents
db.ReadDwgFile("c:\temp\testimage.dwg", IO.FileShare.ReadWrite, False,
Nothing) Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager =
db.TransactionManager Dim ta As Transaction = tm.StartTransaction Dim
rasterImageDef As RasterImageDef Dim dictEntry As
System.Collections.DictionaryEntry Dim nod As DBDictionary Dim imageDict As
DBDictionary nod = CType(tm.GetObject(db.NamedObjectsDictionaryId,
OpenMode.ForRead, False), DBDictionary) imageDict =
CType(tm.GetObject(nod.GetAt("ACAD_IMAGE_DICT"), OpenMode.ForRead, False),
DBDictionary) Dim imagePath As String For Each dictEntry In imageDict Dim
obj As DBObject obj = tm.GetObject(CType(dictEntry.Value(), ObjectId),
OpenMode.ForRead, False) //'the next is needed to get the raster image path
If
obj.GetRXClass.IsDerivedFrom(Autodesk.AutoCAD.Runtime.RXClass.GetClass(GetType(RasterImageDef)))
Then //'create a RasterImageDef wrapper rasterImageDef =
CType(Autodesk.AutoCAD.Runtime.DisposableWrapper.Create(GetType(RasterImageDef),
obj.UnmanagedObject, False), RasterImageDef) imagePath =
rasterImageDef.SourceFileName MsgBox(imagePath) //'Strip off the filename,
looking for the lask backslash, repath it to the temp folder imagePath =
"C:\temp\\" + imagePath.Substring(imagePath.LastIndexOf(Chr(92)) + 1)
//'Make sure the def object is open for write, then set the filename to the
new location rasterImageDef.UpgradeOpen() rasterImageDef.SourceFileName =
imagePath imagePath = rasterImageDef.SourceFileName // 'Just to
double-check, let's get the filename and show it MsgBox(imagePath) End If
Next ta.Commit() ta.Dispose() db.Dispose() End Sub End Class } End
Namespace } Thanks Ashish
Message 3 of 6

the code is attached.
Message 4 of 6
Anonymous
in reply to: ashish.agarwal

Is this your first attempt at ObjectARX.NET programming?

I ask that, because I'm honestly baffled by what you
posted, because I can't tell if it is C# or VB.NET code
(or perhaps both).

Your code contains curly braces (which is used in
C# but not VB).

I would suggest you not try to do any programming
yet, until you first learn the rudimentry basics of using
one of those two languages, once you have made up
your mind which it will be.


--
http://www.caddzone.com

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

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6133410@discussion.autodesk.com...
the code is attached.
Message 5 of 6

yes, it is my first attempt.
its vb.net and i am using visual c# 2005 express edition.
i had a few more errors initially and it was not necessary to put those curly braces.they can be removed.
thanks Edited by: ashish.agarwal on Feb 27, 2009 10:18 PM
Message 6 of 6
arcticad
in reply to: ashish.agarwal

I know I'm going to get trouble for saying this.

I just never thought of editing Visual Basic with the C# editor.

There is a VB to C# to VB converter. It may help.

http://www.developerfusion.com/tools/convert/vb-to-csharp/
---------------------------



(defun botsbuildbots() (botsbuildbots))

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