Discussion Groups

All Discussion Groups » Visual Basic Customization

Thread: File Importing


Permlink Replies: 22 - Last Post: Jan 8, 2009 2:34 PM Last Post By: cadger
hanchris

Posts: 259
Registered: 10/24/07
File Importing
Posted: Dec 22, 2008 10:59 PM
  Click to reply to this thread Reply
Is a way to access the File>>Import command, using VBA?

I managed to get myself a list of drawings that I would like to convert; but don't know how to do this through VBA. Is there some equivalent command line driven function for VBA that is similar to AutoLISP's (command "-Import")?

Thanks,
Chris
Ramyahari

Posts: 16
Registered: 07/09/08
Re: File Importing
Posted: Dec 23, 2008 4:20 AM   in response to: hanchris in response to: hanchris
  Click to reply to this thread Reply
Try this,it may help u

Sub test()
ThisDrawing.SendCommand "filedia" & vbCr & "0" & vbCr
ThisDrawing.SendCommand "import" & vbCr & "ur filepath and ur filename" & vbCr
ThisDrawing.SendCommand "filedia" & vbCr & "1" & vbCr
End Sub


and also look into this

Import Example



Using Programming Languages other than VBA

Sub Example_Import()
' This example will create a new drawing. Be sure to save
' your work and start a new drawing before running this example.
' This example creates a circle. It then exports the drawing
' to a file called DXFExprt.DXF. It then opens a new drawing
' and imports the file.

' Create the circle for visual representation
Dim circleObj As AcadCircle
Dim centerPt(0 To 2) As Double
Dim radius As Double
centerPt(0) = 2: centerPt(1) = 2: centerPt(2) = 0
radius = 1
Set circleObj = ThisDrawing.ModelSpace.AddCircle(centerPt, radius)
ZoomAll

' Create an empty selection set
Dim sset As AcadSelectionSet
Set sset = ThisDrawing.SelectionSets.Add("TEST")

' Export the current drawing to the file specified above.
Dim exportFile As String
exportFile = "C:\my documents\DXFExprt" ' Adjust path for your system
ThisDrawing.Export exportFile, "DXF", sset

' Open a new drawing
Dim Acad As AcadApplication
Dim newdoc As AcadDocument
Set Acad = ThisDrawing.Application
Set newdoc = Acad.Documents.Add("acad.dwt")

' Define the import
Dim importFile As String
Dim InsertPoint(0 To 2) As Double
Dim scalefactor As Double
importFile = "C:\my documents\DXFExprt.dxf" ' Adjust path for your system
InsertPoint(0) = 0#: InsertPoint(1) = 0#: InsertPoint(2) = 0#
scalefactor = 2#

' Import the file
ThisDrawing.Import importFile, InsertPoint, scalefactor
ZoomAll

End Sub
Comments?
hanchris

Posts: 259
Registered: 10/24/07
Re: File Importing
Posted: Dec 23, 2008 6:19 PM   in response to: Ramyahari in response to: Ramyahari
  Click to reply to this thread Reply
Thank you.

This has been very helpful and was exactly what I was looking for.

I ended up using the first method; but I will also be looking at the second one.

Thanks again
hanchris

Posts: 259
Registered: 10/24/07
Re: File Importing
Posted: Jan 2, 2009 2:13 PM   in response to: Ramyahari in response to: Ramyahari
  Click to reply to this thread Reply
All right, so I have tried your import example and I am getting hung up at the following line:


ThisDrawing.Import importFile, InsertPoint, scalefactor


Well I believe it is because the "InsertPoint" by itself is not recognized. It sees a 0 (as a Double) for "InsertPoint(0)", "InsertPoint(1)", "InsertPoint(2)"; but nothing for just "InsertPoint".

Any help?

I just copied the above program and fooled around with different combinations myself, trying to fix it.

Thanks.
hanchris

Posts: 259
Registered: 10/24/07
Re: File Importing
Posted: Jan 5, 2009 2:33 PM   in response to: hanchris in response to: hanchris
  Click to reply to this thread Reply
Attachment Import_Test.zip (14.9 KB)
So, I am attaching an example of the code that I currently have. I would like to try and Import a dgn file and create a batch converter.

First, can the Import be used this way?

Second (even if first is no), why when you go to debug mode is "InsertionPoint" not recognized as a variable, like "scalefactor" is? What am I doing wrong in the definition?

Note: the attached DGN file should be placed on the raw C-drive and I do not believe you need the application to view DGN files.

Thanks,
Chris
cadger

Posts: 341
Registered: 03/28/07
Re: File Importing
Posted: Jan 6, 2009 3:00 AM   in response to: hanchris in response to: hanchris
  Click to reply to this thread Reply
Chris,

It might be a problem with the dgn importing. What version autocad are you using and can you import dgn files manually? With the Import command? The code you attached seems to work fine when you substitute a dxf file in place of the dgn file. The only experience that I have with dgn files is with autocad map with which a custom batch converter could be created.

When debugging, the highlighted variables are not always shown completely with tooltips, it could be much more helpful to open up 'View' 'Locals Window'. There you can note that InsertPoint(0 to 2) is ok.

hope is useful
cadger
hanchris

Posts: 259
Registered: 10/24/07
Re: File Importing
Posted: Jan 6, 2009 12:41 PM   in response to: cadger in response to: cadger
  Click to reply to this thread Reply
cadger,

Thanks for the help I was sort of thinking that perhaps import was not going to work for dgn files, especially after Googling "Import" VBA and AutoCAD. I just had to hold out hope. I am using AutoCAD 2009 and I can manually convert one file at a time, I am mostly just trying to batch the process some how. I also have a LISP file that I can run once I convert the dgn file, so all our settings can be incorporated.

Do you know of any way you can make a window that pops up using the "SendCommand" recognized by VBA? I am asking because I can use the first method described by ramyahari (above); but I cannot save the drawing I want since I cannot find it once it is created and the program is running.

