iLogic : Export idw part data to text file

iLogic : Export idw part data to text file

Anonymous
Not applicable
1,982 Views
10 Replies
Message 1 of 11

iLogic : Export idw part data to text file

Anonymous
Not applicable

We have an idw package we use for Quality control. This idw has more than one sheet. Each sheet has a part placed on the sheet with dims.( DWF attached). Next we open DA inside of the file and run a report. (exported txt attached). I am trying to use ilogic the make the same report with a iLogic browser button pick. I have 2 codes (code examples on attached jpg) that i need to make into 1, or what ever works. Any help would be great.

 

Having trouble attaching the DWF so it is not attached

 

1st code

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument 
Dim oSubDoc As Inventor.Document 
Dim oPropSets As PropertySets 
Dim oPropSet As PropertySet
Dim oPartNumiProp As Inventor.Property 

For Each oSubDoc In oDoc.AllReferencedDocuments 
    If oSubDoc.documenttype = kpartdocumentobject Then
    oPropSets = oSubDoc.PropertySets 
    oPropSet = oPropSets.Item("Inventor User Defined Properties")
    oPartNumiProp = oPropSet.Item("PCMK")
	       
        sMsg=sMsg & oSubDoc.FullFileName & vbLf

    End If
    
Next




    MessageBox.Show(sMsg, "PCMK")
	

 2nd code

fileheader = "QAF Parts for Planning "
fileheader1 = ThisDoc.PathAndFileName(True) 'first line header of txt file
description = "Components to use for Nesting" 'use this variable in the body of the txt

delimiter = "," 'character to separate the names and values on each line



oWrite = System.IO.File.CreateText(ThisDoc.PathAndFileName(False) & ".txt")
oWrite.WriteLine(fileheader) 'include the fileheader on the first line
oWrite.WriteLine(fileheader1) 'include the fileheader on the first line
oWrite.WriteLine(description) 'include the description on the second line
oWrite.WriteLine(Now()) 'include the current date and time on the third line
oWrite.WriteLine() 'blank line

oWrite.Close()

'option to view report
go = MessageBox.Show("Would you like to view the txt file?", "QAF Nesting Report", MessageBoxButtons.YesNo)
If go = 6 Then ThisDoc.Launch(ThisDoc.PathAndFileName(False) & ".txt")


 

 

 

0 Likes
1,983 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable

Just realized that my 1st text file looks bad.

 

QAF to Planning 1.jpg

0 Likes
Message 3 of 11

adam.nagy
Autodesk Support
Autodesk Support

Hi Andrew,

 

Where do you run into problems with combining the two code?

I think this is what you are trying to do:

fileheader = "QAF Parts for Planning "
fileheader1 = ThisDoc.PathAndFileName(True) 'first line header of txt file
description = "Components to use for Nesting" 'use this variable in the body of the txt

delimiter = "," 'character to separate the names and values on each line

oWrite = System.IO.File.CreateText(ThisDoc.PathAndFileName(False) & ".txt")
oWrite.WriteLine(fileheader) 'include the fileheader on the first line
oWrite.WriteLine(fileheader1) 'include the fileheader on the first line
oWrite.WriteLine(description) 'include the description on the second line
oWrite.WriteLine(Now()) 'include the current date and time on the third line
oWrite.WriteLine() 'blank line

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument 
Dim oSubDoc As Inventor.Document 
Dim oPropSets As PropertySets 
Dim oPropSet As PropertySet
Dim oPartNumiProp As Inventor.Property 

For Each oSubDoc In oDoc.AllReferencedDocuments 
    If oSubDoc.documenttype = kpartdocumentobject Then
    oPropSets = oSubDoc.PropertySets 
    oPropSet = oPropSets.Item("Inventor User Defined Properties")
    oPartNumiProp = oPropSet.Item("PCMK")
	       
        sMsg=sMsg & oSubDoc.FullFileName & " - " & oPartNumiProp.Value & vbLf

    End If
    
Next
oWrite.Write(sMsg)
oWrite.Close()

'option to view report
go = MessageBox.Show("Would you like to view the txt file?", "QAF Nesting Report", MessageBoxButtons.YesNo)
If go = 6 Then ThisDoc.Launch(ThisDoc.PathAndFileName(False) & ".txt")

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 4 of 11

Anonymous
Not applicable
Thanks Adam
That gets them together. I will work on it looking like the ilogic.txt file above.
0 Likes
Message 5 of 11

Anonymous
Not applicable
Help
I can't get the code to sort with columns like image above.
0 Likes
Message 6 of 11

admaiora
Mentor
Mentor

Hi Adam,

i have this error using your code,  what do you think?

Thank you Adam! Merry Christmas!

 

 

 

 

Error in rule: Rule2, in document: Test.ipt

Unable to cast COM object of type 'Inventor._DocumentClass' to interface type 'Inventor.DrawingDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D467-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: Interfaccia non supportata. (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

The code

 

fileheader = "QAF Parts for Planning "
fileheader1 = ThisDoc.PathAndFileName(True) 'first line header of txt file
description = "Components to use for Nesting" 'use this variable in the body of the txt

delimiter = "," 'character to separate the names and values on each line

oWrite = System.IO.File.CreateText(ThisDoc.PathAndFileName(False) & ".txt")
oWrite.WriteLine(fileheader) 'include the fileheader on the first line
oWrite.WriteLine(fileheader1) 'include the fileheader on the first line
oWrite.WriteLine(description) 'include the description on the second line
oWrite.WriteLine(Now()) 'include the current date and time on the third line
oWrite.WriteLine() 'blank line

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument 
Dim oSubDoc As Inventor.Document 
Dim oPropSets As PropertySets 
Dim oPropSet As PropertySet
Dim oPartNumiProp As Inventor.Property 

For Each oSubDoc In oDoc.AllReferencedDocuments 
    If oSubDoc.documenttype = kpartdocumentobject Then
    oPropSets = oSubDoc.PropertySets 
    oPropSet = oPropSets.Item("Inventor User Defined Properties")
    oPartNumiProp = oPropSet.Item("PCMK")
	       
        sMsg=sMsg & oSubDoc.FullFileName & " - " & oPartNumiProp.Value & vbLf

    End If
    
Next
oWrite.Write(sMsg)
oWrite.Close()

'option to view report
go = MessageBox.Show("Would you like to view the txt file?", "QAF Nesting Report", MessageBoxButtons.YesNo)
If go = 6 Then ThisDoc.Launch(ThisDoc.PathAndFileName(False) & ".txt")

 

Admaiora
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

_____________________________________________________________________________
Facebook | Twitter | Youtube

0 Likes
Message 7 of 11

adam.nagy
Autodesk Support
Autodesk Support

Hi Mat,

 

First I thought it was similar to this issue:

http://adndevblog.typepad.com/manufacturing/2014/04/disp_e_membernotfound-error-from-ilogic.html

 

Then realized it's even simpler: "Error in rule: Rule2, in document: Test.ipt"

You are using this rule inside a part document but it expects a drawing document.

 

In that case you don't have to iterate through the referenced documents of the part document, but instead read the part document's properties directly. Just to show how things get modified I just comment out what you don't need:

'Dim oDoc As DrawingDocument
'oDoc = ThisApplication.ActiveDocument 
Dim oSubDoc As Inventor.Document 
oSubDoc = ThisApplication.ActiveDocument 'added
Dim oPropSets As PropertySets 
Dim oPropSet As PropertySet
Dim oPartNumiProp As Inventor.Property 

'For Each oSubDoc In oDoc.AllReferencedDocuments 
'    If oSubDoc.documenttype = kpartdocumentobject Then
    oPropSets = oSubDoc.PropertySets 
    oPropSet = oPropSets.Item("Inventor User Defined Properties")
    oPartNumiProp = oPropSet.Item("PCMK")
	       
        sMsg=sMsg & oSubDoc.FullFileName & " - " & oPartNumiProp.Value & vbLf

'    End If
'Next

Merry Christmas and Happy New Year! 🙂

 

Cheers,

 



Adam Nagy
Autodesk Platform Services
0 Likes
Message 8 of 11

admaiora
Mentor
Mentor

Thank you for your interesting Adam!

 

Actually even in the drawing file i receive an error

 

Error in rule: Rule8, in document: text ilogic.idw

Errore non specificato. (Exception from HRESULT: 0x80004005 (E_FAIL))

 

using this

 

fileheader = "QAF Parts for Planning "
fileheader1 = ThisDoc.PathAndFileName(True) 'first line header of txt file
description = "Components to use for Nesting" 'use this variable in the body of the txt

delimiter = "," 'character to separate the names and values on each line

oWrite = System.IO.File.CreateText(ThisDoc.PathAndFileName(False) & ".txt")
oWrite.WriteLine(fileheader) 'include the fileheader on the first line
oWrite.WriteLine(fileheader1) 'include the fileheader on the first line
oWrite.WriteLine(description) 'include the description on the second line
oWrite.WriteLine(Now()) 'include the current date and time on the third line
oWrite.WriteLine() 'blank line

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument 
Dim oSubDoc As Inventor.Document 
Dim oPropSets As PropertySets 
Dim oPropSet As PropertySet
Dim oPartNumiProp As Inventor.Property 

For Each oSubDoc In oDoc.AllReferencedDocuments 
    If oSubDoc.documenttype = kpartdocumentobject Then
    oPropSets = oSubDoc.PropertySets 
    oPropSet = oPropSets.Item("Inventor User Defined Properties")
    oPartNumiProp = oPropSet.Item("PCMK")
	       
        sMsg=sMsg & oSubDoc.FullFileName & " - " & oPartNumiProp.Value & vbLf

    End If
    
Next
oWrite.Write(sMsg)
oWrite.Close()

'option to view report
go = MessageBox.Show("Would you like to view the txt file?", "QAF Nesting Report", MessageBoxButtons.YesNo)
If go = 6 Then ThisDoc.Launch(ThisDoc.PathAndFileName(False) & ".txt")

 

More info

 

System.Runtime.InteropServices.COMException (0x80004005): Errore non specificato. (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.PropertySet.get_Item(Object Index)
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Thank you,  your help makes the difference. Thanks

Admaiora
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

_____________________________________________________________________________
Facebook | Twitter | Youtube

0 Likes
Message 9 of 11

adam.nagy
Autodesk Support
Autodesk Support

Do all the part documents referenced by the drawing file have a User Property called "PCMK"?

Because that's what that code is trying to read.

Is that what you need or what exactly are you trying to automate?



Adam Nagy
Autodesk Platform Services
0 Likes
Message 10 of 11

admaiora
Mentor
Mentor

It was as you said Adam.

Thank you again for solving my problem.

 

I wish you an happy new year!

 

Admaiora
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

_____________________________________________________________________________
Facebook | Twitter | Youtube

0 Likes
Message 11 of 11

Anonymous
Not applicable

hi!

 

It's possible for the fileheader to insert a existing text file

 

fileheader = I:\TEST\HEADER.TXT 

 

Thanks for your help 🙂

0 Likes