Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
philip1009
2499 Views, 14 Replies

Export all Flat Patterns from iPart file to DWG with Part Number as file name.

Hello to all.  I have working iLogic code that exports sheet metal flat patterns to a dwg file with the correct options needed by the programming team.  We have code elsewhere that works great with normal parts to automate the exporting process.

 

Here's the code as of now:

 

SyntaxEditor Code Snippet

Dim oDoc As PartDocument
oDoc=ThisApplication.ActiveDocument
Dim oCompDef As SheetMetalComponentDefinition
oCompDef=oDoc.ComponentDefinition
Dim oDataIO As DataIO
oDataIO=oDoc.ComponentDefinition.DataIO
If oCompDef.HasFlatPattern=False Then
oCompDef.Unfold
Else
oCompDef.FlatPattern.Edit
End If
Dim sOut As String
sOut="FLAT PATTERN DWG?AcadVersion=2000" _
+"&InvisibleLayers=IV_TANGENT;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL" _
+"&SimplifySplines=True" _
+"&LINEAR TOLERANCE=0.010" _
+"&MergeProfilesIntoPolyline=True" _
+"&RebaseGeometry=False" _
+"&TrimCenterlines=True"
Dim sFname As String
sFname=oDoc.FullFileName
sFname=Left$(sFname,Len(sFname)-3)&"dwg"
oCompDef.DataIO.WriteDataToFile(sOut,sFname)

 

The problem is when it exports a flat pattern from an iPart file it, of course, reads the file name such as "PANELS" instead of the iProperties Part Number such as "ST9".

 

How do I change the code so that it saves the dwg file with the name from the Part Number instead of the File Name?

 

I've tried simply changing the code to this:

 

SyntaxEditor Code Snippet

Dim oDoc As PartDocument
oDoc=ThisApplication.ActiveDocument
Dim oCompDef As SheetMetalComponentDefinition
oCompDef=oDoc.ComponentDefinition
Dim oDataIO As DataIO
oDataIO=oDoc.ComponentDefinition.DataIO
If oCompDef.HasFlatPattern=False Then
oCompDef.Unfold
Else
oCompDef.FlatPattern.Edit
End If
Dim sOut As String
sOut="FLAT PATTERN DWG?AcadVersion=2000" _
+"&InvisibleLayers=IV_TANGENT;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL" _
+"&SimplifySplines=True" _
+"&LINEAR TOLERANCE=0.010" _
+"&MergeProfilesIntoPolyline=True" _
+"&RebaseGeometry=False" _
+"&TrimCenterlines=True"
Dim sFname As String
sFname=iProperties.Value("Project", "Part Number")&".dwg"
oCompDef.DataIO.WriteDataToFile(sOut,sFname)

But all I get is the typical HRESULT fail code which doesn't tell me anything.  I've also tried using the Convert to String code like below:

 

SyntaxEditor Code Snippet

sFname=CStr(iProperties.Value("Project", "Part Number"))&".dwg"

But that doesn't work either, if I can get a solution on this that would save the step of having to rename each export one at a time, that would be awesome.

 

My second request would be to add code to automatically do these steps for every member in the iPart table instead having to run the code, change the iPart member, then run the code again for every member.

 

Thanks so much in advance, I've learned plenty about iLogic in the past few months, it's just the little details here and there that trip me up.