iLogic access to Custom Part information from a drawing file

iLogic access to Custom Part information from a drawing file

Anonymous
Not applicable
968 Views
4 Replies
Message 1 of 5

iLogic access to Custom Part information from a drawing file

Anonymous
Not applicable

Looking for help in iLogic.

The goal is to create a comma delimited file so I can import to another program. From a Multi Sheet drawing file I want to cycle through the sheets, open the part (hidden) extract 2 items from the iProperties Part file Custom Tab (_AncestryStr, NAME) and 2 items from the Project Tab (Part Number, Description) string the information together (Each part per line) and write it to a text file.

 

This is what I have so far. (excuse my many trials with comments). Thanks for any help.

1st problem is that when I open the part file I can't seem to get the part information. It gets the drawing information for the file instead.

2nd is how to write the complied strings to a .txt file

 

'open file
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim sSheetName As String
'For Each oSheet In oDoc.Sheets'do the operation for each sheet
oPartSheet = ActiveSheet.Name
'MessageBox.Show(oPartSheet, "oPartSheet")'step through each drawing sheet'For Each oSheet In oDrawing.Sheets'Remove the (:)
lPos = InStr(oPartSheet, ":")
'MessageBox.Show(lPos, "Position")'find the number of characters in the sheet name
sLen = Len(oPartSheet)
'find the sheet name
oPart = Left(oPartSheet, lPos -1)
oPartN = oPart
'Add the .ipt
oPart = oPart & ".ipt"
MessageBox.Show(oPartN, "Part no ipt")
'Open part and get Custom Information, Description
oFullPath = ThisDoc.WorkspacePath()
MessageBox.Show(oFullPath , "directory PATH")
'Open Part and get information
oPartPath = oFullPath & "\" & oPart
MessageBox.Show(oPartPath , "Full PATH")
Dim xDoc As Document = ThisApplication.Documents.Open(oPartPath, True) 'False means it will open invisible 

oName = iProperties.Value("Custom", "NAME")
MessageBox.Show(oNAME, " Part NAME") ' Getting information from drawing not the part.

' Remove the .ipt from the part'TO DO'oNAME = iProperties.Value("Custom", "NAME") ' From the Part File Custom Tab'oPart = iProperties.Value("Project, "Part Number")' From the Part File Project Tab'oDescription = iProperties.Value("Project", "Description")' From the Part File Project Tab'oRefDwg = iProperties.Value("Custom", "_AncestryStr") ' From the Part File Custom Tab'MessageBox.Show(oStr, "Assemblies") 'String information together Testing'Testing to see what string will look like
oName = "CHANNEL"
oPartN = "CH1"
oDescription = "C6x13 x 13'-2 15/16"
oRefDwg = "CPSW(7x2), CP1SW(2)"
oStr = oName & "," & oPartN & "," & oDescription & "," & oRefDwg
MessageBox.Show(oStr, "Comma File")

' Get next sheet in Drawing

'Write to a text file, copied from elsewhere Needs work'Dim oPath As String = oDoc.FullFileName
                'oPath = Left(oPath, Len(oPath) - 3) & "txt"
                    'oPath = Left(oPath, Len(oPath) - 4) & "-Assemblies" & ".txt"
                'System.IO.File.WriteAllText(oPath, Result) 'Pass it the variable Result
                'System.Diagnostics.Process.Start(oPath)

 

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

HermJan.Otterman
Advisor
Advisor
Accepted solution

Hello Steve,

 

I reworked your code a bit.

 

why do you want this to do per sheet? you can,t.  what you can do is:

 

- 1 or if you want to do it per sheet, you need to do it for the view(s) on that sheet, also referenced documents.

  if you do this, you get your info probably multiple times if a component exists in more than one view....

 

- 2 do it for all referenced documents of this drawing

 

 

so the code for the first:

 

 

Dim oDrawDoc As drawingdocument = ThisDoc.Document
Dim oSheet As Sheet = Nothing
        Dim sSheetName As String = Nothing

        For Each oSheet In oDrawDoc.Sheets 'do the operation for each sheet
        
        Dim oDrawingView As drawingview = Nothing
        For Each oDrawingview In oSheet.drawingviews
        
            Dim ComponentDocName As String =  oDrawingView.ReferencedDocumentDescriptor.FullDocumentName
            
            Dim ComponentDoc As Document = ThisApplication.Documents.Open(ComponentDocName, True) 'False means it will open invisible 
             
            'get the properties
            Dim ComponentDocPropName As String = ComponentDoc.PropertySets(4).Item("NAME").Value  '4 = custom
             MessageBox.Show(ComponentDocPropName, " Part NAME") ' Getting information from drawing not the part.
            
            Dim ComponentDocPropPartNumber As String = ComponentDoc.PropertySets(3).Item("Part Number").Value  '3 = standard
             MessageBox.Show(ComponentDocPropPartNumber, "Part Number") ' Getting information from drawing not the part.
            
            'write to a text file (https://msdn.microsoft.com/en-us/library/system.io.file.appendtext(v=vs.110).aspx)
             Dim path As String = "c:\temp\test2.txt"

                ' This text is added only once to the file. 
                If Not System.IO.File.Exists(path) Then
                    ' Create a file to write to.
                    Using sw As System.IO.StreamWriter = System.IO.File.CreateText(path)
                        sw.WriteLine(ComponentDocPropName & "," & ComponentDocPropPartNumber)
                        'sw.WriteLine("And")
                    End Using
                End If

                ' This text is always added, making the file longer over time 
                ' if it is not deleted.
                Using sw As System.IO.StreamWriter = System.IO.File.AppendText(path)
                    sw.WriteLine(ComponentDocPropName & "," & ComponentDocPropPartNumber)
                    'sw.WriteLine("is Extra")
                End Using
                    
            'close the document
            ComponentDoc.Close(True) 'true = skip save
        
        Next
                  
Next

 

and  if you like the second option more:

 

 

 

        Dim oDrawDoc As DrawingDocument = ThisDoc.Document
        
        For Each oRefdoc As Document In oDrawDoc.ReferencedDocuments
            MsgBox(oRefdoc.DisplayName)

            'put your code here

        Next

 

 

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 3 of 5

Anonymous
Not applicable

With a little rework got it to work. Change file location, Open file invisible, Remark out messages, added for fields

Big Thanks. Now I'll need to write the import program.

0 Likes
Message 4 of 5

Anonymous
Not applicable

Well I though we had it. When I examined the output I see multiple duplicates. See the attached

Also attached is my modification to your snippet.

 

Thanks again

0 Likes
Message 5 of 5

HermJan.Otterman
Advisor
Advisor

Hello Steve,

 

that is correct. if you create multiple views of the same component(s) that you will get duplicate lines.

that is why I send you the second option. this wil work for the referenced components only once.

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes