Save idw as dxf

Save idw as dxf

jmlip
Advocate Advocate
483 Views
14 Replies
Message 1 of 15

Save idw as dxf

jmlip
Advocate
Advocate
Can anyone tell me how would I go about adding a path to this code so that I can specify the folder where the dxf should be saved?

Public Sub ExportToDXF()
Dim odoc As DrawingDocument
Set odoc = ThisApplication.ActiveDocument
Dim sFname As String
sFname = odoc.FullFileName
sFname = Left$(sFname, Len(sFname) - 3) & "dxf"
Call odoc.SaveAs(sFname, True)
End Sub

thank you very much in advance!

Joan
0 Likes
484 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable
Well, let ask you a question. Do you want the user to specify or will it be
hard-coded?

Joe ...


wrote in message news:5524733@discussion.autodesk.com...
Can anyone tell me how would I go about adding a path to this code so that I
can specify the folder where the dxf should be saved?

Public Sub ExportToDXF()
Dim odoc As DrawingDocument
Set odoc = ThisApplication.ActiveDocument
Dim sFname As String
sFname = odoc.FullFileName
sFname = Left$(sFname, Len(sFname) - 3) & "dxf"
Call odoc.SaveAs(sFname, True)
End Sub

thank you very much in advance!

Joan
0 Likes
Message 3 of 15

jmlip
Advocate
Advocate
Hi Joe,

Thanks for the reply. It would be hard coded.

Joan
0 Likes
Message 4 of 15

Anonymous
Not applicable
You could do something like this

" Get Full Path and Filename
sFName = oDoc.FullFileName

' Strip off Path
sFName = Right(sFName, Len(sFName) - InStrRev(sFName, "\"))

' Strip off Extension
sFName = Left(sFName, Len(sFName) - 3)

' Add my own path and extension
sFName = "My Full Path to Directory including \ within Parens" & sFName &
"dxf"


--
___________________
Kent Keller
www.kwikmcad.com


wrote in message news:5525061@discussion.autodesk.com...
Hi Joe,

Thanks for the reply. It would be hard coded.

Joan
0 Likes
Message 5 of 15

Anonymous
Not applicable
Very simply,


Dim Filename As String
Filename = "C:\" & Left(ThisApplication.ActiveDocument.DisplayName,
Len(ThisApplication.ActiveDocument.DisplayName) - 4) & ".dxf"


Watch out for word-wrapping in the above example.

However, if I may note, you are not handling potential errors in your
routine. There will be no filename if the document has not been saved. I
would also suggest that you check for a DrawingDocument and not assume that
the user has such opened. I'm sure there may be more but these are what I
see straight away. HTH.

Joe ...


wrote in message news:5525061@discussion.autodesk.com...
Hi Joe,

Thanks for the reply. It would be hard coded.

Joan
0 Likes
Message 6 of 15

jmlip
Advocate
Advocate
Joe,

That works perfect. Thank you very much! I will take your advice and add the error handler and check for DrawingDocument.

Thanks again,

Joan
0 Likes
Message 7 of 15

Anonymous
Not applicable
You're quite welcome, glad I could help.

Joe ...

wrote in message news:5525812@discussion.autodesk.com...
Joe,

That works perfect. Thank you very much! I will take your advice and add
the error handler and check for DrawingDocument.

Thanks again,

Joan
0 Likes
Message 8 of 15

Anonymous
Not applicable
The Display name can be changed and doesn't necessarily have to match the
filename. But I doubt to many people change it so it should work fine in
the majority of cases.

--
___________________
Kent Keller
www.kwikmcad.com


wrote in message news:5525812@discussion.autodesk.com...
Joe,

That works perfect. Thank you very much! I will take your advice and add
the error handler and check for DrawingDocument.

Thanks again,

Joan
0 Likes
Message 9 of 15

Anonymous
Not applicable
I was -just- about to give the same warning...

It's better to use the method Kent provided.

--
T. Ham
CAD Automation & Systems Administrator
CDS Engineering BV

HP xw4300 Workstation
Dual Pentium XEON 3.6 Ghz
4 GB SDRAM
NVIDIA QUADRO FX 3450/4000 SDI (Driver = 8.4.2.6)
250 GB SEAGATE SATA Hard Disc
3Com Gigabit NIC

Windows XP Professional SP2
Autodesk Inventor Series 10 SP3a
--
0 Likes
Message 10 of 15

Anonymous
Not applicable
Just for you to know...I have re-written (a lot of) my code, because on some
parts the DisplayName did not match the FileName.

--
T. Ham
CAD Automation & Systems Administrator
CDS Engineering BV

HP xw4300 Workstation
Dual Pentium XEON 3.6 Ghz
4 GB SDRAM
NVIDIA QUADRO FX 3450/4000 SDI (Driver = 8.4.2.6)
250 GB SEAGATE SATA Hard Disc
3Com Gigabit NIC

Windows XP Professional SP2
Autodesk Inventor Series 10 SP3a
--
0 Likes
Message 11 of 15

jmlip
Advocate
Advocate
Thanks Kent!

I will use the Full File name rather than the Display name. I really appreciate the help!

Joan
0 Likes
Message 12 of 15

jmlip
Advocate
Advocate
Thanks for letting me know Teun. As a VB beginner I really appreciate the guidance and advice from everyone.

Joan
0 Likes
Message 13 of 15

naresh_kalyan
Advocate
Advocate
Thanks to all,
I need to SAVE idw AS dwg. Well, I got the code from this thread. Everything is Ok, at "Call idoc.SaveAs("c:\SG261LPP-DRAWINGS.dwg", True)" facing a error "Invalid procedure call or argument". If I press debug and say continue it is working fine and creating Drgs. I can't able to know what the problem is?

Public Sub saveasdwg()
Set iapp = CreateObject("Inventor.application")
iapp.SilentOperation = True
Set idoc = iapp.Documents.Open("c:\SG261LPP-DRAWINGS.idw", True)
'On Error Resume Next
Call idoc.SaveAs("c:\SG261LPP-DRAWINGS.dwg", True)
idoc.Close
End Sub

Thanks in advance.
NKalyan
0 Likes
Message 14 of 15

Anonymous
Not applicable
you should use Option Explicit in your modules so VB doesn't automatically create objects for you. In the line:

-----------------------------------------------------------
Set idoc = iapp.Documents.Open("c:\SG261LPP-DRAWINGS.idw", True)
-------------------------------------------------------------

you have gotten a document, however, it is not a specific document object, just a generic document. The SaveAs method uses the file extension to determine what translator to use, but the generic Document does not know about the translator for IDW to DWG.

Instead do this:

-----------------------------------------------------------------

Dim oDoc as DrawingDocument
Set oDoc = oApp.Documents.Open("c:\SG261LPP-DRAWINGS.idw", True)
------------------------------------------------------------------
Then it should work.

(P.S. - usually in "typical" VB convention, the first letter denotes the variable type. This is why you see "o" in front of many variables for "object". The "i" in front of your variables would indicate to a VB programmer that the variable is an Integer, which in your case it is not. Doesn't make a difference to the compiler, but it might confuse other programmers using your code.)
0 Likes
Message 15 of 15

naresh_kalyan
Advocate
Advocate
Dear Josh,
Thanks for the reply. Here, I defined the object idoc as
Public idoc As inventor.Document. I think, once I deined the object as Inventor.Document, there's no need to define it again as DrawingDocument.
But, However I ll make a try. I have to install Inventor again. And I will get back to you.

NKalyan
0 Likes