Batch Saving model to IDW or inventor dwg

Batch Saving model to IDW or inventor dwg

tracey
Enthusiast Enthusiast
947 Views
4 Replies
Message 1 of 5

Batch Saving model to IDW or inventor dwg

tracey
Enthusiast
Enthusiast

Hi,

 

I have used this code to successfully to create rules to batch save step files and dwg files (AutoCAD) but I really want inventor dwg's .  I have simply changed out .stp to .dwg which has worked but if I do .idw I get a parameter error.

 

Format:HTML Format
Version:1.0
StartHTML: 165
EndHTML: 26203
StartFragment: 314
EndFragment: 26171
StartSelection: 314
EndSelection: 314

SyntaxEditor Code Snippet

 'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = ThisDoc.FileName(False) 'without extension

If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "Batch DRAWING File Creation")
Exit Sub
End If
'get user input
RUsure = MessageBox.Show ( _
"This will create a DRAWING file for all components." _
& vbLf & " " _
& vbLf & "Are you sure you want to create DRAWING file for all of the assembly components?" _
& vbLf & "This could take a while.", "Confirm - Batch DRAWING File Creation ",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
Return
Else
End If
'- - - - - - - - - - - - -STEP setup - - - - - - - - - - - -
oPath = ThisDoc.Path
'get DRAWING target folder path
oFolder = oPath & "\DRAWING FILES\"
'Check for the drawing folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If

'- - - - - - - - - - - - -Assembly Export- - - - - - - - - - - -
oTime = Now.ToString("HH:mm:ss")
ThisDoc.Document.SaveAs(oFolder & oAsmName & (".idw"), True)

'- - - - - - - - - - - - -Components - - - - - - - - - - - -
'
look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
'work the referenced models
For Each oRefDoc In oRefDocs
Dim oCurFile As Document

oCurFile = ThisApplication.Documents.Open(oRefDoc.FullFileName, True)
oCurFileName = oCurFile.FullFileName
If oRefDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure Then

'defines backslash As the subdirectory separator
Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar

'find the postion of the last backslash in the path
FNamePos = InStrRev(oCurFileName, "\", -1)
'get the file name with the file extension
Name = Right(oCurFileName, Len(oCurFileName) - FNamePos)
'get the file name (without extension)
ShortName = Left(Name, Len(Name) - 4)

Try

oCurFile.SaveAs(oFolder & ShortName & ("idw") , True)

Catch
MessageBox.Show("Error processing " & oCurFileName, "DRAWING File Creation Error")

End Try
End If
oCurFile.Close

Next

'- - - - - - - - - - - - -
MessageBox.Show("New Files Created in: " & vbLf & oFolder, "Batch DRAWING File Creation")
'open the folder where the new files are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)

Is there a way of specifying?

 

Many thanks

 

Tracey P

 

(Thnk you to the creator of this code by the way.  I don't know who you are but found the code from someone who also used it.)

0 Likes
948 Views
4 Replies
Replies (4)
Message 2 of 5

MechMachineMan
Advisor
Advisor

The inventor dwg's have their own save method via the API.

 

See the attached resource:

 

 

(specifically .SaveAsInventorDwg)

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-902B2746-25C9-41A6-953E-C22C28C880AE


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 5

tracey
Enthusiast
Enthusiast

Thanks Justin,   I realise that I can't use save as to create and IDW or inventor DWG.  So can I use the API string in

iLogic?   I get the following error :

Error on Line 31 : Comma, ')', or a valid expression continuation expected.  (snapshot below)  Don't know what it is asking for.

I can use iLogic quite well but this is beyond my skills at the moment.  (Looking for a good VB course!)

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 4281 StartFragment: 314 EndFragment: 4249 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If

'- - - - - - - - - - - - -Assembly Export- - - - - - - - - - - -
oTime = Now.ToString("HH:mm:ss")
ThisDoc.Document.DrawingDocument.SaveAsInventorDWG ( FullFileName As String SaveCopyAs As Boolean (True))  

'- - - - - - - - - - - - -Components - - - - - - - - - - - -'look at the files referenced by the assembly

  Regards

Tracey

0 Likes
Message 4 of 5

MechMachineMan
Advisor
Advisor

Comma, ')', or a valid expression continuation expected

 

From API:

SaveAsInventorDWG ( FullFileName As String, SaveCopyAs As Boolean (True)) 

Your code:

SaveAsInventorDWG ( FullFileName As String SaveCopyAs As Boolean (True)) 

 

How I would do it:

SaveAsInventorDWG (FullFileName, SaveCopyAs) 

 but with the appropriate variables. The error stack really is plain english...


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 5 of 5

tracey
Enthusiast
Enthusiast

I now get another error that I don't understand:

 

Reference to a non-shared member requires an object reference...

problem is - I don't know what that means, or is!!

 

(Getting closer to the code working and reading/learning loads - must stay positive!) 

 

 

 

'- - - - - - - - - - - - -Assembly Export- - - - - - - - - - - -
oTime = Now.ToString("HH:mm:ss")
DrawingDocument.SaveAsInventorDWG ( ThisDoc.FileName(False), SaveCopyAs) 

 Kind regards and thank you for your help

 

Tracey

 

0 Likes