iLogic to "Save Copy As" dwg from ipt flat pattern on file save using ini template file

iLogic to "Save Copy As" dwg from ipt flat pattern on file save using ini template file

Clo-z-nuff_2
Enthusiast Enthusiast
491 Views
1 Reply
Message 1 of 2

iLogic to "Save Copy As" dwg from ipt flat pattern on file save using ini template file

Clo-z-nuff_2
Enthusiast
Enthusiast

Inventor 2018 Pro (I know...I know...get with the times...)

 

I am an iLogic dabbler, by that I mean I search for code that gets me 90% and tweak the rest.  I'm usually able to make things work but this one has me stumped.

 

We export a dwg file from our sheet metal ipt flat patterns to use on a plasma table.  I'd like to automate this in a sheet metal file only when saving.  We currently use a .ini file for the settings which works great.  Preferably, on a save, a dialogue would pop up asking if you want to export the flat pattern to a dwg Yes/No.  If yes, the file gets saved (always to the same folder regardless where the original file is saved) using the ini file.

 

Has anyone done this before or can point me in the right direction?  I've tried various procedures that I have found online code for but none incorporate the ini file from the ipt file.

 

Thanks!

0 Likes
492 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Hi @Clo-z-nuff_2.  I don't think we can include the .ini file specification into this, but here is an example which uses the DataIO object of the FlatPattern to export it to a .dwg file.  You can give this a try if you want.  This can be used as an external iLogic rule, then put this rule's name under the 'After Save Document' event in the Event Triggers dialog of the sheet metal part.  You can reference this page for other optional settings that can be specified within the oFormat line.

oAns = MsgBox("Do you want to export the FlatPattern to a DWG file?", vbYesNo + vbQuestion, "Export FlatPattern DWG?")
If oAns = vbNo Then Exit Sub
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("A Part Document must be active for this rule to work. Exiting.", vbCritical, "iLogic")
	Exit Sub
End If
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
If Not TypeOf oPDoc.ComponentDefinition Is SheetMetalComponentDefinition Then
'If oPDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value <> "Sheet Metal" Then
	MsgBox("This Part is not a Sheet Metal Part. Exiting rule.", vbExclamation, "NOT SHEET METAL")
	Exit Sub
End If
Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
Dim oFP As FlatPattern
If oSMDef.HasFlatPattern Then
	oFP = oSMDef.FlatPattern
Else
	Try
		oSMDef.Unfold
		oFP = oSMDef.FlatPattern
		oFP.ExitEdit
	Catch
	End Try
End If
If oFP Is Nothing Then Exit Sub
Dim oFormat As String = "FLAT PATTERN DWG?AcadVersion=2000&OuterProfileLayer=IV_OUTER_PROFILE&TrimCenterlinesAtContour=True"
oFileName = System.IO.Path.ChangeExtension(oPDoc.FullFileName, ".dwg")
oFP.DataIO.WriteDataToFile(oFormat, oFileName)

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes