DXF export macro stopped working for some users...help?

DXF export macro stopped working for some users...help?

Anonymous
Not applicable
797 Views
7 Replies
Message 1 of 8

DXF export macro stopped working for some users...help?

Anonymous
Not applicable

A previous employee set up an ilogic macro for writing a flat pattern dxf.  The macro looks to an excel spreadsheet to get the name of the folder to save to.  However it stopped working and we get the following error:

Error in rule: Publish, in document: K070001.idw

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

 

Here is the code, anybody know what is wrong here?  I had an intro to ilogic class a year ago and haven't touched it since so we are stumped...

 

 

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 25427 StartFragment: 314 EndFragment: 25395 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

trigger = iTrigger0
oType=Left(ThisDoc.FileName(False),3)
GoExcel.Open("S:\DRAWINGS\Folder Types.xlsx", "Sheet1")
For rowPN = 1 To 200
 If (GoExcel.CellValue("A" & rowPN) = oType) Then
    oFile = GoExcel.CellValue("C" & rowPN) 
              Exit For
 End If
Next
oFolder = "S:\DRAWINGS\NOT RELEASED\" & oFile
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
Dim DWGAddIn As TranslatorAddIn 
DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}") 
Dim oDocument As Document 
oDocument = ThisApplication.ActiveDocument 
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism 
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium 
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium 
If DWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then 
    oOptions.Value("DwgVersion") = 25
Dim strIniFile As String 
strIniFile = "S:\DRAWINGS\DWG export.ini" 
oOptions.Value("Export_Acad_IniFile") = strIniFile 
End If 
path_and_name = oFolder & "\" & ThisDoc.FileName(False)
oDataMedium.FileName = path_and_name & ".dwg"
DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 
ThisDoc.Document.SaveAs(oFolder & "\" & ThisDoc.FileName(False) & (".pdf") , True)
Dim doc As Document = ThisDrawing.ModelDocument
Dim oSheetMetalComp As Inventor.SheetMetalComponentDefinition
oSheetMetalComp = doc.ComponentDefinition
Dim oFlatPattern As FlatPattern
oFlatPattern = oSheetMetalComp.FlatPattern
If oFlatPattern IsNot Nothing Then 
Dim iLogicAuto As Object = iLogicVb.Automation
If (iLogicAuto Is Nothing) Then Exit Sub
Dim ruleName As String = "DXF"
Dim rule As Object = iLogicAuto.GetRule(doc, ruleName)
Dim i As Integer = iLogicAuto.RunRuleDirect(rule)
End If
MessageBox.Show(oFolder, "File Saved To")

 

0 Likes
Accepted solutions (1)
798 Views
7 Replies
Replies (7)
Message 2 of 8

Owner2229
Advisor
Advisor

Hi, this rule is taking file name form an excel table ("S:\DRAWINGS\Folder Types.xlsx"), but it's limit is set to 200 rows, so is it possible that you have more than 200 rows in your table? Anyway this rule is not creating the DXF file, but just DWF and PDF. On the end of this rule is triggered another rule (named "DXF") which should create the DXF file. It is possible that this rule doesn't exist in the part that you're trying to run it from or it has an error in it. Look for it and if it exist then post it here (otherwise I can give you one). Below you have corrected rule for the first case (more than 200 entryes in excel table). It would now work up to infinite amount of rows. It also had condition that the flat pattern had to be present. Now it will create it if it isn't.

 

trigger = iTrigger0
oType=Left(ThisDoc.FileName(False),3)
GoExcel.Open("S:\DRAWINGS\Folder Types.xlsx", "Sheet1")

RowEnd = 200
For countA = 1 To (RowEnd * 0.01)
    If Not String.IsNullOrEmpty(GoExcel.CellValue("C" & RowEnd)) Then
        RowEnd = RowEnd + 100
    Else
        Exit For
    End If
Next

For rowPN = 1 To RowEnd
    If (GoExcel.CellValue("A" & rowPN) = oType) Then
        oFile = GoExcel.CellValue("C" & rowPN) 
        Exit For
    End If
Next

oFolder = "S:\DRAWINGS\NOT RELEASED\" & oFile
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}") 
Dim oDocument As Document = ThisApplication.ActiveDocument 
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism 
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium 

If DWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then 
    oOptions.Value("DwgVersion") = 25
    Dim strIniFile As String = "S:\DRAWINGS\DWG export.ini" 
    oOptions.Value("Export_Acad_IniFile") = strIniFile 
End If 

path_and_name = oFolder & "\" & ThisDoc.FileName(False)
oDataMedium.FileName = path_and_name & ".dwg"
DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 
ThisDoc.Document.SaveAs(path_and_name & ".pdf" , True)