I have to admit VBA may be more powerful, than LISP; but at least you can trace commands easier in LISP...well I can. I have even tried just using the menu I created; but it always recieve an error loading the DVB file, through the LISP methods described at [Afralisp|http://www.afralisp.net/vl/vl-vba.htm] and I am so close to this program that I do not want to go back.
Paul Richardson
Re: File Importing
Posted: Jan 6, 2009 1:28 PM   in response to: hanchris in response to: hanchris
  Click to reply to this thread Reply
Attachment Insert.png (45.3 KB)


Looking at insert in the object browser - it does
not list dgn as a possible file type for the file paramater.

With a quick test here - that seems to be the
case...

 

You can do it in LISP with (command "import"
"c:\\test.dgn" "0,0" "" "" ""). ScriptPro will batch process

files I believe - haven't used it...

 

You could the dos 'for' statement to batch process
your files. Old school  baby... works like a charm.

If you don't find another way - let me know and
I'll write a 'for' script for you.


<hanchris> wrote in message news:6098958@discussion.autodesk.com...
cadger,
Thanks for the help I was sort of thinking that perhaps import was not going
to work for dgn files, especially after Googling "Import" VBA and AutoCAD. I
just had to hold out hope. I am using AutoCAD 2009 and I can manually convert
one file at a time, I am mostly just trying to batch the process some how. I
also have a LISP file that I can run once I convert the dgn file, so all our
settings can be incorporated. Do you know of any way you can make a window
that pops up using the "SendCommand" recognized by VBA? I am asking because I
can use the first method described by ramyahari (above); but I cannot save the
drawing I want since I cannot find it once it is created and the program is
running. I have to admit VBA may be more powerful, than LISP; but at least you
can trace commands easier in LISP...well I can. I have even tried just using
the menu I created; but it always recieve an error loading the DVB file,
through the LISP methods described at
[Afralisp|http://www.afralisp.net/vl/vl-vba.htm] and I am so close to this
program that I do not want to go back.

Paul Richardson
Re: File Importing
Posted: Jan 6, 2009 2:00 PM   in response to: Paul Richardson in response to: Paul Richardson
  Click to reply to this thread Reply


actually 'for' will loop and open each file in a
directory. since we cannot directly open dgn file this would be
tough...


"Paul Richardson" <prichardson<lastpoint> wrote in message news:6099015@discussion.autodesk.com...


Looking at insert in the object browser - it does
not list dgn as a possible file type for the file paramater.

With a quick test here - that seems to be
the case...

 

You can do it in LISP with (command "import"
"c:\\test.dgn" "0,0" "" "" ""). ScriptPro will batch process

files I believe - haven't used it...

 

You could the dos 'for' statement to batch
process your files. Old school  baby... works like a charm.

If you don't find another way - let me know and
I'll write a 'for' script for you.


<hanchris> wrote in message news:6098958@discussion.autodesk.com...
cadger,
Thanks for the help I was sort of thinking that perhaps import was not going
to work for dgn files, especially after Googling "Import" VBA and AutoCAD. I
just had to hold out hope. I am using AutoCAD 2009 and I can manually
convert one file at a time, I am mostly just trying to batch the process
some how. I also have a LISP file that I can run once I convert the dgn
file, so all our settings can be incorporated. Do you know of any way you
can make a window that pops up using the "SendCommand" recognized by VBA? I
am asking because I can use the first method described by ramyahari (above);
but I cannot save the drawing I want since I cannot find it once it is
created and the program is running. I have to admit VBA may be more
powerful, than LISP; but at least you can trace commands easier in
LISP...well I can. I have even tried just using the menu I created; but it
always recieve an error loading the DVB file, through the LISP methods
described at [Afralisp|http://www.afralisp.net/vl/vl-vba.htm] and I am so
close to this program that I do not want to go
back.

hanchris

Posts: 259
Registered: 10/24/07
Re: File Importing
Posted: Jan 6, 2009 2:07 PM   in response to: Paul Richardson in response to: Paul Richardson
  Click to reply to this thread Reply
Really the For Loop has to open a document because I have given up doing this is VBA. I am just trying to move the Listbox contents into LISP and using that instead, so I thought the For loop could save either a concantinated string or an array and bring it into LISP as a List.

In other words, I am just worried about getting the file names as strings into LISP.
Paul Richardson
Re: File Importing
Posted: Jan 6, 2009 2:55 PM   in response to: hanchris in response to: hanchris
  Click to reply to this thread Reply


Cadger has the right idea with 'sendcommand' - much
easier than 'for'.You'll need to add logic

for saving the file... I only tested this batch
process on one file...~)

 

</FONT></DIV>
<DIV><FONT face="Arial" size="2">Sub LoopDir(fileDir As String, file As 
String)<BR>  'add testing to get users current value...<BR>   
<BR>  Do While file <> ""<BR>    Dgn2Dwg 
file<BR>    file = dir<BR>  Loop</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Arial" size="2">End Sub</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Arial" size="2">Sub Dgn2Dwg(file As String)<BR>    
'add testing to get users current value first<BR>    'and set it 
back if necessary.<BR>    ThisDrawing.SetVariable "filedia", 
0<BR>    ThisDrawing.SendCommand "_import" &amp; 
_<BR>        vbCr &amp; file &amp; vbCr &amp; 
"0,0" &amp; vbCr &amp; vbCr &amp; vbCr &amp; vbCr<BR>End Sub</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Arial" size="2">Sub test()<BR>  Dim fileDir As 
String<BR>  fileDir = "c:\"</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Arial" size="2">  Dim file As String<BR>  file = 
dir(fileDir &amp; "*.dgn")<BR>  <BR>  LoopDir fileDir, file<BR>End 
Sub</FONT></DIV>
<DIV><FONT face="Arial" size="2">


<hanchris> wrote in message news:6099055@discussion.autodesk.com...
Really
the For Loop has to open a document because I have given up doing this is VBA.
I am just trying to move the Listbox contents into LISP and using that
instead, so I thought the For loop could save either a concantinated string or
an array and bring it into LISP as a List. In other words, I am just worried
about getting the file names as strings into LISP.

Paul Richardson
Re: File Importing
Posted: Jan 6, 2009 3:31 PM   in response to: Paul Richardson in response to: Paul Richardson
  Click to reply to this thread Reply


sorry I could have tested that a bit better after
refactoring it... this

version sends the full file path to the
Dgn2Dwg function.

</FONT></DIV>
<DIV><FONT face="Arial" size="2">Sub main()<BR>  'add testing to get users 
current value...<BR>  Dim fileDir As String<BR>  fileDir = 
"c:\"<BR> <BR>  Dim file As String<BR>  file = Dir(fileDir &amp; 
"*.dgn")</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Arial" size="2">  Do While file <> 
""<BR>    Dgn2Dwg fileDir &amp; file<BR>    file = 
Dir<BR>  Loop<BR> <BR>End Sub<BR> <BR>Sub Dgn2Dwg(file As 
String)<BR>    'add testing to get users current value 
first<BR>    'so you can set it back as 
needed.<BR>    ThisDrawing.SetVariable "filedia", 
0<BR>    ThisDrawing.SendCommand "_import" &amp; 
_<BR>        vbCr &amp; file &amp; vbCr &amp; 
"0,0" &amp; vbCr &amp; vbCr &amp; vbCr &amp; vbCr<BR>    
ThisDrawing.SetVariable "filedia", 1<BR>End Sub</FONT></DIV>
<DIV><FONT face="Arial" size="2">


"Paul Richardson" <prichardson<lastpoint> wrote in message news:6099119@discussion.autodesk.com...


Cadger has the right idea with 'sendcommand' -
much easier than 'for'.You'll need to add logic

for saving the file... I only tested this batch
process on one file...~)

 

