VBA export drawing to bmp

VBA export drawing to bmp

tuli1954
Participant Participant
647 Views
3 Replies
Message 1 of 4

VBA export drawing to bmp

tuli1954
Participant
Participant

Hello,

Trying to export a dwg to a bitmap format.

 

Neither of the two options shown below worked.

What am I missing?

 

Thank you

 

Sub Export_image()

Dim exportFile As String
exportFile = "c:\tmp\image.bmp"

Dim sset As acadSelectionSet

ThisDrawing.SelectionSets.Item("TEST").Delete
Set sset = ThisDrawing.SelectionSets.Add("TEST")
' option 1
Thisdrawing.saveasbitmap exportFile, 1200, 800
' option 2
Thisdrawing.export expotfile,"bmp", sset
End Sub

0 Likes
Accepted solutions (2)
648 Views
3 Replies
Replies (3)
Message 2 of 4

seabrahenrique
Advocate
Advocate
Accepted solution

Try this:

 

 

Sub Example_Export()
    
    ' Define the name for the exported file
    Dim exportFile As String
    exportFile = "c:\tmp\image"
    
    ' Create an selection set with all elements in a drawing
    Dim sset As AcadSelectionSet
    Set sset = ThisDrawing.SelectionSets.Add("TEST8")
    sset.Select acSelectionSetAll
    
    ' Export the current drawing to the file specified above.
    ThisDrawing.Export exportFile, "bmp", sset
    
End Sub

 

 

I guess you created your selection set but they don't have elements... so, you also have to add elements in your selection set using " sset.Select acSelectionSetAll" or another method.

 

Another thing is: i an "exportfilename" variable, you don't have to use de extension of image. Because you already will to specify that in a a function "Thisdrawing.export expotfile,"bmp", sset"

 

I hope can help u 🙂

 

0 Likes
Message 3 of 4

tuli1954
Participant
Participant
Accepted solution

It works, Thank you

Message 4 of 4

seabrahenrique
Advocate
Advocate

@tuli1954 Nice!

 

Remember mark the answer as solution 🙂

 

Thanks!

0 Likes