Batch export DXF of multiple files with different criteria.

Batch export DXF of multiple files with different criteria.

Kaplar.Balazs
Contributor Contributor
2,500 Views
10 Replies
Message 1 of 11

Batch export DXF of multiple files with different criteria.

Kaplar.Balazs
Contributor
Contributor

Hello everyone,

 

I'm looking for a possible solution for a time consuming manual work I have to deal with everyday.

We're usually outsourcing sheet metal and plastic work to some of our local suppliers. They all are working from DXF files, but inhouse we're using STEP and PDF for manufacturing documents. I have to manually export every .dwg to .dxf after the project has been completed, but some of our machines consists of dozens, if not hundreds of said parts.

 

I want to export all those file's .dwg into dxf with the following criterias.

 

So the requirements are:

Sheet Metal

Material - VIVAK

Material - EUROPLEX SDX

Material - DIBOND

 

Also for every folded sheet metal there has to be a flat pattern exported to .STEP also.

 

I'm using the Drawing Porter addin for quick and easy exporting of STEP and PDF files, but said program can not export flat patterns to STEP, so it would be nice if all could be done with one flick of a finger.

 

Thanks in advance.

 

Have a great day,

Balázs

0 Likes
Accepted solutions (2)
2,501 Views
10 Replies
Replies (10)
Message 2 of 11

A.Acheson
Mentor
Mentor

Here is a starting point for you. It might be difficult to find all of what you need but you can continue to search this forum or through internet explorer search. If you have any questions about it’s actions feel free to ask. I would review it first check where it may fail like iproperties missing from your setup etc then test it first on a non production sample documents first. It works from an assembly.

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/ilogic-rule-to-export-files-of-an-assem...

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 11

Kaplar.Balazs
Contributor
Contributor

Hi,

 

Thanks for your reply. I tried that code provided by Rob67ert and it works almost perfectly.

Now I found that there's a property added to the part where it defines a custom property as "PF_PRT_ZNR" and if that's missing it adds an 'XXX' in front of the part number. I'll figure that out and delete when I have the time to inspect.


Other thing is, while examining the code it came to my mind that why don't I make those parts (Dibond, Vivak etc) sheet metal also? They will be exported too and the part type doesn't matter in the assembly. So all in all I changed my design routine a bit, created Sheet metal defaults for polycarbonate and dibond (bit funny but it works).

 

My only problem left is the export folder. I want to export the DXFs to the same folder I export my STEP and PDF files with DrawingPorter. I post a screenshot of my folder path.

 

I'll be grateful if someone could help me in that.

 

Thanks in advance.

 

Cheers,

Balázs

0 Likes
Message 4 of 11

A.Acheson
Mentor
Mentor
Accepted solution

Here is the snippets that need adjustments.

You can change the folder directory by changing “oPath”

 

Old

oPath = ThisDoc.Path

 

New

oPath = “Enter file path here”

 

And change the filename from custom number to the part number. 

Old

Try CustomName =iProperties.Value(oFileName, "Custom", "PF_PRT_ZNR") Catch CustomName ="XXX" 'Wert, wenn iPropertie PF_PRT_ZNR nicht existiert End Try

New

Try CustomName =iProperties.Value(oFileName, "Project”, "Part Number") Catch CustomName ="XXX" 'Wert, wenn iPropertie PF_PRT_ZNR nicht existiert End Try

 

 

If you don’t have sheet metal parts in the assembly , change the declaration of variable “oCompDef”

 

Old

Dim oCompDef As SheetMetalComponentDefinition

 

New

Dim oCompDef As PartComponentDefinition

 

and also remove any reference to sheet metal functions 

“If oCompDef.HasFlatPattern = False Then oCompDef.Unfold Else oCompDef.FlatPattern.Edit End If”


“oCompDef.FlatPattern.ExitEdit“

 

 

Original rule

 

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)
'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If
'get user input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all of the asembly components that are sheet metal." _
& vbLf & "This rule expects that the part file is saved." _
& vbLf & " " _
& vbLf & "Are you sure you want to create DXF for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic - Batch Output DXFs ",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
Return
Else
End If
oPath = ThisDoc.Path
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
'get DXF target folder path
oFolder = oPath & "\" & oAsmName & " DXF Files"
'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'- - - - - - - - - - - - -Component - - - - - - - - - - - -'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
'work the the drawing files for the referenced models'this expects that the model has been saved
For Each oRefDoc In oRefDocs
iptPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "ipt"
'check that model is saved
If(System.IO.File.Exists(iptPathName)) Then
Dim oDrawDoc As PartDocument
oDrawDoc = ThisApplication.Documents.Open(iptPathName, True)
oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName))
Try
'Set the DXF target file name
Try
CustomName =iProperties.Value(oFileName, "Custom", "PF_PRT_ZNR")
Catch
CustomName ="XXX" 'Wert, wenn iPropertie PF_PRT_ZNR nicht existiert
End Try