Dim doc As Document = ThisDrawing.ModelDocument
Dim oSheetMetalComp As Inventor.SheetMetalComponentDefinition = doc.ComponentDefinition
Dim oFlatPattern As FlatPattern = oSheetMetalComp.FlatPattern
If Not oSheetMetalComp.HasFlatPattern Then
    oSheetMetalComp.Unfold()
    oDoc.Update2(True)
End If

If oFlatPattern IsNot Nothing Then
    Dim iLogicAuto As Object = iLogicVb.Automation
    If (iLogicAuto Is Nothing) Then Exit Sub
    'Select rule named "DXF"
    Dim ruleName As String = "DXF"
    Dim rule As Object = iLogicAuto.GetRule(doc, ruleName)
    'Run rule named "DXF"
    Dim i As Integer = iLogicAuto.RunRuleDirect(rule)
End If
MessageBox.Show(oFolder, "File Saved To")

  

And ofc. sorry for my English.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 8

Anonymous
Not applicable

Thanks for your help Mike; I will look for the rule DXF; I don't see it in the file.

 

When I run the code you cleaned up I get the following errors:

 

Line 28: End of statement expected

Line 29: 'oContext' is not declared.  It may be inaccessible due to its protection level.

Line 30: End of statement expected.

Line 49: 'oDoc' is not declared.  It may be inaccessible due to its protection level.

 

 

Thanks again for your help! 

0 Likes
Message 4 of 8

Anonymous
Not applicable

For what it's worth, here is the DXF rule code from the part file:

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 12194 StartFragment: 314 EndFragment: 12162 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

Sub Main
oType=Left(ThisDoc.FileName(False),3)
GoExcel.Open("S:\DRAWINGS\Folder Types.xlsx", "Sheet1")
For rowPN = 1 To 200
 If (GoExcel.CellValue("A" & rowPN) = oType) Then
    oFile = GoExcel.CellValue("C" & rowPN) 
         Exit For 
 End If
Next
oFolder = "S:\DRAWINGS\NOT RELEASED\" & oFile
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
    Dim oDoc As PartDocument
    oDoc = ThisDoc.Document
    Dim oCompDef As SheetMetalComponentDefinition
    oCompDef = oDoc.ComponentDefinition
    If oCompDef.HasFlatPattern = False Then
        oCompDef.Unfold
    Else
        oCompDef.FlatPattern.Edit
    End If
    sFname = oFolder & "\" & ThisDoc.FileName(False) & ".dxf"
    sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=0&InteriorProfilesLayer=0&InvisibleLayers=IV_UNCONSUMEND_SKETCHES;IV_ALTREP?_BACK;IV_ALTREP_FRONT;IV_ARC_CENTERS;IV_TOOL_CENTE?R_DOWN;IV_TOOL_CENTER;IV_ROLL;IV_TANGENT;IV?_BEND;IV_BEND_DOWN;IV_ROLL_TANGENT;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN&SplineTolerance Double 0.01"
    oCompDef.DataIO.WriteDataToFile( sOut, sFname)
End Sub

 

I just tested on a coworker's computer and the rules run correctly on Windows 8.1; however on another user's computer with Windows 7 it doesn't run, and on my Windows 8.1 it doesn't run....!? 

0 Likes
Message 5 of 8

Owner2229
Advisor
Advisor

Hi, I'm sorry, it's my misstake. I didn't check the code before posting. I'm going to look at the DXF part tomorow in the morning. This first part should be working now:

 

trigger = iTrigger0
oType=Left(ThisDoc.FileName(False),3)
GoExcel.Open("S:\DRAWINGS\Folder Types.xlsx", "Sheet1")

RowEnd = 200
For countA = 1 To (RowEnd * 0.01)
    If Not String.IsNullOrEmpty(GoExcel.CellValue("C" & RowEnd)) Then
        RowEnd = RowEnd + 100
    Else
        Exit For
    End If
Next

For rowPN = 1 To RowEnd
    If (GoExcel.CellValue("A" & rowPN) = oType) Then
        oFile = GoExcel.CellValue("C" & rowPN) 
        Exit For
    End If
Next

oFolder = "S:\DRAWINGS\NOT RELEASED\" & oFile
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}") 
Dim oDocument As Document = ThisApplication.ActiveDocument
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism 
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium 

If DWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then 
    oOptions.Value("DwgVersion") = 25
    Dim strIniFile As String = "S:\DRAWINGS\DWG export.ini" 
    oOptions.Value("Export_Acad_IniFile") = strIniFile 
End If 

path_and_name = oFolder & "\" & ThisDoc.FileName(False)
oDataMedium.FileName = path_and_name & ".dwg"
DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 
ThisDoc.Document.SaveAs(path_and_name & (".pdf") , True)

Dim doc As Document = ThisDrawing.ModelDocument
Dim oSheetMetalComp As Inventor.SheetMetalComponentDefinition = doc.ComponentDefinition
Dim oFlatPattern As FlatPattern = oSheetMetalComp.FlatPattern
If Not oSheetMetalComp.HasFlatPattern Then
    oSheetMetalComp.Unfold()
    oDocument.Update2(True)