</FONT></DIV>
  <DIV><FONT face="Arial" size="2">Sub LoopDir(fileDir As String, file As 
  String)<BR>  'add testing to get users current value...<BR>   
  <BR>  Do While file <> ""<BR>    Dgn2Dwg 
  file<BR>    file = dir<BR>  Loop</FONT></DIV>
  <DIV> </DIV>
  <DIV><FONT face="Arial" size="2">End Sub</FONT></DIV>
  <DIV> </DIV>
  <DIV><FONT face="Arial" size="2">Sub Dgn2Dwg(file As String)<BR>    
  'add testing to get users current value first<BR>    'and set 
  it back if necessary.<BR>    ThisDrawing.SetVariable "filedia", 
  0<BR>    ThisDrawing.SendCommand "_import" &amp; 
  _<BR>        vbCr &amp; file &amp; vbCr 
  &amp; "0,0" &amp; vbCr &amp; vbCr &amp; vbCr &amp; vbCr<BR>End 
Sub</FONT></DIV>
  <DIV> </DIV>
  <DIV><FONT face="Arial" size="2">Sub test()<BR>  Dim fileDir As 
  String<BR>  fileDir = "c:\"</FONT></DIV>
  <DIV> </DIV>
  <DIV><FONT face="Arial" size="2">  Dim file As String<BR>  file = 
  dir(fileDir &amp; "*.dgn")<BR>  <BR>  LoopDir fileDir, file<BR>End 
  Sub</FONT></DIV>
  <DIV><FONT face="Arial" size="2">


<hanchris> wrote in message news:6099055@discussion.autodesk.com...
Really
the For Loop has to open a document because I have given up doing this is
VBA. I am just trying to move the Listbox contents into LISP and using that
instead, so I thought the For loop could save either a concantinated string
or an array and bring it into LISP as a List. In other words, I am just
worried about getting the file names as strings into
LISP.

