Jump to content

Import Bmp image to drawing.


boomoto

Recommended Posts

As the title says I'm trying to import BMP files into a drawing. I understand that there is a command called " IMAGEATTACH" this would work if I could automate it.

 

Basically what I'm doing is I have a program that grabs info from the .dwg then displays it to a form, the user then selects part of the drawing to take a picture of which then exports the the selected lines to a .BMP then creates a new .dwg with the part information. To this point the program works flawless, however I have no idea how to import the the .BMP file back using VBA and have been searching the web for a good bit.

 

So please help :)

Link to comment
Share on other sites

use the -image command this will give you command line prompts with no dialog box

 

Hmm ok, getting somewhere with this; however still can't figure out how to make it all command with no pop up

 

Could you give me an example just to place an image anywhere within the drawing without any interaction other then command line. I will keep trying but if you know it could save me loads of time lol. Thanks

Link to comment
Share on other sites

(defun AT:Image (image pt scale ang / obj)
 ;; Insert image into drawing
 ;; Alan J. Thompson, 06.21.10
 (if (findfile image)
   (if (not (vl-catch-all-error-p
              (setq obj
                     (vl-catch-all-apply
                       (function vla-AddRaster)
                       (list
                         (if
                           (or
                             (eq
                               acmodelspace
                               (vla-get-activespace
                                 (cond (*AcadDoc*)
                                       ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
                                 )
                               )
                             )
                             (eq :vlax-true (vla-get-mspace *AcadDoc*))
                           )
                            (vla-get-modelspace *AcadDoc*)
                            (vla-get-paperspace *AcadDoc*)
                         )
                         image
                         (vlax-3d-point pt)
                         scale
                         ang
                       )
                     )
              )
            )
       )
     obj
   )
 )
)

Link to comment
Share on other sites

(defun AT:Image (image pt scale ang / obj)
 ;; Insert image into drawing
 ;; Alan J. Thompson, 06.21.10
 (if (findfile image)
   (if (not (vl-catch-all-error-p
              (setq obj
                     (vl-catch-all-apply
                       (function vla-AddRaster)
                       (list
                         (if
                           (or
                             (eq
                               acmodelspace
                               (vla-get-activespace
                                 (cond (*AcadDoc*)
                                       ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
                                 )
                               )
                             )
                             (eq :vlax-true (vla-get-mspace *AcadDoc*))
                           )
                            (vla-get-modelspace *AcadDoc*)
                            (vla-get-paperspace *AcadDoc*)
                         )
                         image
                         (vlax-3d-point pt)
                         scale
                         ang
                       )
                     )
              )
            )
       )
     obj
   )
 )
)

 

 

That looks good however I need it for a VBA program so either i need the command lines for it or a way to do it Using VBA thanks though.

Link to comment
Share on other sites

Example from help:

 

Sub AddRaster ( )
 ' This example adds a raster image in model space.
 ' This example uses a file named "raster.jpg."
 ' You should change this example to use
 ' a raster file on your computer.

 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:\raster.jpg"
 insertionPoint(0) = 5#: insertionPoint(1) = 5#: insertionPoint(2) = 0#
 scalefactor = 1#
 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 = "File error" Then
   MsgBox imageName & " could not be found."
   Exit Sub
 End If

 ZoomExtents

End Sub

Link to comment
Share on other sites

Example from help:

 

Sub AddRaster ( )
 ' This example adds a raster image in model space.
 ' This example uses a file named "raster.jpg."
 ' You should change this example to use
 ' a raster file on your computer.

 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:\raster.jpg"
 insertionPoint(0) = 5#: insertionPoint(1) = 5#: insertionPoint(2) = 0#
 scalefactor = 1#
 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 = "File error" Then
   MsgBox imageName & " could not be found."
   Exit Sub
 End If

 ZoomExtents

End Sub

 

Alright that is what I was looking for :D This hopefully should work, I did a quick test and it does place an image for me so hopefully I can get it to the right size and position now :) I'm assuming that the intersection would control that.

Link to comment
Share on other sites

:) ............

 

LOL I used helped from VBA/Cad and google for a good 2 hours of searching, which help did this come from? this site?

Link to comment
Share on other sites

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...