ilogic Export Sheet metal flat pattern to .SAT

ilogic Export Sheet metal flat pattern to .SAT

yvandelafontaine
Advocate Advocate
743 Views
4 Replies
Message 1 of 5

ilogic Export Sheet metal flat pattern to .SAT

yvandelafontaine
Advocate
Advocate

I'm trying to tweak my code (global rule) to export the flat pattern to .sat in format 7.0 (INV2020), it does so but always the folded model. What am I missing???

'On Error GoTo ErrorTrapper:

If iProperties.Value("Project", "Revision Number") = "" Then
iProperties.Value("Project", "Revision Number") = "0"
End If
oRev = iProperties.Value("Project", "Revision Number")


Dim curDoc = ThisApplication.ActiveDocument
If curDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then


    Dim oDoc As PartDocument

    oDoc = ThisApplication.ActiveDocument

				
    Dim oCompDef As SheetMetalComponentDefinition

    oCompDef = oDoc.ComponentDefinition

	'[ Ensure this part has a flat pattern
				
				If oCompDef.FlatPattern Is Nothing Then 
				oCompDef.Unfold
				Else
				End If
				RuleParametersOutput()
				']
				
	oCompDef.FlatPattern.Edit
	
	Dim sOut As String
	
    Dim sPATH As String
	
	oPathSat = ThisDoc.WorkspacePath() & "\SAT\"
	
	
	'[ Ensure this folder exist
	'Check For the SAT folder And create it If it does Not exist
	If Not System.IO.Directory.Exists(oPathSat) Then
	System.IO.Directory.CreateDirectory(oPathSat)
	End If

	
	Version = 7


	Dim sFname As String
	
	sFname = oPathSat & ThisDoc.FileName(False) & "_REV-" & oRev & ".sat"

oDoc.SaveAs(sFname, True)

	'oCompDef.SaveAs(sFname ,False)
       'oCompDef.DataIO.WriteDataToFile( "ACIS SAT", sFname)
	'oCompDef.DataIO.WriteDataToFile( nsOut, nsFname)
	
	oDoc = ThisApplication.ActiveDocument
	
	oCompDef = oDoc.ComponentDefinition
	
	oCompDef.FlatPattern.ExitEdit
	


	
Else
ThisApplication.StatusBarText = ThisDoc.FileName(False) & " Is not in a sheet metal state, convert to sheetmetal and create flat pattern first --- Jumping to next part" 



End If

 

0 Likes
Accepted solutions (1)
744 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

See if this works for you.

From the looks of the StatusBar message, this is just a portion of a larger code, so I'm not sure if this is the main part, or if this is the lower Sub part.  If this portion of the code is not the main top code in your rule, you likely need to change Sub Main() to something else like Sub FlatPatternToSAT().

I also put a check in there, because the WorkspacePath can be empty, if not defined within your Project file.  I also showed an alternate way to get that info, commented out.

As far as the version, I couldn't find any examples of other entries in place of "ACIS SAT".

I tried using the Sub: DataIO.GetOutPutFormats(), but it was constantly throwing errors, so I never was able to get the results.  I tried it on the ComponentDefinition, the FlatPattern, on FlatPattern.SolidBodies.Item(1).DataIO, but always errors.  There is very little documentation about using DataIO's on here, other that where others have tried to use it at some point in the past.  The only official example using it is for DXF's.

Sub Main
	Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
	If iProperties.Value("Project", "Revision Number") = "" Then
		iProperties.Value("Project", "Revision Number") = "0"
	End If
	Dim oRev As String = iProperties.Value("Project", "Revision Number")
	''If oPDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
	If oPDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Sheet Metal" Then
		Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
		If oSMDef.FlatPattern Is Nothing Then 
			oSMDef.Unfold
			oSMDef.FlatPattern.ExitEdit
		End If
	''	Dim oWSP As String = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
		If ThisDoc.WorkspacePath = "" Then
			MsgBox("ThisDoc.WorkspacePath is empty (not defined). Exiting.", vbOKOnly + vbExclamation, "WORKSPACE NOT DEFINED")
			Return 'or Exit Sub
		End If
		Dim oPathSat As String = ThisDoc.WorkspacePath & "\SAT\"
		If Not System.IO.Directory.Exists(oPathSat) Then
			System.IO.Directory.CreateDirectory(oPathSat)
		End If
	''	Version = 7
		Dim oFileName As String = oPathSat & ThisDoc.FileName(False) & "_REV-" & oRev & ".sat"
		Try
			oSMDef.FlatPattern.DataIO.WriteDataToFile("ACIS SAT", oFileName)
		Catch oEx As Exception
			MsgBox("DataIO.WriteDataToFile() failed!" & vbCrLf & _
			"Error Message is as follows:" & vbCrLf & _
			oEx.Message & vbCrLf & vbCrLf  & _
			"Error Source is as follows:" & vbCrLf & _
			oEx.Source & vbCrLf & vbCrLf & _
			"Error StackTrace is as follows:" & vbCrLf & _
			oEx.StackTrace & vbCrLf & vbCrLf  & _
			"Error Type.ToString is as follows:" & vbCrLf & _
			oEx.GetType.ToString, vbOKOnly + vbInformation, " ")
		End Try
	Else
		ThisApplication.StatusBarText = ThisDoc.FileName(False) & " Is not in a sheet metal state, convert to sheetmetal and create flat pattern first --- Jumping to next part" 
	End If
End Sub

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

WCrihfield
Mentor
Mentor

Here's the code I was using to try to get the available formats, in case you or others want to try to get it to work.

I've used this same sub in other situations successfully, but for some reason this situation it just doesn't want to work for me.

Sub Main
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
If oPDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Sheet Metal" Then
	Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
	If oSMDef.FlatPattern Is Nothing Then
		MsgBox("FlatPattern was Nothing.", , " ")
		oSMDef.Unfold
		oSMDef.FlatPattern.ExitEdit
	Else
'		MsgBox("FlatPattern was already not Nothing.", , " ")
	End If
	Dim oFormats() As String
	Dim oStorageTypes() As StorageTypeEnum
	Try
'		oSMDef.DataIO.GetOutputFormats(oFormats, oStorageTypes)
		oSMDef.FlatPattern.DataIO.GetOutputFormats(oFormats, oStorageTypes)
'		oSMDef.FlatPattern.SurfaceBodies.Item(1).DataIO.GetOutputFormats(oFormats, oStorageTypes)
		If oFormats.Length > 0 Then
'			a = InputListBox("Output Formats",oFormats)
			For Each oFormat As String In oFormats
				MsgBox(oFormat)
			Next
		End If
	Catch oEx As Exception
		MsgBox("GetOutputFormats failed." & vbCrLf & _
		"Error Message is as follows:" & vbCrLf & _
		oEx.Message & vbCrLf & vbCrLf  & _
		"Error Source is as follows:" & vbCrLf & _
		oEx.Source & vbCrLf & vbCrLf & _
		"Error StackTrace is as follows:" & vbCrLf & _
		oEx.StackTrace & vbCrLf & vbCrLf  & _
		"Error Type.ToString is as follows:" & vbCrLf & _
		oEx.GetType.ToString, vbOKOnly + vbInformation, " ")
	End Try
End If
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

Also, FYI:

Here are a couple of informational links about the DataIO object.

DataIO Object 

DataIO 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

yvandelafontaine
Advocate
Advocate
Accepted solution

Found the solution the line for exporting is:

oCompDef.FlatPattern.Body.DataIO.WriteDataToFile("ACIS SAT", sFname)

i was actually missing the ".Body." part

0 Likes