Paul Richardson
Re: File Importing
Posted: Jan 6, 2009 4:30 PM   in response to: Paul Richardson in response to: Paul Richardson
  Click to reply to this thread Reply


this will save the file and close
it...

</FONT></DIV>
<DIV><FONT face="Arial" size="2">Sub Dgn2Dwg(file As String)<BR>    
Application.ActiveDocument.SetVariable "filedia", 0<BR>    
Application.ActiveDocument.SendCommand "_import" &amp; 
_<BR>        vbCr &amp; file &amp; vbCr &amp; 
"0,0" &amp; vbCr &amp; vbCr &amp; vbCr &amp; vbCr<BR>    
Application.ActiveDocument.SaveAs file<BR>    
Application.ActiveDocument.Close<BR>End Sub</FONT></DIV>
<DIV><FONT face="Arial" size="2">


"Paul Richardson" <prichardson<lastpoint> wrote in message news:6099162@discussion.autodesk.com...


sorry I could have tested that a bit better after
refactoring it... this

version sends the full file path to the
Dgn2Dwg function.

</FONT></DIV>
  <DIV><FONT face="Arial" size="2">Sub main()<BR>  'add testing to get users 
  current value...<BR>  Dim fileDir As String<BR>  fileDir = 
  "c:\"<BR> <BR>  Dim file As String<BR>  file = Dir(fileDir 
  &amp; "*.dgn")</FONT></DIV>
  <DIV> </DIV>
  <DIV><FONT face="Arial" size="2">  Do While file <> 
  ""<BR>    Dgn2Dwg fileDir &amp; file<BR>    file 
  = Dir<BR>  Loop<BR> <BR>End Sub<BR> <BR>Sub Dgn2Dwg(file As 
  String)<BR>    'add testing to get users current value 
  first<BR>    'so you can set it back as 
  needed.<BR>    ThisDrawing.SetVariable "filedia", 
  0<BR>    ThisDrawing.SendCommand "_import" &amp; 
  _<BR>        vbCr &amp; file &amp; vbCr 
  &amp; "0,0" &amp; vbCr &amp; vbCr &amp; vbCr &amp; vbCr<BR>    
  ThisDrawing.SetVariable "filedia", 1<BR>End Sub</FONT></DIV>
  <DIV><FONT face="Arial" size="2">


"Paul Richardson" <prichardson<lastpoint> wrote in message news:6099119@discussion.autodesk.com...


Cadger has the right idea with 'sendcommand' -
much easier than 'for'.You'll need to add logic

for saving the file... I only tested this batch
process on one file...~)

 

</FONT></DIV>
    <DIV><FONT face="Arial" size="2">Sub LoopDir(fileDir As String, file As 
    String)<BR>  'add testing to get users current value...<BR>   
    <BR>  Do While file <> ""<BR>    Dgn2Dwg 
    file<BR>    file = dir<BR>  Loop</FONT></DIV>
    <DIV> </DIV>
    <DIV><FONT face="Arial" size="2">End Sub</FONT></DIV>
    <DIV> </DIV>
    <DIV><FONT face="Arial" size="2">Sub Dgn2Dwg(file As 
    String)<BR>    'add testing to get users current value 
    first<BR>    'and set it back if 
    necessary.<BR>    ThisDrawing.SetVariable "filedia", 
    0<BR>    ThisDrawing.SendCommand "_import" &amp; 
    _<BR>        vbCr &amp; file &amp; vbCr 
    &amp; "0,0" &amp; vbCr &amp; vbCr &amp; vbCr &amp; vbCr<BR>End 
    Sub</FONT></DIV>
    <DIV> </DIV>
    <DIV><FONT face="Arial" size="2">Sub test()<BR>  Dim fileDir As 
    String<BR>  fileDir = "c:\"</FONT></DIV>
    <DIV> </DIV>
    <DIV><FONT face="Arial" size="2">  Dim file As String<BR>  file = 
    dir(fileDir &amp; "*.dgn")<BR>  <BR>  LoopDir fileDir, file<BR>End 
    Sub</FONT></DIV>
    <DIV><FONT face="Arial" size="2">


