How to import a iges file using vba?

How to import a iges file using vba?

Anonymous
Not applicable
4,151 Views
11 Replies
Message 1 of 12

How to import a iges file using vba?

Anonymous
Not applicable

Hi, I'm new in this forum and I just trying to find the way to make a program to import iges file in Autocad 2017. The next program is what I have until now, this program look in to all folders seeking for any iges file, but I'm no able to import the file in to Autocad. If anyone could help me I'll appreciate it. Thanks 

 

 

Sub DoFolder(Folder)
       Dim SubFolder
       Dim Cadena
       Dim Coordenate(0 To 2) As Double
       Dim myScale As Double
       Dim sFileName As String

       For Each SubFolder In Folder.SubFolders
              DoFolder SubFolder
       Next
       Dim File
       For Each File In Folder.Files

              sFileName = Right(File, 3)

              If sFileName = "dwg" Then
                     Do Until sFileName = ""
                     'Create a Document
                            Dim docObj As AcadDocument
                            Set docObj = ThisDrawing.Application.Documents.Add
       
                     'Open File    
                            Coordenate(0) = 0#: Coordenate(1) = 0#: Coordenate(2) = 0#
                            myScale = 1#
                            ThisDrawing.Import File, Coordenate, myScale
       
                     'Save the document
                            File = Left(File, Len(File) - 3)
                            ThisDrawing.SaveAs File & "dwg"
       
                            sFileName = ""
                     Loop
              End If
       Next
End Sub

 

0 Likes
Accepted solutions (1)
4,152 Views
11 Replies
Replies (11)
Message 2 of 12

Ed__Jobe
Mentor
Mentor

I'm afraid the vba api doesn't have any method to import iges. The db Import method doesn't support as many file types as the IMPORT command. All you could do is call ThisDrawing.Sendcommand(). However, the IMPORT command and IGESIMPORT command are dialog-only commands. So you can't supply any commandline arguments to a call from SendCommand(). So you're kind of stuck. I don't think .NET is going to help either. I can't find any class methods that deal with iges. You can ask in the .NET forum though. Perhaps somebody else knows of a way.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 12

Ed__Jobe
Mentor
Mentor

If you do want to use SendCommand, I found that the IMPORT command responds to setting FILEDIA to 0, whereas the IGESIMPORT command does not. However, if you use the IMPORT command, it responds appropriately to the correct file extension.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 4 of 12

Anonymous
Not applicable

You're right and thanks for your reply, I tried with sending commands from vb and setting filedia = 0, but when the file is imported autocad just show to popup windows displaying that my file is ready, after that I need to click with the mouse to be able to use the import file on the drawing. I already tried many methods to disable this popup windows but nothing works for me. If I find the method to disable this popup windows and make that the file is directly inserted on the drawing the problem will be solved. Do you have any idea how to do it?

 

This is the code I'm using for

 

ThisDrawing.SendCommand "Import" & vbCr & "C:\Users\JEF User\Desktop\Test\2S-BR-2036.igs" & vbCr 

 

and then the popup windows appears waiting for a mouse click  -_-

0 Likes
Message 5 of 12

Ed__Jobe
Mentor
Mentor

Click on the checkbox "Don't show this message again". The notification balloons that popup don't interfere with execution.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 6 of 12

Anonymous
Not applicable

There's not option for that :\, (see attachments)

0 Likes
Message 7 of 12

Ed__Jobe
Mentor
Mentor

I don't see any way around that.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 8 of 12

Anonymous
Not applicable

The problem is that I can not automate this process because the imported file never opens because I need to click the little window on the corner. I need to figure out the way to make the imported file be opened automatically to be able to save it from VBA

0 Likes
Message 9 of 12

Ed__Jobe
Mentor
Mentor

Unfortunately, I don't think you will accomplish it via scripting the command line. The only other info I could find is in this post.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 10 of 12

Anonymous
Not applicable
Accepted solution

This is the answer for my question:

 

 

      Dim File as String

 

      File = Path of the File

 

      'Create Drawing 
            Dim docObj As AcadDocument
            Set docObj = ThisDrawing.Application.Documents.Add

      'Open
            ThisDrawing.SendCommand "_Import" & vbCr & File & vbCr
            Sleep 1000 'Because my computer I have a slow computer 
            ThisDrawing.SendCommand "IMPORTTRANSLATIONRESULT" & vbCr
            ThisDrawing.SendCommand "REGEN" & vbCr

 

      'Save
            ThisDrawing.SaveAs Left(File, Len(File) - 4)

      'Close
            ThisDrawing.Close

Message 11 of 12

Anonymous
Not applicable

Hey @Anonymous . Thanks for posting this. The sleep function you kept calling wouldn't work. Not sure what I was doing wrong or what you referenced to use the internal timer.

However, found a version similar to your import approach with a custom Sleep workaround here: VBA Convert 3D .STEP to older .DWG for AutoCAD  by @Anonymous 

Figure I'd share since I can't stand AutoCAD's dreaded Notificaiton Bubbles during automation routines that leverage the command line. They cause so many snags, and the potential of a decent program creation. 

 

Thanks,

0 Likes
Message 12 of 12

JOSE-MIGUEL_AUNION
Explorer
Explorer

Hi, the SLEEP function is not built in by default in the Visual Basic system. You have to import it via this declaration:

 

Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal milliseconds As LongPtr)

 

for Office 64 bits.

 

really handy.

 

0 Likes