ILogic : how to browse to select an assembly file and get any iProperty value in part ?

ILogic : how to browse to select an assembly file and get any iProperty value in part ?

王承之pmhker
Advisor Advisor
738 Views
6 Replies
Message 1 of 7

ILogic : how to browse to select an assembly file and get any iProperty value in part ?

王承之pmhker
Advisor
Advisor

how to browse to select an assembly file and get any iProperty value in part ?

Public Sub TestFileDialog()
    ' Create a new FileDialog object.
    Dim oFileDlg As FileDialog
    Call ThisApplication.CreateFileDialog(oFileDlg)

    ' Define the filter to select part and assembly files or any file.
    oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"

    ' Define the part and assembly files filter to be the default filter.
    oFileDlg.FilterIndex = 1

    ' Set the title for the dialog.
    oFileDlg.DialogTitle = "Open File Test"

    ' Set the initial directory that will be displayed in the dialog.
    oFileDlg.InitialDirectory = "C:\Temp"

    ' Set the flag so an error will be raised if the user clicks the Cancel button.
    oFileDlg.CancelError = True

    ' Show the open dialog.  The same procedure is also used for the Save dialog.
    ' The commented code can be used for the Save dialog.
    On Error Resume Next
    oFileDlg.ShowOpen
'    oFileDlg.ShowSave

    ' If an error was raised, the user clicked cancel, otherwise display the filename.
    If Err Then
        MsgBox "User cancelled out of dialog"
    ElseIf oFileDlg.FileName <> "" Then
        MsgBox "File " & oFileDlg.FileName & " was selected."
    End If
End Sub

 

 

According to the above code from the API help, I can select and open the file, but I don't know how to get the iproperty value of the selected file。

thanks


If my post answers your question, please click the "Accept as Solution" button. This helps everyone find answers more quickly!
如果我的回帖解决了您的问题,请点击 "接受为解决方案" 按钮. 这可以帮助其他人更快的找到解决方案!


王 承之
Autodesk AGN [Inventor 俱乐部] Leader
Inventor Club | Bilibili


AGN L    EESignature

0 Likes
Accepted solutions (1)
739 Views
6 Replies
Replies (6)
Message 2 of 7

A.Acheson
Mentor
Mentor

Here is a link to the API help sample. And here is the link to an article on implementing this iproperty retrieval.

 

Public Sub GetPropertySample()
    ' Get the active document.
    Dim invDoc As Document
    Set invDoc = ThisApplication.ActiveDocument
    
    ' Get the design tracking property set.
    Dim invDesignInfo As PropertySet
    Set invDesignInfo = invDoc.PropertySets.Item("Design Tracking Properties")
    
    ' Get the part number property.
    Dim invPartNumberProperty As Property
    Set invPartNumberProperty = invDesignInfo.Item("Part Number")
    
    MsgBox "Part Number: " & invPartNumberProperty.value
End Sub

 

 

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 7

王承之pmhker
Advisor
Advisor

thanks for your answer.

My purpose is when I have already opened a part or assembly "A",then  open another assembly "B" with ILOGIC and get its iproperty value to write to the  document "A"


If my post answers your question, please click the "Accept as Solution" button. This helps everyone find answers more quickly!
如果我的回帖解决了您的问题,请点击 "接受为解决方案" 按钮. 这可以帮助其他人更快的找到解决方案!


王 承之
Autodesk AGN [Inventor 俱乐部] Leader
Inventor Club | Bilibili


AGN L    EESignature

0 Likes
Message 4 of 7

A.Acheson
Mentor
Mentor

Here is a link to documents open method. 

 

Use this to open the document given the file name retrieved from the file dialogue box.

 

Syntax

Documents.OpenFullDocumentName As String, [OpenVisible] As Boolean ) As Document

 

 

 

 

Dim NewDoc As Document

NewDoc = ThisApplication.Documents.Open(oFileDlg.FileName,True)

 

 

 Now retrieve the iproperty using the NewDoc document reference then pass it back to the original document reference. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 7

王承之pmhker
Advisor
Advisor
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam)|*.iam|All Files (*.*)|*.*"
oFileDlg.DialogTitle = "Open"
oFileDlg.InitialDirectory = oOrigRefName
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
Return
ElseIf oFileDlg.FileName <> "" Then	
Dim oDoc As Document = oFileDlg.FileName
MessageBox.Show("File opened: " & oFileDlg.FileName, "iLogic")
If oDoc.DocumentType =kAssemblyDocumentObject Then
	MessageBox.Show("The file is assembly", "iLogic")
End If
Dim opn =oDoc.iProperties.Value("Project", "Part Number")
	MessageBox.Show(opn,"iLogic")
End If

 

this is my code, but it can not get the iprop value


If my post answers your question, please click the "Accept as Solution" button. This helps everyone find answers more quickly!
如果我的回帖解决了您的问题,请点击 "接受为解决方案" 按钮. 这可以帮助其他人更快的找到解决方案!


王 承之
Autodesk AGN [Inventor 俱乐部] Leader
Inventor Club | Bilibili


AGN L    EESignature

0 Likes
Message 6 of 7

A.Acheson
Mentor
Mentor
Accepted solution

This isn't correct

 

Dim oDoc As Document = oFileDlg.FileName 

 

 oFileDlg.FileName is a String value for the full file path of the file and not the document  reference. Refer to Documents.Open Method 

 

I see you are using the ilogic snippet for iproperty. I would recommend you use the api method posted earlier as there can  be  issues reading  read only files. 

API method:

' Get the design tracking property set.
    Dim invDesignInfo As PropertySet
    invDesignInfo = NewDoc.PropertySets.Item("Design Tracking Properties")
    
    ' Get the part number property.
    Dim invPartNumberProperty As Property
    invPartNumberProperty = invDesignInfo.Item("Part Number")
    
    MsgBox ("Part Number: " & invPartNumberProperty.value)

Ilogic method:

This is incorrect 

oDoc.iProperties.Value("Project", "Part Number")

 

The iproperty snippet without a document referenced will default to the document active which in this case is the  document the rule is first ran from or in. 

 

Sample method 

'Create document reference

Dim
ofilename As String
oFilename = IO.Path.GetFileName(NewDoc.FullFileName)

iProperties.Value(Project", "Part Number")= iProperties.Value(oFilename,"Project", "Part Number")

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 7 of 7

王承之pmhker
Advisor
Advisor

Thanks a lot. this is my demo of full code. Thank you for helping me solve the problem successfully。😀

 

Dim oFileDlg As Inventor.FileDialog = Nothing 
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*. *" 
oFileDlg.DialogTitle = "Open" 
oFileDlg.InitialDirectory = oOrigRefName
oFileDlg.CancelError = True 
On Error Resume Next 
oFileDlg.ShowOpen() 
If Err.Number <> 0 Then 
	Return
	ElseIf oFileDlg.FileName <> "" Then  
		Dim oDoc As Document =ThisApplication. Documents.Open(oFileDlg.FileName,False) 
		Dim oDif As PropertySet= oDoc.PropertySets.Item("Design Tracking Properties")
  		Dim oPro = oDif.Item("Part Number") 
  		ThisDoc.Document.DisplayName=oPro.Value	
End If


If my post answers your question, please click the "Accept as Solution" button. This helps everyone find answers more quickly!
如果我的回帖解决了您的问题,请点击 "接受为解决方案" 按钮. 这可以帮助其他人更快的找到解决方案!


王 承之
Autodesk AGN [Inventor 俱乐部] Leader
Inventor Club | Bilibili


AGN L    EESignature

0 Likes