<hanchris> wrote in message news:6099055@discussion.autodesk.com...
Really
the For Loop has to open a document because I have given up doing this is
VBA. I am just trying to move the Listbox contents into LISP and using
that instead, so I thought the For loop could save either a concantinated
string or an array and bring it into LISP as a List. In other words, I am
just worried about getting the file names as strings into
LISP.

hanchris

Posts: 259
Registered: 10/24/07
Re: File Importing
Posted: Jan 7, 2009 5:05 AM   in response to: Paul Richardson in response to: Paul Richardson
  Click to reply to this thread Reply
I believe I am almost there; but I am still having a problem, when typing it in like you have it (without HTML of course). The problem is the original window gets saved. There is a work around; but I basically have to show another Userform and wait for an addition input. I guess this is do-able; but is there another work around.

I have tried putting a delay in there too, which looks like the following; but that does not help.



Sub MyDelayMacro

For iCount = 1 to 1000
Next iCount

End Sub



I am wondering if there is a way you can stop all procedures, so AutoCAD can catch up and pop the new imported drawing up and than start after a pre-determined time?

Thanks again for the help.
Paul Richardson
Re: File Importing
Posted: Jan 7, 2009 1:07 PM   in response to: hanchris in response to: hanchris
  Click to reply to this thread Reply


Sorry dude - vba sendcommand, forms and
timers - oh my!  You're on your own...~) gl...


<hanchris> wrote in message news:6099658@discussion.autodesk.com...
I
believe I am almost there; but I am still having a problem, when typing it in
like you have it (without HTML of course). The problem is the original window
gets saved. There is a work around; but I basically have to show another
Userform and wait for an addition input. I guess this is do-able; but is there
another work around. I have tried putting a delay in there too, which looks
like the following; but that does not help. Sub MyDelayMacro For iCount
= 1 to 1000 Next iCount End Sub I am wondering if there is a way you
can stop all procedures, so AutoCAD can catch up and pop the new imported
drawing up and than start after a pre-determined time? Thanks again for the
help.

Laurie Comerford
Re: File Importing
Posted: Jan 6, 2009 9:26 PM   in response to: hanchris in response to: hanchris
  Click to reply to this thread Reply
Attachment clsVLAX.zip (1.9 KB)
Hi hanchris,

Here is another approach. Use VBA along the lines of the code below to
write a lisp program. The code is incomplete, but will give you a
staring point.