oDataMedium.FileName = oFolder & "\" & CustomName  & " " & oFileName & ".dxf"

Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDrawDoc.ComponentDefinition
If oCompDef.HasFlatPattern = False Then
oCompDef.Unfold
Else
oCompDef.FlatPattern.Edit
End If
Dim sOut As String
sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_OUTER_PR?OFILE"
oCompDef.DataIO.WriteDataToFile( sOut, oDataMedium.FileName)
'just for check its works coretcly'i=MessageBox.Show(oDataMedium.FileName, "Title",MessageBoxButtons.OKCancel)'MessageBox.Show(i,"title",MessageBoxButtons.OK)'If i=2 Then'Exit Sub'End If
oCompDef.FlatPattern.ExitEdit
Catch
End Try
oDrawDoc.Close
Else
End If
Next

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 11

Kaplar.Balazs
Contributor
Contributor

Hello Acheson,

 

Thanks for your input, I really appreciate it.

 

I'm wondering if the 

oPath = "Enter file path here"

could be standardized to work on every computer without editing the code. I think this would need a standard folder set up on every computer but maybe I can push it through the design department.

 

Other thing is, while this code was written by somebody else for a different but similar purpose I think opening every document then checking, closing etc. takes a lot of time. It's better to have a progress bar and % display than watching inventor opening and closing files. And closing every leftover part which weren't closed by the rule itself.

Am I asking too much? 🙂 

 

Thanks in advance.

 

Balázs

0 Likes
Message 6 of 11

A.Acheson
Mentor
Mentor
Accepted solution

oPath can be standardized yes. You can either take the location from the main assembly you are working in using this doc.path or hard code it in stating location like “c/…/…” or use system IO to get another path if you would like. 

 

 

For the progress bar you will need to use the loop of assembly documents to index up the progress bar. The link below has a great example so simply transfer the code to your rule excluding the loop sample they are using. 

https://blogs.rand.com/manufacturing/2017/10/inventor-progress-bar.html

 

Regarding opening the drawing checking and closing this is the process carried out regardless of the operation being performed .

You can change the visibility of the drawing to false which will not open on screen but in the background. There has been mixed results of this on various forum post so I keep it visible. You may be able to put in some update snippets to ensure the drawing gets updated before printing etc. 

oDrawDoc = ThisApplication.Documents.Open(iptPathName, False)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 7 of 11

Kaplar.Balazs
Contributor
Contributor

Thanks. This looks promising.

However on the first try I encountered a problem (I think it roots in the sample which have sections cut out)


" 'sDXFOutList' is not declared. It may be inaccessible due to its protection level."

 

I downloaded VisualStudio and started some tutorials to dig deeper into the VB programming world but so far my progress is veery basic and slow. Another guy on forums suggested to use it because it gives possible solutions to these problems, also I quickly jumped into the software without any proper preparations becaue my time is limited for these projects. Neither possible fix was successful so I'm stuck here.

 

Tried the rule with 

oDrawDoc = ThisApplication.Documents.Open(iptPathName, False)

but it failed to complete after the first sheet metal export. So I'll sit and wait until it scrolls through all my components.

 

Just thinking out loud, is it possible to limit the "search area" for the rule? For example we are using a standardized project number for every machine. It's set up like this for example:
VT-21-1550_PRESSFIT_MACHINE

VT is our company abbreviation, 21 is the project year, 1550 or whatever is the project number.

Every assembly, part and drawing has the same name w/o company name and year, e.g. :1550-010-001-A0.

My idea is that we only need to check the custom made parts with our standard part number if they are sheet metal or not then export only those. ContentCenter, Library and other not specifically named parts could be skipped to reduce overall process time.

 

I'll click accept on your replies because my original problem is solved now, the rule works as intended.

Thanks for everything!

0 Likes
Message 8 of 11

A.Acheson
Mentor
Mentor

I guess the drawing needs to be visibly open to create the flat pattern, but I am not sure about your error message, I would need to test the rule your using.

 

Here is another example of this rule. It is layout out in VB.net format so a little easier to follow I believe. You can  see how some of the filtering is done in the main section of the rule before it calls  the sub routine "ExportFlatPatternDXF(oDoc)"  

 

Adapted from rules found here

Sub Main()
	oAdoc = ThisApplication.ActiveDocument
	oAcompdef = oAdoc.ComponentDefinition
	
	If oAdoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		For Each oDoc As Document In oAdoc.AllReferencedDocuments
			'Filtering of documents for processing
			'MessageBox.Show(oDoc.FullFileName)
			If Not oDoc.FullFileName.Contains("Content Center") Then 'Looks at full file name and if it does not contain Content Center it moves to next line
				If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
					Dim PartDoc As PartDocument = oDoc
					'do your stuff here.
					'MessageBox.Show( "Check if inside filter")
					Call ExportFlatPatternDXF(oDoc)
				Else
				
				End If
			End If
		Next oDoc
	End If
End Sub
Public Sub ExportFlatPatternDXF(oDoc)
	
	'Checks if it is a Sheet metal Part
	If TypeOf oDoc.ComponentDefinition Is SheetMetalComponentDefinition Then
		Dim oCompDef As SheetMetalComponentDefinition
	    oCompDef = oDoc.ComponentDefinition
	    If oCompDef.HasFlatPattern = False Then
		    oCompDef.Unfold
	    Else
		    oCompDef.FlatPattern.Edit
	    End If

	    Dim sOut As String
	    sOut = "FLAT PATTERN DXF?AcadVersion=2000&OuterProfileLayer=IV_INTERIOR_PROFILES"
		NewPath = System.IO.Path.GetDirectoryName(oDoc.fulldocumentname) & "\"
		MessageBox.Show(NewPath, "Title")

	    Dim sFname As String = NewPath & System.IO.Path.GetFileNameWithoutExtension(oDoc.fulldocumentname) & ".dxf"
	    sFname = ThisDoc.Path & "\" & ThisDoc.FileName(False) & ".dxf"
		MessageBox.Show(sFname, "Title")

	    MessageBox.Show("DXF SAVED TO: " & sFname ,"DXF Saved", MessageBoxButtons.OK)
	    oCompDef.DataIO.WriteDataToFile( sOut, sFname)
	End If
End Sub

 A specific filter is a good idea to target only the parts you want to process. if you want to integrate that. This one will work if you have filtered out the read only files as the ilogic snippet tries to write to the file even if checking the contents and of course it can't as it is read only and will cause an error. 

If iProperties.Value(oRefDoc.DisplayName, "Project", "Part Number").ToString.Contains("1234") Then 
						MessageBox.Show(oRefDoc.DisplayName, "Yes ")
					End If

 You can also use the longer property set method through the API to check the part number without excluding read only files. 

https://modthemachine.typepad.com/my_weblog/2010/02/accessing-iproperties.html

 

If you want help with the rule post up the one that best suits your needs and it can be easily adapted. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 9 of 11

Anonymous
Not applicable

Can you please guide me how to customize layers with this logic?

 

I want to have something like this.

Tangent Lines=IV_TANGENT:Visibility=OFF;LinePattern=28100;LineWeight=0.0500;Color=0,0,0;
Bend Lines (Front)=IV_BEND:Visibility=OFF;LinePattern=28100;LineWeight=0.0500;Color=0,0,0;
Bend Lines (Back)=IV_BEND_DOWN:Visibility=OFF;LinePattern=28100;LineWeight=0.0500;Color=0,0,0;
Tool Centers (Front)=IV_TOOL_CENTER:Visibility=OFF;LinePattern=28100;LineWeight=0.0500;Color=0,0,0;
Tool Centers (Back)=IV_TOOL_CENTER_DOWN:Visibility=OFF;LinePattern=28100;LineWeight=0.0500;Color=0,0,0;
Arc Centers=IV_ARC_CENTERS:Visibility=OFF;LinePattern=28100;LineWeight=0.0500;Color=0,0,0;
Outer Profile=IV_OUTER_PROFILE:Visibility=ON;LinePattern=28100;LineWeight=0.0500;Color=0,0,0;
Inner Profile=IV_INTERIOR_PROFILES:Visibility=ON;LinePattern=28100;LineWeight=0.0500;Color=0,0,0;
Feature Profile (Front)=IV_FEATURE_PROFILES:Visibility=ON;LinePattern=28100;LineWeight=0.0500;Color=0,0,0;
Feature Profile (Back)=IV_FEATURE_PROFILES_DOWN:Visibility=ON;LinePattern=28100;LineWeight=0.0500;Color=0,0,0;
Alternate Rep (Front)=IV_ALTREP_FRONT:Visibility=OFF;LinePattern=28100;LineWeight=0.0500;Color=0,0,0;
Alternate Rep (Back)=IV_ALTREP_BACK:Visibility=OFF;LinePattern=28100;LineWeight=0.0500;Color=0,0,0;
Unconsumed Sketches=IV_UNCONSUMED_SKETCHES:Visibility=OFF;LinePattern=0;LineWeight=-1.0000;Color=-255,-255,-255;
Tangent Roll Lines=IV_ROLL_TANGENT:Visibility=OFF;LinePattern=28100;LineWeight=0.0500;Color=0,0,0;
Roll Lines=IV_ROLL:Visibility=OFF;LinePattern=28100;LineWeight=0.0500;Color=0,0,0;

0 Likes
Message 10 of 11

Anonymous
Not applicable
Hi,

Can you please write this logic to customize layers aswell?

thanks and regards
Manju
0 Likes
Message 11 of 11

A.Acheson
Mentor
Mentor

Please open a new post relating to the layer request. This one is solved and your request is very specific. If possible find a similar post and reference it in your new post. Hopefully another user familiar with layers can help out. I would also consult the API help for assistance. Thanks

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes