Automatically insert, scale, and plot to PDF many images in separate drawings

Automatically insert, scale, and plot to PDF many images in separate drawings

lmendelson
Participant Participant
1,971 Views
6 Replies
Message 1 of 7

Automatically insert, scale, and plot to PDF many images in separate drawings

lmendelson
Participant
Participant

Each week I will have the task of taking images with a known scale-down factor and delivering these as separate PDFs to markup. It's always a different number of images, but it's always the same scale-down factor. Is there any way to write a macro in order to do this automatically? I have some python and VBA experience but have never used macros with a CAD software (I know it will involve a FOR loop but have no idea how/where to write/execute anything in AutoCAD).

 

Thanks in advance!

 

0 Likes
1,972 Views
6 Replies
Replies (6)
Message 2 of 7

norman.yuan
Mentor
Mentor

When you say "taking images..." it does not sound like an AutoCAD term for referring to anything presented in AutoCAD application, unless you actually refer to image file being inserted into AutoCAD drawing. My guess is that is meant to be the view (or portion of view) of drawing opened in AutoCAD.

 

If so and if you only want to know if it is doable, then yes, it can be automated to print selected views (or portions of them) of currently open drawing into PDFs, and repeat this process to multiple drawings with APIs available in AutoCAD (LISP, VBA/COM, .NET and ObjectARX).

 

If you want to do it yourself, (it looks like you do not have AutoCAD programming experience), you'll need to know AutoCAD very well and know how to program AutoCAD (LISP, VBA/COM or .NET) (like at least in intermediate level). Also, while you post in AutoCAD VBA forum, and AutoCAD VBA is capable of do it, it might be wise to use AutoCAD .NET API.

 

Whatever API you choose to learn/start with, it may take quite sometime to learn to eventually being able to do it.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 7

lmendelson
Participant
Participant

I did mean inserting images into AutoCAD. I need to insert each image from a file folder at the origin, set 0 rotation, set a scale factor, and plot the whole image to PDF at say 1/8" = 1' into the same folder.

0 Likes
Message 4 of 7

norman.yuan
Mentor
Mentor

Well, what I said still stands: you can do it with LISP/VBA(COM API)/.NET API.

 

Take VBA/COM API as example, you can use AddRaster() method of AcadBlock class to insert images into particular layout (ModelSpace or PaperSpace) with given location, scale and rotation angle. Then you can use AcadPlot and AcadPlotConfiguration class to define the portion of view you want to plot (to PDF with given PDF file name). Once it works for a single opened drawing, you can then use a looping logic to apply the process to a list of drawings. 

 

Again, intermediate AutoCAD programming skill level is warranted to get this thing done properly, IMO.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 7

lmendelson
Participant
Participant

Thanks! I will see what I can do.

0 Likes
Message 6 of 7

subhashmecha
Contributor
Contributor

You can try with VBA coding...... like 

 

Sub Ch10_AttachingARaster()
  Dim insertionPoint(0 To 2) As Double
  Dim scalefactor As Double
  Dim rotationAngle As Double
  Dim imageName As String
  Dim rasterObj As AcadRasterImage

Dim processPath As String
processPath = "" 'CHANGE THE PROCESS PATH

Dim filename As String
filename = Dir(processPath & "\*.jpg")

Do While filename <> ""
Debug.Print "Processing " & processPath & filename

Dim oDocopen As AcadDocument
Set oDocopen = Application.Documents.Open(processPath & "\" & filename)

Dim oDoc As AcadDocument
Set oDoc = Application.ActiveDocument

insertionPoint(0) = 5
  insertionPoint(1) = 5
  insertionPoint(2) = 0
  scalefactor = 2
  rotationAngle = 0

  On Error GoTo ERRORHANDLER
  ' Attach the raster image in model space
  Set rasterObj = ThisDrawing.ModelSpace.AddRaster(imageName, insertionPoint, scalefactor, rotationAngle)
  ZoomAll
  Exit Sub

ERRORHANDLER:
  MsgBox Err.Description

oDocopen.Save
oDocopen.Close

Loop

MsgBox ("Macro Execution Succesfully Completed!")

End Sub
 


 

Thank you,
Subhash.
0 Likes
Message 7 of 7

lmendelson
Participant
Participant

Thank you so much! Does this loop through all images in a processPath folder, and does it plot from a specific file with those requirements?

0 Likes