At the end you can get away with using one SendCommand only to load the
lisp file you write.


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub ImportDGN()
On Error GoTo ErrorHandler
Dim j As Integer
Dim sFileLine As String
Dim sFileSpec As String
sFileSpec = "C:\Temp\MyLispFile.lsp"
j = FreeFile
Open sFileSpec For Output As #j
sFileLine = "defun ImportDGN ()"
' I doubt if you need to set the filedia variable for the
' lisp to work, but if you do, simply put the lisp code in
' here to save the current value and set the new value to 0
Print #j, sFileLine
For Each Item In items_in_your_listbox ' Adjust this as needed to
' get the data from your listbox. Note you could use code posted by
' Paul to process
' all the files in the one folder without putting them in a list box.
sFileLine = " (command ""import"" ""ListboxItem"" ""0,0"" """" """"
"""")"
Print #j, sFileLine

Next
sFileLine = ")"
Print #j, sFileLine
sFileLine = "(ImportDGN)"
Print #j, sFileLine
Close j
ThisDrawing.SendCommand "(Load " & sFileSpec & ")"
Exit Sub
ErrorHandler:
MsgBox "Unable to process data in Sub 'ImportDGN' due to:" & vbCrLf &
Err.Description, vbCritical
Err.Clear
End Sub ' ImportDGN



A better solution again is to use the "EvalLispExpression" function from
the attached version of Frank Oquendo's clsVLAX. This enables removal
of all instances of the dreaded "Sendcommand"


Regards


Laurie Comerford



hanchris wrote:
Really the For Loop has to open a document because I have given up doing
this is VBA. I am just trying to move the Listbox contents into LISP and
using that instead, so I thought the For loop could save either a
concantinated string or an array and bring it into LISP as a List. In
other words, I am just worried about getting the file names as strings
into LISP.
Paul Richardson
Re: File Importing
Posted: Jan 6, 2009 2:13 PM   in response to: Paul Richardson in response to: Paul Richardson
  Click to reply to this thread Reply


Of course we don't have to open the file as we
loop. duh....

Give me a minute or 10 and I'll write it up to
see if it works.


"Paul Richardson" <prichardson<lastpoint> wrote in message news:6099024@discussion.autodesk.com...


actually 'for' will loop and open each file in a
directory. since we cannot directly open dgn file this would be
tough...


"Paul Richardson" <prichardson<lastpoint> wrote in message news:6099015@discussion.autodesk.com...


Looking at insert in the object browser - it
does not list dgn as a possible file type for the file
paramater.

With a quick test here - that seems to be
the case...

 

You can do it in LISP with (command "import"
"c:\\test.dgn" "0,0" "" "" ""). ScriptPro will batch process

files I believe - haven't used
it...

 

You could the dos 'for' statement to batch
process your files. Old school  baby... works like a
charm.

If you don't find another way - let me know and
I'll write a 'for' script for you.


<hanchris> wrote in message news:6098958@discussion.autodesk.com...
cadger,
Thanks for the help I was sort of thinking that perhaps import was not
going to work for dgn files, especially after Googling "Import" VBA and
AutoCAD. I just had to hold out hope. I am using AutoCAD 2009 and I can
manually convert one file at a time, I am mostly just trying to batch the
process some how. I also have a LISP file that I can run once I convert
the dgn file, so all our settings can be incorporated. Do you know of any
way you can make a window that pops up using the "SendCommand" recognized
by VBA? I am asking because I can use the first method described by
ramyahari (above); but I cannot save the drawing I want since I cannot
find it once it is created and the program is running. I have to admit VBA
may be more powerful, than LISP; but at least you can trace commands
easier in LISP...well I can. I have even tried just using the menu I
created; but it always recieve an error loading the DVB file, through the
LISP methods described at [Afralisp|http://www.afralisp.net/vl/vl-vba.htm]
and I am so close to this program that I do not want to go
back.

cadger

Posts: 341
Registered: 03/28/07
Re: File Importing
Posted: Jan 6, 2009 1:35 PM   in response to: hanchris in response to: hanchris
  Click to reply to this thread Reply
Chris,

I'm certain it's possible in 2009 if you can do it manually or with sendcommand; most of my experience is with 2004.

'ThisDrawing.SendCommand "filedia" & vbCr & "1" & vbCr' sets the variable 'filedia' (File dialogue on/off) just remove those and you will see where the files go (if they are being created).

The lisp file to incorporate settings can be included in the vba program as well. I wouldn't go so far to say that vba is more powerful than lisp, each are more powerful in their own ways, and of course easier the more familiar you are with them.

cadger
hanchris

Posts: 259
Registered: 10/24/07
Re: File Importing
Posted: Jan 6, 2009 1:56 PM   in response to: hanchris in response to: hanchris
  Click to reply to this thread Reply
Thanks everyone for the help.

I just have one more question: I have decided to just use VBA for its user form; but having trouble now sending a variable to LISP. In VBA I get an "error in setting system variable."

The variable I want to send is from a Listbox :ProcessList.List(0). If I could do that then a simple For statement will be do-able, to create a List (I believe).


Here is what I have to set a variable (just worrying about one now):

Dim UserList As String
ThisDrawing.SetVariable UserList, ProcessList.List(0)


Right now I am just trying to display the list with

(alert (getvar "UserList"))

But I am assuming all I will nee to use it is use a simple:
(setq Test (getvar "UserList"))


After the above, I am just thinking about replacing 0 with an i and using the following For statement:

For i = ProcessList.ListCount - 1 To 0 Step -1


Thanks again for your help.
cadger

Posts: 341
Registered: 03/28/07
Re: File Importing
Posted: Jan 8, 2009 2:09 AM   in response to: hanchris in response to: hanchris
  Click to reply to this thread Reply
hi, i don't know if you figured this out yet, but an easy way to transfer variables between lisp and vba is to use predefined variables...
e.g. USERS1, USERS2, USERS3 etc. for strings

thisdrawing.setvariable "USERS1" , "blahblah"
(getvar "USERS1")
Laurie Comerford
Re: File Importing
Posted: Jan 8, 2009 3:35 AM   in response to: hanchris in response to: hanchris
  Click to reply to this thread Reply
Hi hanchris,

A couple of things.

If you look at the code I posted yesterday it shows a way of avoiding
the problem of direct transfer between VBA variables and lisp variables.

OR

The VLAX class posted with the code enables direct transfer between VBA
variables and lisp variables - have you looked at it?

If you put your code inside code markers as shown below it will not be
totally stuffed up by the Autodesk incompetents and it will make it a
lot easier to read and therefore to help you.


Place code here so that code formatting is not lost.


Regards


Laurie Comerford

hanchriswrote:
Thanks everyone for the help. I just have one more question: I have
decided to just use VBA for its user form; but having trouble now
sending a variable to LISP. In VBA I get an "error in setting system
variable." The variable I want to send is from a Listbox
:ProcessList.List(0). If I could do that then a simple For statement
will be do-able, to create a List (I believe). Here is what I have to
set a variable (just worrying about one now): Dim UserList As String
ThisDrawing.SetVariable UserList, ProcessList.List(0) Right now I am
just trying to display the list with (alert (getvar "UserList")) But I
am assuming all I will nee to use it is use a simple: (setq Test (getvar
"UserList")) After the above, I am just thinking about replacing 0 with
an i and using the following For statement: For i =
ProcessList.ListCount - 1 To 0 Step -1 Thanks again for your help.
hanchris

Posts: 259
Registered: 10/24/07
Re: File Importing
Posted: Jan 8, 2009 11:43 AM   in response to: Laurie Comerford in response to: Laurie Comerford
  Click to reply to this thread Reply
cadger,

Thanks, I have tried that the problem is I want to be able to do this with an open list that could be more than 5 variables and I have to grab them all before VBA stops.

It was suggested on another board that I might want to try writing to a text file and then reading it in LISP. I couild then delete the file when I am done. I do not feel comfortiable in my VBA program to go tampering with the registry files, which I know is another way I could store data.


Laurie,

Thanks also, where is that program? Is it here?
http://discussion.autodesk.com/forums/thread.jspa?messageID=6057793&#6057793

Also, when people mention "code markers" what do you mean? Is it the same as the Quote markers. I only ask because a various of other sites I visit have a difference between quote markers and code markers; but if they are the same here then I will use them from now on.


Thanks again everyone.
cadger

Posts: 341
Registered: 03/28/07
Re: File Importing
Posted: Jan 8, 2009 2:15 PM   in response to: hanchris in response to: hanchris
  Click to reply to this thread Reply
at the top of the message board they have (relatively new) instructions for posting code. Put

{ code }
don't use spaces between the squigglies and code
code here except use no spaces

{ code }

modified from the vanilla vba help

Dim MyIndex, FileNumber
 
    FileNumber = FreeFile    ' Get unused file
        ' number.
    Open "c:\TESTttt.txt" For Output As #FileNumber    ' Create file name.
    For MyIndex = 1 To 5    ' Loop 5 times.
          Write #FileNumber, "This is a sample." & myindex    ' Output text.
    Next MyIndex
    Close #FileNumber    ' Close file.


i don't know how to open a file in lisp though