End If

If oFlatPattern IsNot Nothing Then
    Dim iLogicAuto As Object = iLogicVb.Automation
    If (iLogicAuto Is Nothing) Then Exit Sub
    'Select rule named "DXF"
    Dim ruleName As String = "DXF"
    Dim rule As Object = iLogicAuto.GetRule(doc, ruleName)
    'Run rule named "DXF"
    Dim i As Integer = iLogicAuto.RunRuleDirect(rule)
End If
MessageBox.Show(oFolder, "File Saved To")
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 6 of 8

Owner2229
Advisor
Advisor
Accepted solution

Hi, below is the DXF rule cleaned up. It was as well limited to 200 rows that it will look on in the table. And I changed the sOut part so it is more synoptic, so it is easier for you if you'll ever want to change it in the future. Here is what it does: WriteFlatPatternAsDXF_Sample.pdf

Anyway both rules are looking for the Excel table in "S:\DRAWINGS\Folder Types.xlsx" and are trying to write to "S:\DRAWINGS\NOT RELEASED\", so you should look if you can acces this folders from all these computers. I believe it is a server disc, so you need to have it set the same on all computers.

 

E.g.: Server named "DC". If you dont know the address to your server than you should ask your IT or colleagues. When you type in your explorer "\\dc\" then it should send you to default server folder. Destination folder is "\\DC\DRAWINGS\NOT RELEASED\", so you need to have "DC" set as disc "S" in your windows. Otherwise we can change the address in your rules to absolute instead of relative:

"S:\DRAWINGS\NOT RELEASED\"  >> "\\DC\DRAWINGS\NOT RELEASED\"

In my opinion is changing the code address easier than setting up all PCs in your company.

 

Or does every colleague have his own Excel table? If so, than it need to be on disc "S:" on all PCs, or we can make one version of these rules for every one of them.

 

Sub Main
    oType=Left(ThisDoc.FileName(False),3)
    GoExcel.Open("S:\DRAWINGS\Folder Types.xlsx", "Sheet1")
	
    RowEnd = 200
    For countA = 1 To (RowEnd * 0.01)
        If Not String.IsNullOrEmpty(GoExcel.CellValue("C" & RowEnd)) Then
            RowEnd = RowEnd + 100
        Else
            Exit For
        End If
    Next

    For rowPN = 1 To RowEnd
        If (GoExcel.CellValue("A" & rowPN) = oType) Then
            oFile = GoExcel.CellValue("C" & rowPN) 
            Exit For
        End If
    Next
    oFolder = "S:\DRAWINGS\NOT RELEASED\" & oFile
    If Not System.IO.Directory.Exists(oFolder) Then
        System.IO.Directory.CreateDirectory(oFolder)
    End If
    Dim oDoc As PartDocument
    oDoc = ThisDoc.Document
    Dim oCompDef As SheetMetalComponentDefinition
    oCompDef = oDoc.ComponentDefinition
    If oCompDef.HasFlatPattern = False Then
        oCompDef.Unfold
    Else
        oCompDef.FlatPattern.Edit
    End If
    sFname = oFolder & "\" & ThisDoc.FileName(False) & ".dxf"
    sOut = "FLAT PATTERN DXF?AcadVersion=2004" _
	+ "&OuterProfileLayer=0" _
	+ "&InteriorProfilesLayer=0" _
	+ "&InvisibleLayers=IV_UNCONSUMEND_SKETCHES;IV_ALTREP?_BACK;IV_ALTREP_FRONT;IV_ARC_CENTERS;IV_TOOL_CENTE?R_DOWN;IV_TOOL_CENTER;IV_ROLL;IV_TANGENT;IV?_BEND;IV_BEND_DOWN;IV_ROLL_TANGENT;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN" _
	+ "&SplineTolerance Double 0.01"
    oCompDef.DataIO.WriteDataToFile( sOut, sFname)
End Sub

As always, sorry for my english.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 7 of 8

Anonymous
Not applicable

Thanks for your all of your help; everything is working well.  Your improvements to the code were a big help to us!  And your English is just fine!!!

0 Likes
Message 8 of 8

Owner2229
Advisor
Advisor

You're welcomed, if it would be any use for you, then I can implement any of the following functions to your code. Basically it's all just to improve sheet metal processing:

 

-add part number (or any other property) on the sheet metal surface, made by single lines. So the part can be easier identified after laser cuting and single lines, so the writing doesn't take the whole day (as I got to know, writing is kinda slow on laser, atleast on the one we have).

 

-add bedn lines on the sheet metal surface with text next to them. "U" for bend up, "D" for bend down. Or some other text, it's up to you ofc. (I'm planing add the bend angle and radius next to it, but that part I don't have finished jet.)

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes