Error in export path

Error in export path

Neuzzo
Advocate Advocate
463 Views
2 Replies
Message 1 of 3

Error in export path

Neuzzo
Advocate
Advocate

Hi, I have an error in this ilogic rule that I can't solve.
Simply when it opens the flat pattern to export it to the chosen folder (folder that is set in the path and has as variable the sheet metal material) it gives me error.
Can anyone help me? Thanks

 

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium 
oDataMedium1 = ThisApplication.TransientObjects.CreateDataMedium 


If oPDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 1200
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2'oOptions.Value("Custom_End_Sheet") = 4
End If 

oRefDoc = ThisDrawing.ModelDocument
Dim oPropValue As String 
Dim oPropValue1 As String 

oPropValue = oRefDoc.PropertySets("Summary Information").Item("Revision Number").Value 
iProperties.Value("Summary", "Revision Number") = oPropValue

oPropValue1 = oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Material").Value 
iProperties.Value("Custom", "Material Type") = oPropValue1

Rev = iProperties.Value("Summary", "Revision Number")

'get PDF target folder path
Dim oFolder As String 
	oFolder = "\\SRVDOC2016\pubblica\Foto-Articoli-AS400\"

Dim PDFFolder2 As String
	PDFFolder2 = "\\SRVDOC2016\pubblica\Foto-Articoli-AS400_REV_VECCHIE"

'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

Dim Materiale As String = iProperties.Value("Custom", "Material Type")

If Not System.IO.Directory.Exists("\\srvdoc2016\PUBBLICA\PRODUZIONE\TAGLIO LASER\" & Materiale & "\") Then
    System.IO.Directory.CreateDirectory("\\srvdoc2016\PUBBLICA\PRODUZIONE\TAGLIO LASER\" & Materiale & "\")
End If


 'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & ".pdf" 
oDataMedium1.FileName = PDFFolder2 & "\" & oFileName & "-" & Rev &".pdf" 


'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium1)

Dim oPart As PartDocument
Dim oPartPath As String

' Get drawing path
oPartPath = ThisDoc.PathAndFileName(False) & ".ipt"

' Set a reference to the target part
oPart = ThisApplication.Documents.ItemByName(oPartPath)

' Open the target part
ThisApplication.Documents.Open(oPartPath)

InventorVb.DocumentUpdate(True)

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

Dim oType As String
oType = oDoc.DocumentSubType.DocumentSubTypeID

Dim currentStyle As String
currentStyle = iProperties.Material

If oType =  "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
      'Set your filepath here:
	SETFilePath = "C:\temp\" & oPropValue1

	Dim partDoc As PartDocument

	'Check for flat pattern >> create one if needed
	Dim oDoc01 As PartDocument
	oDoc01 = ThisApplication.ActiveDocument
	Dim oCompDef As SheetMetalComponentDefinition
	oCompDef = oDoc01.ComponentDefinition
	If oCompDef.HasFlatPattern = False Then
	oCompDef.Unfold

	Else
	oCompDef.FlatPattern.Edit
	End If

	'DXF Settings
	Dim sOut As String
	Dim sPATH As String
	sOut = "FLAT PATTERN DXF?AcadVersion=2000&OuterProfileLayer=Burn&InteriorProfilesLayer=Burn&InvisibleLayers=IV_UNCONSUMEND_SKETCHES;IV_ALTREP_BACK;IV_ALTREP_FRONT;IV_ARC_CENTERS;IV_TOOL_CENTER_DOWN;IV_TOOL_CENTER;IV_ARC_CENTERS;IV_TANGENT;IV_BEND;IV_BEND_DOWN&SplineTolerance Double 0.01"
	Dim sFname As String
	pFname = ThisDoc.FileName(False) & ".ipt"
	
	'Export the DXF and fold the model back up
	oCompDef.DataIO.WriteDataToFile( sOut, SETFilePath & "\" & ThisDoc.FileName(False) & ".dwg")
	Dim oSMDef As SheetMetalComponentDefinition
	oSMDef = oDoc01.ComponentDefinition
	oSMDef.FlatPattern.ExitEdit

Else 

      GoTo Update
	  
End If

Update :

InventorVb.DocumentUpdate(False)
opendoc = ThisDoc.PathAndFileName()'saves doc path and file name
doc = ThisApplication.Documents.Open(opendoc & ".ipt")'saves 'doc' as the open application from 'opendoc' adding the extension '.iam'
doc.Close 'closes the indicated document 'doc'

'System.Threading.Thread.CurrentThread.Sleep(2000)
InventorVb.DocumentUpdate(False)

InventorVb.DocumentUpdate(False)

'iLogicVb.RunExternalRule("DWG_LOGICO")

 

Danilo "DannyGi" G.
Mechanical design engineer and product developer
0 Likes
Accepted solutions (1)
464 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor

A few questions to help diagnose the issue. Could you possibly post the error message both the first and second tab? Is this a newly constructed rule? Is the external rule existing with the same name? Can you check the full file path with a message box and ensure it is logical for saving?  Can you step through the code with a messagebox and check how far the code is getting? 

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 3

WCrihfield
Mentor
Mentor
Accepted solution

Are you sure that this Part file exists with the specified file name?  If not, it will throw an error.

You can try changing this:

' Get drawing path
oPartPath = ThisDoc.PathAndFileName(False) & ".ipt"

' Set a reference to the target part
oPart = ThisApplication.Documents.ItemByName(oPartPath)

 To something like this:

oPartPath = ThisDoc.PathAndFileName(False) & ".ipt"
If Not System.IO.File.Exists(oPartPath) Then
	MsgBox("The following file:" & vbCrLf & oPartPath & vbCrLf & "Does not exist.  Exiting rule.",,"")
	Exit Sub
End If
oPart = ThisApplication.Documents.ItemByName(oPartPath)

That way, if the that file does not exist, it will let you know, then exit the rule, instead of throwing the error.

There is another similar situation like this near the end of the rule too.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes