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

VB.net syntax for adding image without frame

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
BugWare
1545 Views, 14 Replies

VB.net syntax for adding image without frame

My VB.NET app uses the code below to insert a JPG image into the drawing.  What is the syntax for making it NOT add the frame around the image?  Thanks in advance.  Mitch

 

 'Insert Picture
        Dim insertionPoint(2) As Double
        Dim scalefactor As Double
        Dim rotAngleInDegree, rotAngle As Double
        Dim imageName As String
        Dim raster As Autodesk.AutoCAD.Interop.Common.AcadRasterImage
        Dim startPoint(2) As Double

            imageName = "C:\TestImage.jpg"

            insertionPoint(0) = 1.0
            insertionPoint(1) = Tier1BoxHt 'TopEdge - 0.4 'Tier1BoxHt + Tier2BoxHt + Tier3BoxHt / 2 '0.1     '6.1

 

            scalefactor = 1.0#
            rotAngleInDegree = 0.0#
            rotAngle = rotAngleInDegree * 3.141592 / 180.0#
           

            raster = ThisDrawing.ModelSpace.AddRaster(imageName, insertionPoint, scalefactor, rotAngle)

Micropaleontology
Oil Industry
Tags (1)
14 REPLIES 14
Message 2 of 15
Virupaksha_aithal
in reply to: BugWare

Hi,

 

Drawing of frame around the image is controlled by system variable “IMAGEFRAME”.  You need to set system variable IMAGEFRAME to 0 to avoid drawing of frame around the image. Refer AutoCAD help for different values IMAGEFRAME takes.



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Message 3 of 15
BugWare
in reply to: Virupaksha_aithal

Thanks very much Virupaksha. That is certainly easy to to do for the end user, but I really need to do this programatically in VB.NET, and not force the end user to do it. Do you know the syntax that I can add to the code shown above in this thread? Thanks again, Mitch
Micropaleontology
Oil Industry
Message 4 of 15

try this: Application.SetSystemVariable("imageframe", 0)
Message 5 of 15

When I try Application.SetSystemVariable("imageframe", 0) I get the compile error:

Error 1 'SetSystemVariable' is not a member of 'System.Windows.Forms.Application'.

I feel like we're getting closer, thanks conormccartney3897.
Micropaleontology
Oil Industry
Message 6 of 15

check your imports up top, look for this, or add if not there: Imports Autodesk.AutoCAD.ApplicationServices
Message 7 of 15
_gile
in reply to: BugWare

Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("imageframe", 0)



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 8 of 15
BugWare
in reply to: _gile

Both solutions by conormccartne3897 and _gile work nicely... sort of. Odd behavior... I've tested this over and over, and it's always the same.

This code does set imageframe to 0.  However, if you exit AutoCAD, it remembers that setting, but the next time you run this code it doesn't work.  You can see that imageframe is set to 0 on the command line.  So if you manually change imageframe to 1, then exit the program, rerun it, the code works again.

So... imageframe has to be already set to 1 for this code to work.  If it's set to 0 to start with, the codewon't work and the image will have a frame.

I just realized while writing this that the simple solution to the problem is to set the imageframe to 1 first, then set it to 0.  An extra line of code, but that does the trick.  

Thanks very much!

Micropaleontology
Oil Industry
Message 9 of 15
_gile
in reply to: BugWare


BugWare a écrit :

I just realized while writing this that the simple solution to the problem is to set the imageframe to 1 first, then set it to 0.  An extra line of code, but that does the trick. 


Don't make unusefull work, just check the current value.

 

Not certain of VB syntax

 

Imports AcApp = Autodesk.AutoCAD.ApplicationSevices.Application
...
If CShort(AcApp.GetSystemVariable("IMAGEFRAME") = 1 Then
    AcApp.SetSystemVariable("IMAGEFRAME", 0)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 10 of 15

hrmm that is odd behavior, but Gilles method makes more sense, use an if statement like so for VB, if its not equal to 0, then switch: If Application.GetSystemVariable("imageframe") <> 0 Then Application.SetSystemVariable("imageframe", 0) End If
Message 11 of 15
LE3
Advocate
in reply to: conormccartney3897

I just happen to be working on a method that requires this, and it is based on the code here: http://adndevblog.typepad.com/autocad/2012/05/access-raster-image-variables-using-the-net-api.html (VB.NET)

 

Or in the case it is useful, the counter part in C#, that works for me here:

 

var nodDictionary = transaction.GetObject(database.NamedObjectsDictionaryId, OpenMode.ForRead) as DBDictionary;

if (nodDictionary != null)

{

conststring acadImageVars = "ACAD_IMAGE_VARS";

RasterVariables rasterVariables;

if (nodDictionary.Contains(acadImageVars))

{

var acadImageVarsId = nodDictionary.GetAt(acadImageVars);

rasterVariables = transaction.GetObject(acadImageVarsId, OpenMode.ForWrite) as RasterVariables;

}

else

{

rasterVariables = new RasterVariables();

nodDictionary.UpgradeOpen();

nodDictionary.SetAt(acadImageVars, rasterVariables);

transaction.AddNewlyCreatedDBObject(rasterVariables, true);

}

if (rasterVariables != null)

{

rasterVariables.ImageFrame = FrameSetting.ImageFrameOff;

}

}

 

HTH.

Message 12 of 15
BugWare
in reply to: _gile

But it IS already equal to 0 when the program starts, so checking to see if it's 0 won't help.  It must be changed to 1, then set back to 0 to get it to work. I've tested this several times.

Micropaleontology
Oil Industry
Message 13 of 15
1005592820
in reply to: BugWare

I have some problems, these codes can't add JPG images to the file, I don't know why?

On Error Resume Next
Set ohost = GetObject("AutoCAD.Application.19") '检查AutoCAD是否已经打开
If Err <> 0 Then '没有打开
Err.Clear
Set ohost = CreateObject("AutoCAD.Application.19") '打开CAD
If Err Then
MsgBox Err.Number & ":" & Err.Description '打开失败
Exit Sub
End If
End If

Set odaApp = ohost.Application
ohost.Visible = True
Set odoc = ohost.Documents.Open(filePath)
Set acadDoc = ohost.ActiveDocument

'gr 测试
Dim insertionPoint(0 To 2) As Double
Dim scalefactor As Double
Dim rotationAngle As Double
Dim imageName As String
Dim rasterObj As AcadRasterImage
imageName = "D:/Siemens/signpic/lilin.jpg"
insertionPoint(0) = 5#: insertionPoint(1) = 5#: insertionPoint(2) = 0#
scalefactor = 1#
rotationAngle = 0

Set rasterObj = odoc.ModelSpace.AddRaster(imageName, insertionPoint, scalefactor, rotationAngle)

If Err.Description = "File error" Then
MsgBox imageName & " could not be found."


Exit Sub
End If

odoc.Save
odoc.Close
Message 14 of 15
1005592820
in reply to: LE3

you are great
Message 15 of 15
1005592820
in reply to: BugWare

Hi, is there a solution to this problem?

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